From 017f7eb1379ae413d7729c5a3c55b4eca193a779 Mon Sep 17 00:00:00 2001 From: Huang Wei Date: Fri, 10 Nov 2023 15:10:35 +0800 Subject: [PATCH] fix --- docs/zh/maintain/openmldb_ops.md | 2 + src/client/ns_client.cc | 94 +++++++++++++---------------- src/client/ns_client.h | 42 ++++++------- src/client/tablet_client.cc | 52 ++++++++-------- src/client/tablet_client.h | 17 +++--- src/cmd/openmldb.cc | 68 ++++++++++----------- src/datacollector/data_collector.cc | 4 +- src/nameserver/name_server_impl.cc | 4 +- src/sdk/sql_cluster_router.cc | 19 +++--- tools/tool.py | 3 +- 10 files changed, 146 insertions(+), 159 deletions(-) diff --git a/docs/zh/maintain/openmldb_ops.md b/docs/zh/maintain/openmldb_ops.md index 10b53437b52..96f95b43b53 100644 --- a/docs/zh/maintain/openmldb_ops.md +++ b/docs/zh/maintain/openmldb_ops.md @@ -34,6 +34,8 @@ python tools/openmldb_ops.py --openmldb_bin_path=./bin/openmldb --zk_cluster=172.24.4.40:30481 --zk_root_path=/openmldb --cmd=scaleout ``` +运行结果可以只关注ERROR级日志,存在ERROR级日志即执行失败。 + ### 系统要求 - 要求python2.7及以上版本 - `showopstatus`和`showtablestatus`需要`prettytable`依赖 diff --git a/src/client/ns_client.cc b/src/client/ns_client.cc index eb37aa2719f..adbe3e59579 100644 --- a/src/client/ns_client.cc +++ b/src/client/ns_client.cc @@ -221,17 +221,16 @@ base::Status NsClient::ShowOPStatus(const std::string& name, uint32_t pid, return {base::ReturnCode::kError, response->msg()}; } -bool NsClient::CancelOP(uint64_t op_id, std::string& msg) { +base::Status NsClient::CancelOP(uint64_t op_id) { ::openmldb::nameserver::CancelOPRequest request; ::openmldb::nameserver::GeneralResponse response; request.set_op_id(op_id); - bool ok = client_.SendRequest(&::openmldb::nameserver::NameServer_Stub::CancelOP, &request, &response, - FLAGS_request_timeout_ms, 1); - msg = response.msg(); - if (ok && response.code() == 0) { - return true; + auto st = client_.SendRequestSt(&::openmldb::nameserver::NameServer_Stub::CancelOP, &request, &response, + FLAGS_request_timeout_ms, 1); + if (st.OK()) { + return {response.code(), response.msg()}; } - return false; + return st; } bool NsClient::AddTableField(const std::string& table_name, const ::openmldb::common::ColumnDesc& column_desc, @@ -329,10 +328,10 @@ bool NsClient::SetSdkEndpoint(const std::string& server_name, const std::string& return false; } -bool NsClient::AddReplica(const std::string& name, const std::set& pid_set, const std::string& endpoint, - std::string& msg) { +base::Status NsClient::AddReplica(const std::string& name, const std::set& pid_set, + const std::string& endpoint) { if (pid_set.empty()) { - return false; + return {base::ReturnCode::kError, "arg pid set is empty"}; } ::openmldb::nameserver::AddReplicaNSRequest request; ::openmldb::nameserver::GeneralResponse response; @@ -345,13 +344,12 @@ bool NsClient::AddReplica(const std::string& name, const std::set& pid request.add_pid_group(pid); } } - bool ok = client_.SendRequest(&::openmldb::nameserver::NameServer_Stub::AddReplicaNS, &request, &response, - FLAGS_request_timeout_ms, 1); - msg = response.msg(); - if (ok && response.code() == 0) { - return true; + auto st = client_.SendRequestSt(&::openmldb::nameserver::NameServer_Stub::AddReplicaNS, &request, &response, + FLAGS_request_timeout_ms, 1); + if (st.OK()) { + return {response.code(), response.msg()}; } - return false; + return st; } bool NsClient::AddReplicaNS(const std::string& name, const std::vector& endpoint_vec, uint32_t pid, @@ -380,10 +378,10 @@ bool NsClient::AddReplicaNS(const std::string& name, const std::vector& pid_set, const std::string& endpoint, - std::string& msg) { +base::Status NsClient::DelReplica(const std::string& name, const std::set& pid_set, + const std::string& endpoint) { if (pid_set.empty()) { - return false; + return {base::ReturnCode::kError, "arg pid set is empty"}; } ::openmldb::nameserver::DelReplicaNSRequest request; ::openmldb::nameserver::GeneralResponse response; @@ -396,13 +394,12 @@ bool NsClient::DelReplica(const std::string& name, const std::set& pid request.add_pid_group(pid); } } - bool ok = client_.SendRequest(&::openmldb::nameserver::NameServer_Stub::DelReplicaNS, &request, &response, - FLAGS_request_timeout_ms, 1); - msg = response.msg(); - if (ok && response.code() == 0) { - return true; + auto st = client_.SendRequestSt(&::openmldb::nameserver::NameServer_Stub::DelReplicaNS, &request, &response, + FLAGS_request_timeout_ms, 1); + if (st.OK()) { + return {response.code(), response.msg()}; } - return false; + return st; } bool NsClient::ConfSet(const std::string& key, const std::string& value, std::string& msg) { @@ -445,7 +442,7 @@ bool NsClient::ConfGet(const std::string& key, std::map& pid_set, - const std::string& des_endpoint, std::string& msg) { +base::Status NsClient::Migrate(const std::string& src_endpoint, const std::string& name, const std::set& pid_set, + const std::string& des_endpoint) { ::openmldb::nameserver::MigrateRequest request; ::openmldb::nameserver::GeneralResponse response; request.set_src_endpoint(src_endpoint); @@ -490,13 +486,12 @@ bool NsClient::Migrate(const std::string& src_endpoint, const std::string& name, for (auto pid : pid_set) { request.add_pid(pid); } - bool ok = client_.SendRequest(&::openmldb::nameserver::NameServer_Stub::Migrate, &request, &response, + auto st = client_.SendRequestSt(&::openmldb::nameserver::NameServer_Stub::Migrate, &request, &response, FLAGS_request_timeout_ms, 1); - msg = response.msg(); - if (ok && response.code() == 0) { - return true; + if (st.OK()) { + return {response.code(), response.msg()}; } - return false; + return st; } bool NsClient::RecoverEndpoint(const std::string& endpoint, bool need_restore, uint32_t concurrency, std::string& msg) { @@ -516,20 +511,19 @@ bool NsClient::RecoverEndpoint(const std::string& endpoint, bool need_restore, u return false; } -bool NsClient::RecoverTable(const std::string& name, uint32_t pid, const std::string& endpoint, std::string& msg) { +base::Status NsClient::RecoverTable(const std::string& name, uint32_t pid, const std::string& endpoint) { ::openmldb::nameserver::RecoverTableRequest request; ::openmldb::nameserver::GeneralResponse response; request.set_name(name); request.set_pid(pid); request.set_endpoint(endpoint); request.set_db(GetDb()); - bool ok = client_.SendRequest(&::openmldb::nameserver::NameServer_Stub::RecoverTable, &request, &response, + auto st = client_.SendRequestSt(&::openmldb::nameserver::NameServer_Stub::RecoverTable, &request, &response, FLAGS_request_timeout_ms, 1); - msg = response.msg(); - if (ok && response.code() == 0) { - return true; + if (st.OK()) { + return {response.code(), response.msg()}; } - return false; + return st; } bool NsClient::ConnectZK(std::string& msg) { @@ -590,8 +584,7 @@ bool NsClient::GetTablePartition(const std::string& name, uint32_t pid, return false; } -bool NsClient::UpdateTableAliveStatus(const std::string& endpoint, std::string& name, uint32_t pid, bool is_alive, - std::string& msg) { +base::Status NsClient::UpdateTableAliveStatus(const std::string& endpoint, const std::string& name, uint32_t pid, bool is_alive) { ::openmldb::nameserver::UpdateTableAliveRequest request; ::openmldb::nameserver::GeneralResponse response; request.set_endpoint(endpoint); @@ -601,13 +594,12 @@ bool NsClient::UpdateTableAliveStatus(const std::string& endpoint, std::string& if (pid < UINT32_MAX) { request.set_pid(pid); } - bool ok = client_.SendRequest(&::openmldb::nameserver::NameServer_Stub::UpdateTableAliveStatus, &request, &response, + auto st = client_.SendRequestSt(&::openmldb::nameserver::NameServer_Stub::UpdateTableAliveStatus, &request, &response, FLAGS_request_timeout_ms, 1); - msg = response.msg(); - if (ok && response.code() == 0) { - return true; + if (st.OK()) { + return {response.code(), response.msg()}; } - return false; + return st; } bool NsClient::UpdateTTL(const std::string& name, const ::openmldb::type::TTLType& type, uint64_t abs_ttl, diff --git a/src/client/ns_client.h b/src/client/ns_client.h index e48aaac955f..fda147e36e0 100644 --- a/src/client/ns_client.h +++ b/src/client/ns_client.h @@ -94,12 +94,11 @@ class NsClient : public Client { bool MakeSnapshot(const std::string& name, const std::string& db, uint32_t pid, uint64_t end_offset, std::string& msg); // NOLINT - base::Status ShowOPStatus(const std::string& name, uint32_t pid, - nameserver::ShowOPStatusResponse* response); + base::Status ShowOPStatus(const std::string& name, uint32_t pid, nameserver::ShowOPStatusResponse* response); base::Status ShowOPStatus(uint64_t op_id, ::openmldb::nameserver::ShowOPStatusResponse* response); - // TODO - bool CancelOP(uint64_t op_id, std::string& msg); // NOLINT + + base::Status CancelOP(uint64_t op_id); bool AddTableField(const std::string& table_name, const ::openmldb::common::ColumnDesc& column_desc, std::string& msg); // NOLINT @@ -143,36 +142,33 @@ class NsClient : public Client { const ::openmldb::nameserver::TableInfo& table_info, const ::openmldb::nameserver::ZoneInfo& zone_info, std::string& msg); // NOLINT - // TODO - bool AddReplica(const std::string& name, const std::set& pid_set, const std::string& endpoint, - std::string& msg); // NOLINT + + base::Status AddReplica(const std::string& name, const std::set& pid_set, const std::string& endpoint); bool AddReplicaNS(const std::string& name, const std::vector& endpoint_vec, uint32_t pid, const ::openmldb::nameserver::ZoneInfo& zone_info, const ::openmldb::api::TaskInfo& task_info); - // TODO - bool DelReplica(const std::string& name, const std::set& pid_set, const std::string& endpoint, - std::string& msg); // NOLINT + + base::Status DelReplica(const std::string& name, const std::set& pid_set, const std::string& endpoint); bool ConfSet(const std::string& key, const std::string& value, std::string& msg); // NOLINT bool ConfGet(const std::string& key, std::map& conf_map, // NOLINT std::string& msg); // NOLINT - // TODO - bool ChangeLeader(const std::string& name, uint32_t pid, - std::string& candidate_leader, // NOLINT - std::string& msg); // NOLINT + + base::Status ChangeLeader(const std::string& name, uint32_t pid, + std::string& candidate_leader); // NOLINT bool OfflineEndpoint(const std::string& endpoint, uint32_t concurrency, std::string& msg); // NOLINT - // TODO - bool Migrate(const std::string& src_endpoint, const std::string& name, const std::set& pid_set, - const std::string& des_endpoint, std::string& msg); // NOLINT + + base::Status Migrate(const std::string& src_endpoint, const std::string& name, const std::set& pid_set, + const std::string& des_endpoint); bool RecoverEndpoint(const std::string& endpoint, bool need_restore, uint32_t concurrency, std::string& msg); // NOLINT - // TODO get msg - bool RecoverTable(const std::string& name, uint32_t pid, const std::string& endpoint, std::string& msg); // NOLINT + + base::Status RecoverTable(const std::string& name, uint32_t pid, const std::string& endpoint); bool ConnectZK(std::string& msg); // NOLINT @@ -184,11 +180,9 @@ class NsClient : public Client { bool GetTablePartition(const std::string& name, uint32_t pid, ::openmldb::nameserver::TablePartition& table_partition, // NOLINT std::string& msg); // NOLINT - // TODO - bool UpdateTableAliveStatus(const std::string& endpoint, - std::string& name, // NOLINT - uint32_t pid, bool is_alive, - std::string& msg); // NOLINT + + base::Status UpdateTableAliveStatus(const std::string& endpoint, const std::string& name, uint32_t pid, + bool is_alive); bool UpdateTTL(const std::string& name, const ::openmldb::type::TTLType& type, uint64_t abs_ttl, uint64_t lat_ttl, const std::string& ts_name, std::string& msg); // NOLINT diff --git a/src/client/tablet_client.cc b/src/client/tablet_client.cc index 2de831718c1..923d14a384b 100644 --- a/src/client/tablet_client.cc +++ b/src/client/tablet_client.cc @@ -487,37 +487,36 @@ bool TabletClient::GetManifest(uint32_t tid, uint32_t pid, ::openmldb::common::S return true; } -bool TabletClient::GetTableStatus(::openmldb::api::GetTableStatusResponse& response) { +base::Status TabletClient::GetTableStatus(::openmldb::api::GetTableStatusResponse& response) { ::openmldb::api::GetTableStatusRequest request; - bool ret = client_.SendRequest(&::openmldb::api::TabletServer_Stub::GetTableStatus, &request, &response, + auto st = client_.SendRequestSt(&::openmldb::api::TabletServer_Stub::GetTableStatus, &request, &response, FLAGS_request_timeout_ms, 1); - if (ret) { - return true; + if (st.OK()) { + return {response.code(), response.msg()}; } - return false; + return st; } -bool TabletClient::GetTableStatus(uint32_t tid, uint32_t pid, ::openmldb::api::TableStatus& table_status) { +base::Status TabletClient::GetTableStatus(uint32_t tid, uint32_t pid, ::openmldb::api::TableStatus& table_status) { return GetTableStatus(tid, pid, false, table_status); } -bool TabletClient::GetTableStatus(uint32_t tid, uint32_t pid, bool need_schema, +base::Status TabletClient::GetTableStatus(uint32_t tid, uint32_t pid, bool need_schema, ::openmldb::api::TableStatus& table_status) { ::openmldb::api::GetTableStatusRequest request; request.set_tid(tid); request.set_pid(pid); request.set_need_schema(need_schema); ::openmldb::api::GetTableStatusResponse response; - bool ret = client_.SendRequest(&::openmldb::api::TabletServer_Stub::GetTableStatus, &request, &response, + auto st = client_.SendRequestSt(&::openmldb::api::TabletServer_Stub::GetTableStatus, &request, &response, FLAGS_request_timeout_ms, 1); - if (!ret) { - return false; + if (!st.OK()) { + return st; } - if (response.all_table_status_size() > 0) { + if (response.code() == 0 && response.all_table_status_size() > 0) { table_status = response.all_table_status(0); - return true; } - return false; + return {response.code(), response.msg()}; } std::shared_ptr TabletClient::Scan(uint32_t tid, uint32_t pid, @@ -675,25 +674,26 @@ bool TabletClient::SetExpire(uint32_t tid, uint32_t pid, bool is_expire) { return true; } -bool TabletClient::GetTableFollower(uint32_t tid, uint32_t pid, uint64_t& offset, - std::map& info_map, std::string& msg) { +base::Status TabletClient::GetTableFollower(uint32_t tid, uint32_t pid, uint64_t& offset, + std::map& info_map) { ::openmldb::api::GetTableFollowerRequest request; ::openmldb::api::GetTableFollowerResponse response; request.set_tid(tid); request.set_pid(pid); - bool ok = client_.SendRequest(&::openmldb::api::TabletServer_Stub::GetTableFollower, &request, &response, + auto st = client_.SendRequestSt(&::openmldb::api::TabletServer_Stub::GetTableFollower, &request, &response, FLAGS_request_timeout_ms, 1); - if (response.has_msg()) { - msg = response.msg(); - } - if (!ok || response.code() != 0) { - return false; - } - for (int idx = 0; idx < response.follower_info_size(); idx++) { - info_map.insert(std::make_pair(response.follower_info(idx).endpoint(), response.follower_info(idx).offset())); + if (st.OK()) { + if(response.code() == 0) { + offset = response.offset(); + for (int idx = 0; idx < response.follower_info_size(); idx++) { + info_map.insert(std::make_pair(response.follower_info(idx).endpoint(), response.follower_info(idx).offset())); + } + return {}; + } else { + return {response.code(), response.msg()}; + } } - offset = response.offset(); - return true; + return st; } bool TabletClient::Get(uint32_t tid, uint32_t pid, const std::string& pk, uint64_t time, std::string& value, diff --git a/src/client/tablet_client.h b/src/client/tablet_client.h index f6ff72e4cfa..7d2c948d7a9 100644 --- a/src/client/tablet_client.h +++ b/src/client/tablet_client.h @@ -164,21 +164,20 @@ class TabletClient : public Client { bool& is_leader); // NOLINT bool GetManifest(uint32_t tid, uint32_t pid, ::openmldb::common::StorageMode storage_mode, - ::openmldb::api::Manifest& manifest); // NOLINT - // TODO get msg - bool GetTableStatus(::openmldb::api::GetTableStatusResponse& response); // NOLINT - bool GetTableStatus(uint32_t tid, uint32_t pid, + ::openmldb::api::Manifest& manifest); // NOLINT + + base::Status GetTableStatus(::openmldb::api::GetTableStatusResponse& response); // NOLINT + base::Status GetTableStatus(uint32_t tid, uint32_t pid, ::openmldb::api::TableStatus& table_status); // NOLINT - bool GetTableStatus(uint32_t tid, uint32_t pid, bool need_schema, + base::Status GetTableStatus(uint32_t tid, uint32_t pid, bool need_schema, ::openmldb::api::TableStatus& table_status); // NOLINT bool FollowOfNoOne(uint32_t tid, uint32_t pid, uint64_t term, uint64_t& offset); // NOLINT - // TODO get msg - bool GetTableFollower(uint32_t tid, uint32_t pid, + + base::Status GetTableFollower(uint32_t tid, uint32_t pid, uint64_t& offset, // NOLINT - std::map& info_map, // NOLINT - std::string& msg); // NOLINT + std::map& info_map); // NOLINT bool GetAllSnapshotOffset(std::map>& tid_pid_offset); // NOLINT diff --git a/src/cmd/openmldb.cc b/src/cmd/openmldb.cc index 9df5d86cb60..fe1875c901f 100644 --- a/src/cmd/openmldb.cc +++ b/src/cmd/openmldb.cc @@ -495,17 +495,16 @@ void HandleNSClientCancelOP(const std::vector& parts, ::openmldb::c return; } try { - std::string err; if (boost::lexical_cast(parts[1]) <= 0) { std::cout << "Invalid args. op_id should be large than zero" << std::endl; return; } uint64_t op_id = boost::lexical_cast(parts[1]); - bool ok = client->CancelOP(op_id, err); - if (ok) { - std::cout << "Cancel op ok!" << std::endl; + auto st = client->CancelOP(op_id); + if (st.OK()) { + std::cout << "Cancel op ok" << std::endl; } else { - std::cout << "Cancel op failed! " << err << std::endl; + std::cout << "Cancel op failed, error msg: " << st.ToString() << std::endl; } } catch (std::exception const& e) { std::cout << "Invalid args. op_id should be uint64_t" << std::endl; @@ -697,10 +696,10 @@ void HandleNSAddReplica(const std::vector& parts, ::openmldb::clien std::cout << "has not valid pid" << std::endl; return; } - std::string msg; - bool ok = client->AddReplica(parts[1], pid_set, parts[3], msg); - if (!ok) { - std::cout << "Fail to addreplica. error msg:" << msg << std::endl; + + auto st = client->AddReplica(parts[1], pid_set, parts[3]); + if (!st.OK()) { + std::cout << "Fail to addreplica. error msg:" << st.GetMsg() << std::endl; return; } std::cout << "AddReplica ok" << std::endl; @@ -720,10 +719,9 @@ void HandleNSDelReplica(const std::vector& parts, ::openmldb::clien std::cout << "has not valid pid" << std::endl; return; } - std::string msg; - bool ok = client->DelReplica(parts[1], pid_set, parts[3], msg); - if (!ok) { - std::cout << "Fail to delreplica. error msg:" << msg << std::endl; + auto st = client->DelReplica(parts[1], pid_set, parts[3]); + if (!st.OK()) { + std::cout << "Fail to delreplica. error msg:" << st.GetMsg() << std::endl; return; } std::cout << "DelReplica ok" << std::endl; @@ -900,9 +898,9 @@ void HandleNSClientChangeLeader(const std::vector& parts, ::openmld if (parts.size() > 3) { candidate_leader = parts[3]; } - bool ret = client->ChangeLeader(parts[1], pid, candidate_leader, msg); - if (!ret) { - std::cout << "failed to change leader. error msg: " << msg << std::endl; + auto st = client->ChangeLeader(parts[1], pid, candidate_leader); + if (!st.OK()) { + std::cout << "failed to change leader. error msg: " << st.GetMsg() << std::endl; return; } } catch (const std::exception& e) { @@ -961,9 +959,9 @@ void HandleNSClientMigrate(const std::vector& parts, ::openmldb::cl std::cout << "has not valid pid" << std::endl; return; } - bool ret = client->Migrate(parts[1], parts[2], pid_set, parts[4], msg); - if (!ret) { - std::cout << "failed to migrate partition. error msg: " << msg << std::endl; + auto st = client->Migrate(parts[1], parts[2], pid_set, parts[4]); + if (!st.OK()) { + std::cout << "failed to migrate partition. error msg: " << st.GetMsg() << std::endl; return; } std::cout << "partition migrate ok" << std::endl; @@ -1016,10 +1014,9 @@ void HandleNSClientRecoverTable(const std::vector& parts, ::openmld } try { uint32_t pid = boost::lexical_cast(parts[2]); - std::string msg; - bool ok = client->RecoverTable(parts[1], pid, parts[3], msg); - if (!ok) { - std::cout << "Fail to recover table. error msg:" << msg << std::endl; + auto st = client->RecoverTable(parts[1], pid, parts[3]); + if (!st.OK()) { + std::cout << "Fail to recover table. error msg:" << st.GetMsg() << std::endl; return; } std::cout << "recover table ok" << std::endl; @@ -2696,9 +2693,9 @@ void HandleNSClientUpdateTableAlive(const std::vector& parts, ::ope return; } } - std::string msg; - if (!client->UpdateTableAliveStatus(endpoint, name, pid, is_alive, msg)) { - std::cout << "Fail to update table alive. error msg: " << msg << std::endl; + + if (auto st = client->UpdateTableAliveStatus(endpoint, name, pid, is_alive);!st.OK()) { + std::cout << "Fail to update table alive. error msg: " << st.GetMsg() << std::endl; return; } std::cout << "update ok" << std::endl; @@ -3110,19 +3107,19 @@ void HandleClientGetTableStatus(const std::vector parts, ::openmldb if (parts.size() == 3) { ::openmldb::api::TableStatus table_status; try { - if (client->GetTableStatus(boost::lexical_cast(parts[1]), boost::lexical_cast(parts[2]), - table_status)) { + if (auto st = client->GetTableStatus(boost::lexical_cast(parts[1]), boost::lexical_cast(parts[2]), + table_status); st.OK()) { status_vec.push_back(table_status); } else { - std::cout << "gettablestatus failed" << std::endl; + std::cout << "gettablestatus failed, error msg: " << st.GetMsg() << std::endl; } } catch (boost::bad_lexical_cast& e) { std::cout << "Bad gettablestatus format" << std::endl; } } else if (parts.size() == 1) { ::openmldb::api::GetTableStatusResponse response; - if (!client->GetTableStatus(response)) { - std::cout << "gettablestatus failed" << std::endl; + if (auto st = client->GetTableStatus(response); !st.OK()) { + std::cout << "gettablestatus failed, error msg: " << st.GetMsg() << std::endl; return; } for (int idx = 0; idx < response.all_table_status_size(); idx++) { @@ -3304,8 +3301,8 @@ void HandleClientPreview(const std::vector& parts, ::openmldb::clie return; } ::openmldb::api::TableStatus table_status; - if (!client->GetTableStatus(tid, pid, true, table_status)) { - std::cout << "Fail to get table status" << std::endl; + if (auto st = client->GetTableStatus(tid, pid, true, table_status); !st.OK()) { + std::cout << "Fail to get table status, error msg: " << st.GetMsg() << std::endl; return; } /*std::string schema = table_status.schema(); @@ -3395,9 +3392,8 @@ void HandleClientGetFollower(const std::vector& parts, ::openmldb:: } std::map info_map; uint64_t offset = 0; - std::string msg; - if (!client->GetTableFollower(tid, pid, offset, info_map, msg)) { - std::cout << "get failed. msg: " << msg << std::endl; + if (auto st = client->GetTableFollower(tid, pid, offset, info_map); !st.OK()) { + std::cout << "get failed, error msg: " << st.GetMsg() << std::endl; return; } std::vector header; diff --git a/src/datacollector/data_collector.cc b/src/datacollector/data_collector.cc index 8cf02a3ab2b..e4a72b4154a 100644 --- a/src/datacollector/data_collector.cc +++ b/src/datacollector/data_collector.cc @@ -255,8 +255,8 @@ void DataCollectorImpl::CreateTaskEnv(const datasync::AddSyncTaskRequest* reques } auto tablet_client = tablet_client_map_[tablet_endpoint]; api::TableStatus table_status; - if (!tablet_client->GetTableStatus(tid, pid, table_status)) { - SET_RESP_AND_WARN(response, -1, "get table status from tablet server failed, maybe table doesn't exist"); + if (auto st = tablet_client->GetTableStatus(tid, pid, table_status); !st.OK()) { + SET_RESP_AND_WARN(response, -1, "get table status from tablet server failed, maybe table doesn't exist: " + st.GetMsg()); return; } if (!ValidateTableStatus(table_status)) { diff --git a/src/nameserver/name_server_impl.cc b/src/nameserver/name_server_impl.cc index 862ee42d320..743883abb77 100644 --- a/src/nameserver/name_server_impl.cc +++ b/src/nameserver/name_server_impl.cc @@ -5009,8 +5009,8 @@ void NameServerImpl::UpdateTableStatus() { pos_response.reserve(16); for (const auto& kv : tablet_ptr_map) { ::openmldb::api::GetTableStatusResponse tablet_status_response; - if (!kv.second->client_->GetTableStatus(tablet_status_response)) { - PDLOG(WARNING, "get table status failed! endpoint[%s]", kv.first.c_str()); + if (auto st = kv.second->client_->GetTableStatus(tablet_status_response); !st.OK()) { + PDLOG(WARNING, "get table status failed! endpoint[%s], %s", kv.first.c_str(), st.GetMsg()); continue; } for (int pos = 0; pos < tablet_status_response.all_table_status_size(); pos++) { diff --git a/src/sdk/sql_cluster_router.cc b/src/sdk/sql_cluster_router.cc index 90054f277aa..e328b12b926 100644 --- a/src/sdk/sql_cluster_router.cc +++ b/src/sdk/sql_cluster_router.cc @@ -4331,10 +4331,12 @@ std::shared_ptr SQLClusterRouter::ExecuteShowTableStat std::shared_ptr tablet_client; if (tablet_accessor && (tablet_client = tablet_accessor->GetClient())) { ::openmldb::api::GetTableStatusResponse response; - if (tablet_client->GetTableStatus(response)) { + if (auto st = tablet_client->GetTableStatus(response); st.OK()) { for (const auto& table_status : response.all_table_status()) { table_statuses[table_status.tid()][table_status.pid()][tablet_client->GetEndpoint()] = table_status; } + } else { + LOG(WARNING) << "get table status from tablet failed: " << st.GetMsg(); } } } @@ -4464,14 +4466,17 @@ bool SQLClusterRouter::CheckTableStatus(const std::string& db, const std::string if (tablet_accessor && (tablet_client = tablet_accessor->GetClient())) { uint64_t offset = 0; std::map info_map; - std::string msg; - tablet_client->GetTableFollower(tid, pid, offset, info_map, msg); - for (auto& meta : partition_info.partition_meta()) { - if (meta.is_leader()) continue; + auto st = tablet_client->GetTableFollower(tid, pid, offset, info_map); + if (st.OK()) { + for (auto& meta : partition_info.partition_meta()) { + if (meta.is_leader()) continue; - if (info_map.count(meta.endpoint()) == 0) { - append_error_msg(error_msg, pid, false, meta.endpoint(), "not connected to leader"); + if (info_map.count(meta.endpoint()) == 0) { + append_error_msg(error_msg, pid, false, meta.endpoint(), "not connected to leader"); + } } + } else { + append_error_msg(error_msg, pid, -1, "", absl::StrCat("fail to get from tablet: ", st.GetMsg())); } } diff --git a/tools/tool.py b/tools/tool.py index da16dc50347..98876b2cc3a 100644 --- a/tools/tool.py +++ b/tools/tool.py @@ -125,8 +125,7 @@ def RunWithRetuncode(self, command, # TODO(hw): the print from ns/tablet client are not standard, print it for debug if output != "": log.info(output) - if errout != "": - log.info(errout) + # errout has glog output, don't print it if "error msg" in output: return Status(-1, output), output return Status(p.returncode, errout), output