| 8608 | } |
| 8609 | |
| 8610 | void NameServerImpl::SyncTable(RpcController* controller, const SyncTableRequest* request, GeneralResponse* response, |
| 8611 | Closure* done) { |
| 8612 | brpc::ClosureGuard done_guard(done); |
| 8613 | if (!running_.load(std::memory_order_acquire)) { |
| 8614 | response->set_code(::fedb::base::ReturnCode::kNameserverIsNotLeader); |
| 8615 | response->set_msg("nameserver is not leader"); |
| 8616 | PDLOG(WARNING, "cur nameserver is not leader"); |
| 8617 | return; |
| 8618 | } |
| 8619 | if (mode_.load(std::memory_order_relaxed) != kLEADER) { |
| 8620 | response->set_code(::fedb::base::ReturnCode::kCurNameserverIsNotLeaderMdoe); |
| 8621 | response->set_msg("cur nameserver is not leader mode"); |
| 8622 | PDLOG(WARNING, "cur nameserver is not leader mode"); |
| 8623 | return; |
| 8624 | } |
| 8625 | int code = 0; |
| 8626 | std::string msg = "ok"; |
| 8627 | std::string name = request->name(); |
| 8628 | std::string db = request->db(); |
| 8629 | std::string cluster_alias = request->cluster_alias(); |
| 8630 | std::shared_ptr<::fedb::nameserver::TableInfo> table_info; |
| 8631 | do { |
| 8632 | std::shared_ptr<::fedb::client::NsClient> client; |
| 8633 | { |
| 8634 | std::lock_guard<std::mutex> lock(mu_); |
| 8635 | if (!GetTableInfoUnlock(name, db, &table_info)) { |
| 8636 | response->set_code(::fedb::base::ReturnCode::kTableIsNotExist); |
| 8637 | response->set_msg("table is not exist!"); |
| 8638 | PDLOG(WARNING, "table[%s] is not exist!", name.c_str()); |
| 8639 | return; |
| 8640 | } |
| 8641 | auto it = nsc_.find(cluster_alias); |
| 8642 | if (it == nsc_.end()) { |
| 8643 | code = 404; |
| 8644 | msg = "replica name not found"; |
| 8645 | PDLOG(WARNING, "replica name [%s] not found when synctable [%s]", cluster_alias.c_str(), name.c_str()); |
| 8646 | break; |
| 8647 | } |
| 8648 | if (it->second->state_.load(std::memory_order_relaxed) != kClusterHealthy) { |
| 8649 | code = 507; |
| 8650 | msg = "replica cluster not healthy"; |
| 8651 | PDLOG(WARNING, "replica cluster [%s] not healthy when syntable [%s]", cluster_alias.c_str(), |
| 8652 | name.c_str()); |
| 8653 | break; |
| 8654 | } |
| 8655 | client = std::atomic_load_explicit(&it->second->client_, std::memory_order_relaxed); |
| 8656 | } |
| 8657 | std::vector<::fedb::nameserver::TableInfo> tables; |
| 8658 | if (!client->ShowTable(name, db, false, tables, msg)) { |
| 8659 | code = 455; |
| 8660 | msg = "showtable error when synctable"; |
| 8661 | PDLOG(WARNING, "replica cluster [%s] showtable error when synctable [%s]", cluster_alias.c_str(), |
| 8662 | name.c_str()); |
| 8663 | break; |
| 8664 | } |
| 8665 | std::vector<std::string> table_name_vec; |
| 8666 | for (auto& rkv : tables) { |
| 8667 | table_name_vec.push_back(rkv.name()); |
nothing calls this directly
no test coverage detected