Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vagetablechicken committed Nov 10, 2023
1 parent ad0cdaf commit 017f7eb
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 159 deletions.
2 changes: 2 additions & 0 deletions docs/zh/maintain/openmldb_ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`依赖
94 changes: 43 additions & 51 deletions src/client/ns_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<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,
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;
Expand All @@ -345,13 +344,12 @@ bool NsClient::AddReplica(const std::string& name, const std::set<uint32_t>& 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<std::string>& endpoint_vec, uint32_t pid,
Expand Down Expand Up @@ -380,10 +378,10 @@ bool NsClient::AddReplicaNS(const std::string& name, const std::vector<std::stri
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,
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;
Expand All @@ -396,13 +394,12 @@ bool NsClient::DelReplica(const std::string& name, const std::set<uint32_t>& 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) {
Expand Down Expand Up @@ -445,7 +442,7 @@ bool NsClient::ConfGet(const std::string& key, std::map<std::string, std::string
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) {
::openmldb::nameserver::ChangeLeaderRequest request;
::openmldb::nameserver::GeneralResponse response;
request.set_name(name);
Expand All @@ -454,13 +451,12 @@ bool NsClient::ChangeLeader(const std::string& name, uint32_t pid, std::string&
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()};
}
return false;
return st;
}

bool NsClient::OfflineEndpoint(const std::string& endpoint, uint32_t concurrency, std::string& msg) {
Expand All @@ -479,8 +475,8 @@ bool NsClient::OfflineEndpoint(const std::string& endpoint, uint32_t concurrency
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, 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 @@ 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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
42 changes: 18 additions & 24 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);
// 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
Expand Down Expand Up @@ -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<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);
// TODO
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
// 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<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
// 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

Expand All @@ -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
Expand Down
52 changes: 26 additions & 26 deletions src/client/tablet_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<openmldb::base::ScanKvIterator> TabletClient::Scan(uint32_t tid, uint32_t pid,
Expand Down Expand Up @@ -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<std::string, uint64_t>& info_map, std::string& msg) {
base::Status TabletClient::GetTableFollower(uint32_t tid, uint32_t pid, uint64_t& offset,
std::map<std::string, uint64_t>& 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,
Expand Down
Loading

0 comments on commit 017f7eb

Please sign in to comment.