| 5350 | } |
| 5351 | |
| 5352 | void NameServerImpl::UpdateTableStatusFun( |
| 5353 | const std::map<std::string, std::shared_ptr<TableInfo>>& table_info_map, |
| 5354 | const std::unordered_map<std::string, ::fedb::api::TableStatus>& pos_response) { |
| 5355 | std::lock_guard<std::mutex> lock(mu_); |
| 5356 | for (const auto& kv : table_info_map) { |
| 5357 | uint32_t tid = kv.second->tid(); |
| 5358 | std::string first_index_col; |
| 5359 | if (kv.second->column_key_size() > 0) { |
| 5360 | first_index_col = kv.second->column_key(0).index_name(); |
| 5361 | } |
| 5362 | for (int idx = 0; idx < kv.second->table_partition_size(); idx++) { |
| 5363 | uint32_t pid = kv.second->table_partition(idx).pid(); |
| 5364 | ::fedb::nameserver::TablePartition* table_partition = kv.second->mutable_table_partition(idx); |
| 5365 | ::google::protobuf::RepeatedPtrField<::fedb::nameserver::PartitionMeta>* partition_meta_field = |
| 5366 | table_partition->mutable_partition_meta(); |
| 5367 | for (int meta_idx = 0; meta_idx < kv.second->table_partition(idx).partition_meta_size(); meta_idx++) { |
| 5368 | std::string endpoint = kv.second->table_partition(idx).partition_meta(meta_idx).endpoint(); |
| 5369 | bool tablet_has_partition = false; |
| 5370 | ::fedb::nameserver::PartitionMeta* partition_meta = partition_meta_field->Mutable(meta_idx); |
| 5371 | std::string pos_key = std::to_string(tid) + "_" + std::to_string(pid) + "_" + endpoint; |
| 5372 | auto pos_response_iter = pos_response.find(pos_key); |
| 5373 | if (pos_response_iter != pos_response.end()) { |
| 5374 | const ::fedb::api::TableStatus& table_status = pos_response_iter->second; |
| 5375 | partition_meta->set_offset(table_status.offset()); |
| 5376 | partition_meta->set_record_byte_size(table_status.record_byte_size() + |
| 5377 | table_status.record_idx_byte_size()); |
| 5378 | uint64_t record_cnt = table_status.record_cnt(); |
| 5379 | if (!first_index_col.empty()) { |
| 5380 | for (int pos = 0; pos < table_status.ts_idx_status_size(); pos++) { |
| 5381 | if (table_status.ts_idx_status(pos).idx_name() == first_index_col) { |
| 5382 | record_cnt = 0; |
| 5383 | for (int seg_idx = 0; seg_idx < table_status.ts_idx_status(pos).seg_cnts_size(); |
| 5384 | seg_idx++) { |
| 5385 | record_cnt += table_status.ts_idx_status(pos).seg_cnts(seg_idx); |
| 5386 | } |
| 5387 | break; |
| 5388 | } |
| 5389 | } |
| 5390 | } |
| 5391 | partition_meta->set_record_cnt(record_cnt); |
| 5392 | partition_meta->set_diskused(table_status.diskused()); |
| 5393 | if (kv.second->table_partition(idx).partition_meta(meta_idx).is_alive() && |
| 5394 | kv.second->table_partition(idx).partition_meta(meta_idx).is_leader()) { |
| 5395 | table_partition->set_record_cnt(record_cnt); |
| 5396 | table_partition->set_record_byte_size(table_status.record_byte_size() + |
| 5397 | table_status.record_idx_byte_size()); |
| 5398 | table_partition->set_diskused(table_status.diskused()); |
| 5399 | } |
| 5400 | tablet_has_partition = true; |
| 5401 | } |
| 5402 | partition_meta->set_tablet_has_partition(tablet_has_partition); |
| 5403 | } |
| 5404 | } |
| 5405 | } |
| 5406 | } |
| 5407 | |
| 5408 | int NameServerImpl::CreateDelReplicaOP(const std::string& name, const std::string& db, uint32_t pid, |
| 5409 | const std::string& endpoint) { |