int ObClientServerStub::get_cs_and_ms() { int ret = OB_SUCCESS; ObChunkServerManager obcsm; ObChunkServerManager::const_iterator it; ObServer server; ret = rs_dump_cs_info(obcsm); if (OB_SUCCESS != ret) { fprintf(stderr, "Get chunk server manager error!\n"); return ret; } for (it = obcsm.begin(); it != obcsm.end(); ++it) { ObServer node; node = it->server_; node.set_port(it->port_cs_); chunk_server_list_.push_back(node); node.set_port(it->port_ms_); merge_server_list_.push_back(node); } return ret; }
int ObSchemaServiceMsProvider::reset() { int ret = OB_SUCCESS; tbsys::CWLockGuard guard(rwlock_); count_ = 0; ObChunkServerManager::const_iterator it; for (it = server_manager_.begin(); server_manager_.end() != it && count_ < MAX_SERVER_COUNT; ++it) { if (ObServerStatus::STATUS_DEAD != it->ms_status_) { ObServer ms = it->server_; ms.set_port(it->port_ms_); ms_carray_[count_].ms_ = ms; ms_carray_[count_].retry_count_ = 0; ++count_; TBSYS_LOG(DEBUG, "schema service ms provider found count_=%ld, ms=%s", count_, to_cstring(ms)); } } // end for // shuffle the server list after reset if (count_ > 0) { // std::random_shuffle(ms_carray_, ms_carray_ + count_); } return ret; }
int ObAppStats::sum_cs_cluster_stats(const ObServer& rs, const ObRole server_type) { ObClientRpcStub rs_stub; ObChunkServerManager obsm; int ret = rs_stub.initialize(rs, &GFactory::get_instance().get_base_client().get_client_mgr()); if (OB_SUCCESS == ret) { ret = rs_stub.rs_dump_cs_info(obsm); } ObServer server_list[MAX_SERVER_NUM]; ObArrayHelper<ObServer> server_array(MAX_SERVER_NUM, server_list, 0); if (OB_SUCCESS == ret) { ObChunkServerManager::const_iterator it = obsm.begin(); ObServer node; while (it != obsm.end()) { node = it->server_; if (server_type == OB_CHUNKSERVER) node.set_port(it->port_cs_); else node.set_port(it->port_ms_); /* node.to_string(ipstr, 64); fprintf(stderr, "dump server ip:%s, server status:%ld, serving:%d\n", ipstr, it->status_, ObServerStatus::STATUS_SERVING); */ if (it->status_ != ObServerStatus::STATUS_DEAD) { server_array.push_back(node); } ++it; } ret = sum_cluster_stats(server_type, server_array); } return ret; }
int32_t ObClusterStats::refresh() { int ret = 0; ObRole server_type = store_.diff.get_server_type(); if (server_type == OB_ROOTSERVER) { ret = ObServerStats::refresh(); } else if (server_type == OB_UPDATESERVER) { ObServer update_server; ret = rpc_stub_.get_update_server(update_server); ObClientRpcStub update_stub; if (OB_SUCCESS == ret) { ret = update_stub.initialize(update_server, &GFactory::get_instance().get_base_client().get_client_mgr()); } if (OB_SUCCESS == ret) { ret = update_stub.fetch_stats(store_.current); } } else if (server_type == OB_CHUNKSERVER || server_type == OB_MERGESERVER) { ObChunkServerManager obsm; ret = rpc_stub_.rs_dump_cs_info(obsm); if (OB_SUCCESS == ret) { ObChunkServerManager::const_iterator it = obsm.begin(); ObServer node; char ipstr[OB_MAX_SERVER_ADDR_SIZE]; int alive_server_count = 0; while (it != obsm.end()) { node = it->server_; if (server_type == OB_CHUNKSERVER) node.set_port(it->port_cs_); else node.set_port(it->port_ms_); node.to_string(ipstr, OB_MAX_SERVER_ADDR_SIZE); /* fprintf(stderr, "dump server ip:%s, server status:%ld, serving:%d\n", ipstr, it->status_, ObServerStatus::STATUS_SERVING); */ if (it->status_ != ObServerStatus::STATUS_DEAD) { ObClientRpcStub node_stub; ObStatManager node_stats; node_stats.set_server_type(server_type); ret = node_stub.initialize( node, &GFactory::get_instance().get_base_client().get_client_mgr()); if (OB_SUCCESS != ret) { ++it; continue ;} ret = node_stub.fetch_stats(node_stats); //printf("ret=%d, node_stats:%lu\n", ret, node_stats.get_server_type()); if (OB_SUCCESS != ret) { ++it; continue ;} if (alive_server_count == 0) store_.current = node_stats; else store_.current.add(node_stats); ++alive_server_count; } ++it; } if (0 == alive_server_count) { fprintf(stderr, "no any alive servers, cannot collect data.\n"); } } } return ret; }