| 7558 | } |
| 7559 | |
| 7560 | void NameServerImpl::UpdateTableAliveStatus(RpcController* controller, const UpdateTableAliveRequest* request, |
| 7561 | GeneralResponse* response, Closure* done) { |
| 7562 | brpc::ClosureGuard done_guard(done); |
| 7563 | if (!running_.load(std::memory_order_acquire)) { |
| 7564 | response->set_code(::fedb::base::ReturnCode::kNameserverIsNotLeader); |
| 7565 | response->set_msg("nameserver is not leader"); |
| 7566 | PDLOG(WARNING, "cur nameserver is not leader"); |
| 7567 | return; |
| 7568 | } |
| 7569 | if (auto_failover_.load(std::memory_order_acquire)) { |
| 7570 | response->set_code(::fedb::base::ReturnCode::kAutoFailoverIsEnabled); |
| 7571 | response->set_msg("auto_failover is enabled"); |
| 7572 | PDLOG(WARNING, "auto_failover is enabled"); |
| 7573 | return; |
| 7574 | } |
| 7575 | std::lock_guard<std::mutex> lock(mu_); |
| 7576 | std::string name = request->name(); |
| 7577 | std::string endpoint = request->endpoint(); |
| 7578 | if (tablets_.find(endpoint) == tablets_.end()) { |
| 7579 | PDLOG(WARNING, "endpoint[%s] is not exist", endpoint.c_str()); |
| 7580 | response->set_code(::fedb::base::ReturnCode::kEndpointIsNotExist); |
| 7581 | response->set_msg("endpoint is not exist"); |
| 7582 | return; |
| 7583 | } |
| 7584 | std::shared_ptr<::fedb::nameserver::TableInfo> table_info; |
| 7585 | if (!GetTableInfoUnlock(request->name(), request->db(), &table_info)) { |
| 7586 | PDLOG(WARNING, "table [%s] is not exist", name.c_str()); |
| 7587 | response->set_code(::fedb::base::ReturnCode::kTableIsNotExist); |
| 7588 | response->set_msg("table is not exist"); |
| 7589 | return; |
| 7590 | } |
| 7591 | std::shared_ptr<::fedb::nameserver::TableInfo> cur_table_info(table_info->New()); |
| 7592 | cur_table_info->CopyFrom(*table_info); |
| 7593 | bool has_update = false; |
| 7594 | for (int idx = 0; idx < cur_table_info->table_partition_size(); idx++) { |
| 7595 | if (request->has_pid() && cur_table_info->table_partition(idx).pid() != request->pid()) { |
| 7596 | continue; |
| 7597 | } |
| 7598 | for (int meta_idx = 0; meta_idx < cur_table_info->table_partition(idx).partition_meta_size(); meta_idx++) { |
| 7599 | if (cur_table_info->table_partition(idx).partition_meta(meta_idx).endpoint() == endpoint) { |
| 7600 | ::fedb::nameserver::TablePartition* table_partition = cur_table_info->mutable_table_partition(idx); |
| 7601 | ::fedb::nameserver::PartitionMeta* partition_meta = table_partition->mutable_partition_meta(meta_idx); |
| 7602 | partition_meta->set_is_alive(request->is_alive()); |
| 7603 | std::string is_alive = request->is_alive() ? "true" : "false"; |
| 7604 | PDLOG(INFO, "update status[%s]. name[%s] endpoint[%s] pid[%u]", is_alive.c_str(), name.c_str(), |
| 7605 | endpoint.c_str(), cur_table_info->table_partition(idx).pid()); |
| 7606 | has_update = true; |
| 7607 | break; |
| 7608 | } |
| 7609 | } |
| 7610 | } |
| 7611 | if (has_update) { |
| 7612 | if (UpdateZkTableNode(cur_table_info)) { |
| 7613 | PDLOG(INFO, "update alive status ok. name[%s] endpoint[%s]", name.c_str(), endpoint.c_str()); |
| 7614 | table_info->CopyFrom(*cur_table_info); |
| 7615 | response->set_code(::fedb::base::ReturnCode::kOk); |
| 7616 | response->set_msg("ok"); |
| 7617 | } else { |
nothing calls this directly
no outgoing calls
no test coverage detected