MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / StartNsClient

Function StartNsClient

src/cmd/fedb.cc:4994–5220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4992}
4993
4994void StartNsClient() {
4995 std::string endpoint;
4996 std::string real_endpoint;
4997 if (FLAGS_interactive) {
4998 std::cout << "Welcome to fedb with version " << FEDB_VERSION << std::endl;
4999 }
5000 std::shared_ptr<::fedb::zk::ZkClient> zk_client;
5001 if (!FLAGS_zk_cluster.empty()) {
5002 zk_client = std::make_shared<::fedb::zk::ZkClient>(
5003 FLAGS_zk_cluster, "", 1000, "", FLAGS_zk_root_path);
5004 if (!zk_client->Init()) {
5005 std::cout << "zk client init failed" << std::endl;
5006 return;
5007 }
5008 std::string node_path = FLAGS_zk_root_path + "/leader";
5009 std::vector<std::string> children;
5010 if (!zk_client->GetChildren(node_path, children) || children.empty()) {
5011 std::cout << "get children failed" << std::endl;
5012 return;
5013 }
5014 std::string leader_path = node_path + "/" + children[0];
5015 if (!zk_client->GetNodeValue(leader_path, endpoint)) {
5016 std::cout << "get leader failed" << std::endl;
5017 return;
5018 }
5019 std::cout << "ns leader: " << endpoint << std::endl;
5020 // real endpoint part
5021 std::string path = FLAGS_zk_root_path + "/map/names/" + endpoint;
5022 if (zk_client->IsExistNode(path) == 0) {
5023 if (!zk_client->GetNodeValue(path, real_endpoint)) {
5024 std::cout << "get real_endpoint failed" << std::endl;
5025 return;
5026 }
5027 std::string name_root_path = FLAGS_zk_root_path + "/map/names";
5028 std::vector<std::string> nodes;
5029 if (!zk_client->GetChildren(name_root_path, nodes)
5030 || nodes.empty()) {
5031 std::cout << "get server name nodes failed" << std::endl;
5032 return;
5033 }
5034 for (const auto& node : nodes) {
5035 std::string real_ep;
5036 std::string real_path = name_root_path + "/" + node;
5037 if (!zk_client->GetNodeValue(real_path, real_ep)) {
5038 std::cout << "get zk server name failed" << std::endl;
5039 return;
5040 }
5041 real_ep_map.insert(std::make_pair(node, real_ep));
5042 }
5043 }
5044 } else if (!FLAGS_endpoint.empty()) {
5045 endpoint = FLAGS_endpoint;
5046 } else {
5047 std::cout << "Start failed! not set endpoint or zk_cluster"
5048 << std::endl;
5049 return;
5050 }
5051 ::fedb::client::NsClient client(endpoint, real_endpoint);

Callers 1

mainFunction · 0.85

Calls 15

linenoiseFunction · 0.85
linenoiseHistoryAddFunction · 0.85
linenoiseFreeFunction · 0.85
linenoiseSetMultiLineFunction · 0.85
HandleNsClientSQLFunction · 0.85
SplitStringFunction · 0.85
HandleNSShowTabletFunction · 0.85
HandleNSShowSdkEndpointFunction · 0.85
HandleNSShowNameServerFunction · 0.85
HandleNSShowOPStatusFunction · 0.85
HandleNSCreateTableFunction · 0.85
HandleNSPutFunction · 0.85

Tested by

no test coverage detected