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

Method UpdateTableInfo

src/nameserver/name_server_impl.cc:7344–7404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7342}
7343
7344void NameServerImpl::UpdateTableInfo(const std::string& src_endpoint, const std::string& name, const std::string& db,
7345 uint32_t pid, const std::string& des_endpoint,
7346 std::shared_ptr<::fedb::api::TaskInfo> task_info) {
7347 std::lock_guard<std::mutex> lock(mu_);
7348 std::shared_ptr<::fedb::nameserver::TableInfo> table_info;
7349 if (!GetTableInfoUnlock(name, db, &table_info)) {
7350 PDLOG(WARNING, "not found table %s in table_info map. op_id[%lu]", name.c_str(), task_info->op_id());
7351 task_info->set_status(::fedb::api::TaskStatus::kFailed);
7352 return;
7353 }
7354 for (int idx = 0; idx < table_info->table_partition_size(); idx++) {
7355 if (table_info->table_partition(idx).pid() != pid) {
7356 continue;
7357 }
7358 int src_endpoint_index = -1;
7359 int des_endpoint_index = -1;
7360 for (int meta_idx = 0; meta_idx < table_info->table_partition(idx).partition_meta_size(); meta_idx++) {
7361 std::string endpoint = table_info->table_partition(idx).partition_meta(meta_idx).endpoint();
7362 if (endpoint == src_endpoint) {
7363 src_endpoint_index = meta_idx;
7364 } else if (endpoint == des_endpoint) {
7365 des_endpoint_index = meta_idx;
7366 }
7367 }
7368 if (src_endpoint_index < 0) {
7369 PDLOG(WARNING, "has not found src_endpoint[%s]. name[%s] pid[%u] op_id[%lu]", src_endpoint.c_str(),
7370 name.c_str(), pid, task_info->op_id());
7371 task_info->set_status(::fedb::api::TaskStatus::kFailed);
7372 return;
7373 }
7374 ::fedb::nameserver::TablePartition* table_partition = table_info->mutable_table_partition(idx);
7375 ::google::protobuf::RepeatedPtrField<::fedb::nameserver::PartitionMeta>* partition_meta_field =
7376 table_partition->mutable_partition_meta();
7377 if (des_endpoint_index < 0) {
7378 // use src_endpoint's meta when the meta of des_endpoint is not
7379 // exist
7380 PDLOG(INFO,
7381 "des_endpoint meta is not exist, use src_endpoint's meta."
7382 "src_endpoint[%s] name[%s] pid[%u] des_endpoint[%s]",
7383 src_endpoint.c_str(), name.c_str(), pid, des_endpoint.c_str());
7384 ::fedb::nameserver::PartitionMeta* partition_meta = partition_meta_field->Mutable(src_endpoint_index);
7385 partition_meta->set_endpoint(des_endpoint);
7386 partition_meta->set_is_alive(true);
7387 partition_meta->set_is_leader(false);
7388 } else {
7389 ::fedb::nameserver::PartitionMeta* partition_meta = partition_meta_field->Mutable(des_endpoint_index);
7390 partition_meta->set_is_alive(true);
7391 partition_meta->set_is_leader(false);
7392 PDLOG(INFO, "remove partition[%u] in endpoint[%s]. name[%s]", pid, src_endpoint.c_str(), name.c_str());
7393 partition_meta_field->DeleteSubrange(src_endpoint_index, 1);
7394 }
7395 break;
7396 }
7397 if (!UpdateZkTableNode(table_info)) {
7398 task_info->set_status(::fedb::api::TaskStatus::kFailed);
7399 return;
7400 }
7401 task_info->set_status(::fedb::api::TaskStatus::kDone);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected