| 3345 | } |
| 3346 | |
| 3347 | bool NameServerImpl::AddFieldToTablet(const std::vector<fedb::common::ColumnDesc>& cols, |
| 3348 | std::shared_ptr<TableInfo> table_info, fedb::common::VersionPair* new_pair) { |
| 3349 | std::set<std::string> endpoint_set; |
| 3350 | std::map<std::string, std::shared_ptr<TabletClient>> tablet_client_map; |
| 3351 | for (const auto& part : table_info->table_partition()) { |
| 3352 | for (const auto& meta : part.partition_meta()) { |
| 3353 | if (tablet_client_map.find(meta.endpoint()) != tablet_client_map.end()) { |
| 3354 | continue; |
| 3355 | } |
| 3356 | std::shared_ptr<TabletInfo> tablet = GetTabletInfo(meta.endpoint()); |
| 3357 | if (!tablet) { |
| 3358 | continue; |
| 3359 | } |
| 3360 | if (!tablet->Health()) { |
| 3361 | LOG(WARNING) << "endpoint[" << meta.endpoint() << "] is offline"; |
| 3362 | return false; |
| 3363 | } |
| 3364 | tablet_client_map.insert(std::make_pair(meta.endpoint(), tablet->client_)); |
| 3365 | } |
| 3366 | } |
| 3367 | const std::string& name = table_info->name(); |
| 3368 | int32_t version_id = 1; |
| 3369 | if (table_info->schema_versions_size() > 0) { |
| 3370 | int32_t versions_size = table_info->schema_versions_size(); |
| 3371 | const auto& pair = table_info->schema_versions(versions_size - 1); |
| 3372 | version_id = pair.id(); |
| 3373 | } |
| 3374 | if (version_id >= UINT8_MAX) { |
| 3375 | LOG(WARNING) << "reach max version " << UINT8_MAX << " table " << name; |
| 3376 | return false; |
| 3377 | } |
| 3378 | uint32_t field_count = table_info->column_desc_size() + table_info->added_column_desc_size(); |
| 3379 | version_id++; |
| 3380 | new_pair->set_id(version_id); |
| 3381 | new_pair->set_field_count(field_count); |
| 3382 | |
| 3383 | uint32_t tid = table_info->tid(); |
| 3384 | std::string msg; |
| 3385 | std::vector<fedb::common::ColumnDesc> new_cols; |
| 3386 | for (auto it = tablet_client_map.begin(); it != tablet_client_map.end(); it++) { |
| 3387 | if (!it->second->UpdateTableMetaForAddField(tid, cols, *new_pair, msg)) { |
| 3388 | LOG(WARNING) << "update table_meta on endpoint[" << it->first << "for add table field failed! err: " << msg; |
| 3389 | return false; |
| 3390 | } |
| 3391 | LOG(INFO) << "update table_meta on endpoint[" << it->first << "] for add table field success! version is " |
| 3392 | << version_id << " columns size is " << field_count << " for table " << table_info->name(); |
| 3393 | } |
| 3394 | return true; |
| 3395 | } |
| 3396 | |
| 3397 | void NameServerImpl::AddTableField(RpcController* controller, const AddTableFieldRequest* request, |
| 3398 | GeneralResponse* response, Closure* done) { |
nothing calls this directly
no test coverage detected