Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: catch error msgs in ns/tablet client #3587

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/zh/maintain/openmldb_ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ python tools/openmldb_ops.py --openmldb_bin_path=./bin/openmldb --zk_cluster=0.0
python tools/openmldb_ops.py --openmldb_bin_path=./bin/openmldb --zk_cluster=0.0.0.0:2181 --zk_root_path=/openmldb --cmd=recoverdata
```

注:理论上openmldb_ops不要求版本匹配,高版本openmldb_ops可以操作低版本的openmldb集群
运行结果可以只关注是否存在ERROR级日志,如果存在,请保留完整的日志记录,便于技术人员查找问题

### 系统要求
- 要求python2.7及以上版本
- 理论上openmldb_ops不要求与OpenMLDB集群的版本匹配,高版本openmldb_ops可以操作低版本的OpenMLDB集群。
- `showopstatus`和`showtablestatus`需要`prettytable`依赖
3 changes: 3 additions & 0 deletions src/base/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include <string>

#include "absl/strings/str_cat.h"

#include "base/slice.h"
#include "version.h" // NOLINT

Expand Down Expand Up @@ -185,6 +187,7 @@
inline bool OK() const { return code == ReturnCode::kOk; }
inline const std::string& GetMsg() const { return msg; }
inline int GetCode() const { return code; }
inline std::string ToString() const { return absl::StrCat("ReturnCode[", code, "]", msg); }

Check warning on line 190 in src/base/status.h

View check run for this annotation

Codecov / codecov/patch

src/base/status.h#L190

Added line #L190 was not covered by tests
int code;
std::string msg;
};
Expand Down
97 changes: 45 additions & 52 deletions src/client/ns_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,16 @@
return {base::ReturnCode::kError, response->msg()};
}

bool NsClient::CancelOP(uint64_t op_id, std::string& msg) {
base::Status NsClient::CancelOP(uint64_t op_id) {

Check warning on line 224 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L224

Added line #L224 was not covered by tests
::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()};

Check warning on line 231 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L229-L231

Added lines #L229 - L231 were not covered by tests
}
return false;
return st;

Check warning on line 233 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L233

Added line #L233 was not covered by tests
}

bool NsClient::AddTableField(const std::string& table_name, const ::openmldb::common::ColumnDesc& column_desc,
Expand Down Expand Up @@ -329,10 +328,10 @@
return false;
}

bool NsClient::AddReplica(const std::string& name, const std::set<uint32_t>& pid_set, const std::string& endpoint,
std::string& msg) {
base::Status NsClient::AddReplica(const std::string& name, const std::set<uint32_t>& pid_set,

Check warning on line 331 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L331

Added line #L331 was not covered by tests
const std::string& endpoint) {
if (pid_set.empty()) {
return false;
return {base::ReturnCode::kError, "arg pid set is empty"};

Check warning on line 334 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L334

Added line #L334 was not covered by tests
}
::openmldb::nameserver::AddReplicaNSRequest request;
::openmldb::nameserver::GeneralResponse response;
Expand All @@ -345,13 +344,12 @@
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()};

Check warning on line 350 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L348-L350

Added lines #L348 - L350 were not covered by tests
}
return false;
return st;

Check warning on line 352 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L352

Added line #L352 was not covered by tests
}

bool NsClient::AddReplicaNS(const std::string& name, const std::vector<std::string>& endpoint_vec, uint32_t pid,
Expand Down Expand Up @@ -380,10 +378,10 @@
return false;
}

bool NsClient::DelReplica(const std::string& name, const std::set<uint32_t>& pid_set, const std::string& endpoint,
std::string& msg) {
base::Status NsClient::DelReplica(const std::string& name, const std::set<uint32_t>& pid_set,

Check warning on line 381 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L381

Added line #L381 was not covered by tests
const std::string& endpoint) {
if (pid_set.empty()) {
return false;
return {base::ReturnCode::kError, "arg pid set is empty"};

Check warning on line 384 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L384

Added line #L384 was not covered by tests
}
::openmldb::nameserver::DelReplicaNSRequest request;
::openmldb::nameserver::GeneralResponse response;
Expand All @@ -396,13 +394,12 @@
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()};

Check warning on line 400 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L398-L400

Added lines #L398 - L400 were not covered by tests
}
return false;
return st;

Check warning on line 402 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L402

Added line #L402 was not covered by tests
}

bool NsClient::ConfSet(const std::string& key, const std::string& value, std::string& msg) {
Expand Down Expand Up @@ -445,7 +442,7 @@
return false;
}

bool NsClient::ChangeLeader(const std::string& name, uint32_t pid, std::string& candidate_leader, std::string& msg) {
base::Status NsClient::ChangeLeader(const std::string& name, uint32_t pid, std::string& candidate_leader) {

Check warning on line 445 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L445

Added line #L445 was not covered by tests
::openmldb::nameserver::ChangeLeaderRequest request;
::openmldb::nameserver::GeneralResponse response;
request.set_name(name);
Expand All @@ -454,13 +451,12 @@
request.set_candidate_leader(candidate_leader);
}
request.set_db(GetDb());
bool ok = client_.SendRequest(&::openmldb::nameserver::NameServer_Stub::ChangeLeader, &request, &response,
auto st = client_.SendRequestSt(&::openmldb::nameserver::NameServer_Stub::ChangeLeader, &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()};

Check warning on line 457 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L456-L457

Added lines #L456 - L457 were not covered by tests
}
return false;
return st;

Check warning on line 459 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L459

Added line #L459 was not covered by tests
}

bool NsClient::OfflineEndpoint(const std::string& endpoint, uint32_t concurrency, std::string& msg) {
Expand All @@ -479,8 +475,8 @@
return false;
}

bool NsClient::Migrate(const std::string& src_endpoint, const std::string& name, const std::set<uint32_t>& pid_set,
const std::string& des_endpoint, std::string& msg) {
base::Status NsClient::Migrate(const std::string& src_endpoint, const std::string& name,

Check warning on line 478 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L478

Added line #L478 was not covered by tests
const std::set<uint32_t>& pid_set, const std::string& des_endpoint) {
::openmldb::nameserver::MigrateRequest request;
::openmldb::nameserver::GeneralResponse response;
request.set_src_endpoint(src_endpoint);
Expand All @@ -490,13 +486,12 @@
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()};

Check warning on line 492 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L491-L492

Added lines #L491 - L492 were not covered by tests
}
return false;
return st;

Check warning on line 494 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L494

Added line #L494 was not covered by tests
}

bool NsClient::RecoverEndpoint(const std::string& endpoint, bool need_restore, uint32_t concurrency, std::string& msg) {
Expand All @@ -516,20 +511,19 @@
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) {

Check warning on line 514 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L514

Added line #L514 was not covered by tests
::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()};

Check warning on line 524 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L523-L524

Added lines #L523 - L524 were not covered by tests
}
return false;
return st;

Check warning on line 526 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L526

Added line #L526 was not covered by tests
}

bool NsClient::ConnectZK(std::string& msg) {
Expand Down Expand Up @@ -590,8 +584,8 @@
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,

Check warning on line 587 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L587

Added line #L587 was not covered by tests
bool is_alive) {
::openmldb::nameserver::UpdateTableAliveRequest request;
::openmldb::nameserver::GeneralResponse response;
request.set_endpoint(endpoint);
Expand All @@ -601,13 +595,12 @@
if (pid < UINT32_MAX) {
request.set_pid(pid);
}
bool ok = client_.SendRequest(&::openmldb::nameserver::NameServer_Stub::UpdateTableAliveStatus, &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::UpdateTableAliveStatus, &request,
&response, FLAGS_request_timeout_ms, 1);
if (st.OK()) {
return {response.code(), response.msg()};

Check warning on line 601 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L599-L601

Added lines #L599 - L601 were not covered by tests
}
return false;
return st;

Check warning on line 603 in src/client/ns_client.cc

View check run for this annotation

Codecov / codecov/patch

src/client/ns_client.cc#L603

Added line #L603 was not covered by tests
}

bool NsClient::UpdateTTL(const std::string& name, const ::openmldb::type::TTLType& type, uint64_t abs_ttl,
Expand Down
28 changes: 11 additions & 17 deletions src/client/ns_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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
Expand Down Expand Up @@ -144,35 +143,32 @@ class NsClient : public Client {
const ::openmldb::nameserver::ZoneInfo& zone_info,
std::string& msg); // NOLINT

bool AddReplica(const std::string& name, const std::set<uint32_t>& pid_set, const std::string& endpoint,
std::string& msg); // NOLINT
base::Status AddReplica(const std::string& name, const std::set<uint32_t>& pid_set, const std::string& endpoint);

bool AddReplicaNS(const std::string& name, const std::vector<std::string>& endpoint_vec, uint32_t pid,
const ::openmldb::nameserver::ZoneInfo& zone_info, const ::openmldb::api::TaskInfo& task_info);

bool DelReplica(const std::string& name, const std::set<uint32_t>& pid_set, const std::string& endpoint,
std::string& msg); // NOLINT
base::Status DelReplica(const std::string& name, const std::set<uint32_t>& 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<std::string, std::string>& conf_map, // NOLINT
std::string& msg); // NOLINT

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

bool Migrate(const std::string& src_endpoint, const std::string& name, const std::set<uint32_t>& 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<uint32_t>& pid_set,
const std::string& des_endpoint);

bool RecoverEndpoint(const std::string& endpoint, bool need_restore, uint32_t concurrency,
std::string& msg); // NOLINT

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

Expand All @@ -185,10 +181,8 @@ class NsClient : public Client {
::openmldb::nameserver::TablePartition& table_partition, // NOLINT
std::string& msg); // NOLINT

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
Expand Down
Loading
Loading