| 8740 | } |
| 8741 | |
| 8742 | int NameServerImpl::SyncExistTable(const std::string& alias, const std::string& name, const std::string& db, |
| 8743 | const std::vector<::fedb::nameserver::TableInfo> tables_remote, |
| 8744 | const ::fedb::nameserver::TableInfo& table_info_local, uint32_t pid, int& code, |
| 8745 | std::string& msg) { |
| 8746 | std::vector<::fedb::nameserver::TableInfo> table_vec; |
| 8747 | ::fedb::nameserver::TableInfo table_info_remote; |
| 8748 | for (const auto& table : tables_remote) { |
| 8749 | if (table.name() == name && table.db() == db) { |
| 8750 | table_vec.push_back(table); |
| 8751 | table_info_remote = table; |
| 8752 | break; |
| 8753 | } |
| 8754 | } |
| 8755 | { |
| 8756 | decltype(tablets_) tablets; |
| 8757 | { |
| 8758 | std::lock_guard<std::mutex> lock(mu_); |
| 8759 | auto it = tablets_.begin(); |
| 8760 | for (; it != tablets_.end(); it++) { |
| 8761 | if (it->second->state_ != api::kTabletHealthy) { |
| 8762 | continue; |
| 8763 | } |
| 8764 | tablets.insert(std::make_pair(it->first, it->second)); |
| 8765 | } |
| 8766 | } |
| 8767 | std::map<std::string, std::map<uint32_t, std::map<uint32_t, uint64_t>>> tablet_part_offset; |
| 8768 | for (auto it = tablets.begin(); it != tablets.end(); it++) { |
| 8769 | std::map<uint32_t, std::map<uint32_t, uint64_t>> value; |
| 8770 | bool ok = it->second->client_->GetAllSnapshotOffset(value); |
| 8771 | if (ok) { |
| 8772 | tablet_part_offset.insert(std::make_pair(it->second->client_->GetEndpoint(), value)); |
| 8773 | } |
| 8774 | } |
| 8775 | std::lock_guard<std::mutex> lock(mu_); |
| 8776 | if (!CompareTableInfo(table_vec, false)) { |
| 8777 | PDLOG(WARNING, "compare table info error"); |
| 8778 | msg = "compare table info error"; |
| 8779 | code = 567; |
| 8780 | return -1; |
| 8781 | } |
| 8782 | if (!CompareSnapshotOffset(table_vec, msg, code, tablet_part_offset)) { |
| 8783 | return -1; |
| 8784 | } |
| 8785 | } |
| 8786 | std::vector<uint32_t> pid_vec; |
| 8787 | if (pid == INVALID_PID) { |
| 8788 | for (int idx = 0; idx < table_info_remote.table_partition_size(); idx++) { |
| 8789 | pid_vec.push_back(table_info_remote.table_partition(idx).pid()); |
| 8790 | } |
| 8791 | } else { |
| 8792 | pid_vec.push_back(pid); |
| 8793 | } |
| 8794 | for (const auto& cur_pid : pid_vec) { |
| 8795 | bool has_pid = false; |
| 8796 | for (int idx = 0; idx < table_info_local.table_partition_size(); idx++) { |
| 8797 | const ::fedb::nameserver::TablePartition& table_partition_local = table_info_local.table_partition(idx); |
| 8798 | if (table_partition_local.pid() == cur_pid) { |
| 8799 | has_pid = true; |
nothing calls this directly
no test coverage detected