| 6547 | } |
| 6548 | |
| 6549 | int NameServerImpl::CreateTableRemoteTask(std::shared_ptr<OPData> op_data) { |
| 6550 | CreateTableData create_table_data; |
| 6551 | if (!create_table_data.ParseFromString(op_data->op_info_.data())) { |
| 6552 | PDLOG(WARNING, "parse create_table_data failed. data[%s]", op_data->op_info_.data().c_str()); |
| 6553 | return -1; |
| 6554 | } |
| 6555 | std::string alias = create_table_data.alias(); |
| 6556 | ::fedb::nameserver::TableInfo remote_table_info = create_table_data.remote_table_info(); |
| 6557 | uint64_t op_index = op_data->op_info_.op_id(); |
| 6558 | std::shared_ptr<Task> task = |
| 6559 | CreateTableRemoteTask(remote_table_info, alias, op_index, ::fedb::api::OPType::kCreateTableRemoteOP); |
| 6560 | if (!task) { |
| 6561 | PDLOG(WARNING, "create CreateTableRemote task failed. table[%s] pid[%u]", remote_table_info.name().c_str(), |
| 6562 | op_data->op_info_.pid()); |
| 6563 | return -1; |
| 6564 | } |
| 6565 | op_data->task_list_.push_back(task); |
| 6566 | |
| 6567 | ::fedb::nameserver::TableInfo table_info = create_table_data.table_info(); |
| 6568 | uint32_t tid = table_info.tid(); |
| 6569 | uint32_t remote_tid = remote_table_info.tid(); |
| 6570 | std::string name = table_info.name(); |
| 6571 | std::string db = table_info.db(); |
| 6572 | for (int idx = 0; idx < remote_table_info.table_partition_size(); idx++) { |
| 6573 | const ::fedb::nameserver::TablePartition& table_partition = remote_table_info.table_partition(idx); |
| 6574 | uint32_t pid = table_partition.pid(); |
| 6575 | for (int meta_idx = 0; meta_idx < table_partition.partition_meta_size(); meta_idx++) { |
| 6576 | if (table_partition.partition_meta(meta_idx).is_leader()) { |
| 6577 | const ::fedb::nameserver::PartitionMeta& partition_meta = table_partition.partition_meta(meta_idx); |
| 6578 | const std::string& endpoint = partition_meta.endpoint(); |
| 6579 | std::string leader_endpoint; |
| 6580 | std::shared_ptr<::fedb::nameserver::TableInfo> table_info_tmp = |
| 6581 | std::make_shared<::fedb::nameserver::TableInfo>(table_info); |
| 6582 | if (GetLeader(table_info_tmp, pid, leader_endpoint) < 0 || leader_endpoint.empty()) { |
| 6583 | PDLOG(WARNING, "get leader failed. table[%s] pid[%u]", name.c_str(), pid); |
| 6584 | return -1; |
| 6585 | } |
| 6586 | task = CreateAddReplicaRemoteTask(leader_endpoint, op_index, ::fedb::api::OPType::kCreateTableRemoteOP, |
| 6587 | tid, remote_tid, pid, endpoint, idx); |
| 6588 | if (!task) { |
| 6589 | PDLOG(WARNING, |
| 6590 | "create addreplica task failed. leader cluster " |
| 6591 | "tid[%u] replica cluster tid[%u] pid[%u]", |
| 6592 | tid, remote_tid, pid); |
| 6593 | return -1; |
| 6594 | } |
| 6595 | op_data->task_list_.push_back(task); |
| 6596 | task = CreateAddTableInfoTask(alias, endpoint, name, db, remote_tid, pid, op_index, |
| 6597 | ::fedb::api::OPType::kCreateTableRemoteOP); |
| 6598 | if (!task) { |
| 6599 | PDLOG(WARNING, "create addtableinfo task failed. tid[%u] pid[%u]", tid, pid); |
| 6600 | return -1; |
| 6601 | } |
| 6602 | op_data->task_list_.push_back(task); |
| 6603 | break; |
| 6604 | } |
| 6605 | } |
| 6606 | } |
nothing calls this directly
no test coverage detected