@@ -811,6 +811,48 @@ void DoGetStoreMetrics(google::protobuf::RpcController * /*controller*/,
811811 }
812812}
813813
814+ void DoGetStoreOwnMetrics (google::protobuf::RpcController * /* controller*/ ,
815+ const pb::coordinator::GetStoreOwnMetricsRequest *request,
816+ pb::coordinator::GetStoreOwnMetricsResponse *response, TrackClosure *done,
817+ std::shared_ptr<CoordinatorControl> coordinator_control,
818+ std::shared_ptr<Engine> /* raft_engine*/ ) {
819+ brpc::ClosureGuard done_guard (done);
820+ auto tracker = done->Tracker ();
821+ tracker->SetServiceQueueWaitTime ();
822+
823+ auto is_leader = coordinator_control->IsLeader ();
824+ DINGO_LOG (DEBUG) << " Receive Get StoreOwnMetrics Request, IsLeader:" << is_leader
825+ << " , Request:" << request->ShortDebugString ();
826+
827+ if (!is_leader) {
828+ return coordinator_control->RedirectResponse (response);
829+ }
830+
831+ // get store own metrics
832+ std::vector<pb::common::StoreOwnMetrics> store_own_metrics_list;
833+ std::vector<int64_t > store_ids;
834+ if (request->store_ids_size () > 0 ) {
835+ store_ids.reserve (request->store_ids_size ());
836+ for (const auto &store_id : request->store_ids ()) {
837+ store_ids.push_back (store_id);
838+ }
839+ }
840+ coordinator_control->GetStoreOwnMetrics (store_ids, store_own_metrics_list);
841+ if (store_own_metrics_list.size () != request->store_ids ().size () && request->store_ids ().size () > 0 ) {
842+ DINGO_LOG (ERROR) << " GetStoreOwnMetrics size not match, store_ids_size=" << request->store_ids ().size ()
843+ << " , store_own_metrics_list_size=" << store_own_metrics_list.size ();
844+ auto *error = response->mutable_error ();
845+ error->set_errcode (pb::error::Errno::EILLEGAL_PARAMTETERS);
846+ error->set_errmsg (" invalid store id" );
847+ return ;
848+ }
849+
850+ for (auto &store_own_metrics : store_own_metrics_list) {
851+ auto *new_store_own_metrics = response->add_store_own_metrics ();
852+ *new_store_own_metrics = store_own_metrics;
853+ }
854+ }
855+
814856void DoDeleteStoreMetrics (google::protobuf::RpcController * /* controller*/ ,
815857 const pb::coordinator::DeleteStoreMetricsRequest *request,
816858 pb::coordinator::DeleteStoreMetricsResponse *response, TrackClosure *done,
@@ -2833,6 +2875,29 @@ void CoordinatorServiceImpl::GetStoreMetrics(google::protobuf::RpcController *co
28332875 }
28342876}
28352877
2878+ void CoordinatorServiceImpl::GetStoreOwnMetrics (google::protobuf::RpcController *controller,
2879+ const pb::coordinator::GetStoreOwnMetricsRequest *request,
2880+ pb::coordinator::GetStoreOwnMetricsResponse *response,
2881+ google::protobuf::Closure *done) {
2882+ brpc::ClosureGuard done_guard (done);
2883+ auto is_leader = coordinator_control_->IsLeader ();
2884+ DINGO_LOG (DEBUG) << " Receive Get StoreOwnMetrics Request, IsLeader:" << is_leader
2885+ << " , Request:" << request->ShortDebugString ();
2886+ if (!is_leader) {
2887+ return coordinator_control_->RedirectResponse (response);
2888+ }
2889+ // Run in queue.
2890+ auto *svr_done = new CoordinatorServiceClosure (__func__, done_guard.release (), request, response);
2891+ auto task = std::make_shared<ServiceTask>([this , controller, request, response, svr_done]() {
2892+ DoGetStoreOwnMetrics (controller, request, response, svr_done, coordinator_control_, engine_);
2893+ });
2894+ bool ret = worker_set_->ExecuteRR (task);
2895+ if (!ret) {
2896+ brpc::ClosureGuard done_guard (svr_done);
2897+ ServiceHelper::SetError (response->mutable_error (), pb::error::EREQUEST_FULL, " Commit execute queue failed" );
2898+ }
2899+ }
2900+
28362901void CoordinatorServiceImpl::DeleteStoreMetrics (google::protobuf::RpcController *controller,
28372902 const pb::coordinator::DeleteStoreMetricsRequest *request,
28382903 pb::coordinator::DeleteStoreMetricsResponse *response,
0 commit comments