| 1611 | } |
| 1612 | |
| 1613 | int NameServerImpl::UpdateTaskStatus(bool is_recover_op) { |
| 1614 | std::map<std::string, std::shared_ptr<TabletClient>> client_map; |
| 1615 | { |
| 1616 | std::lock_guard<std::mutex> lock(mu_); |
| 1617 | for (auto iter = tablets_.begin(); iter != tablets_.end(); ++iter) { |
| 1618 | if (iter->second->state_ != ::fedb::api::TabletState::kTabletHealthy) { |
| 1619 | DEBUGLOG("tablet[%s] is not Healthy", iter->first.c_str()); |
| 1620 | uint64_t cur_time = ::baidu::common::timer::get_micros() / 1000; |
| 1621 | if (cur_time < iter->second->ctime_ + FLAGS_tablet_heartbeat_timeout) { |
| 1622 | continue; |
| 1623 | } |
| 1624 | // clear the task in offline tablet |
| 1625 | for (const auto& op_list : task_vec_) { |
| 1626 | if (op_list.empty()) { |
| 1627 | continue; |
| 1628 | } |
| 1629 | std::shared_ptr<OPData> op_data = op_list.front(); |
| 1630 | if (op_data->task_list_.empty()) { |
| 1631 | continue; |
| 1632 | } |
| 1633 | // update task status |
| 1634 | std::shared_ptr<Task> task = op_data->task_list_.front(); |
| 1635 | if (task->task_info_->status() != ::fedb::api::kDoing) { |
| 1636 | continue; |
| 1637 | } |
| 1638 | if (task->task_info_->has_endpoint() && task->task_info_->endpoint() == iter->first) { |
| 1639 | PDLOG(WARNING, |
| 1640 | "tablet is offline. update task status " |
| 1641 | "from[kDoing] to[kFailed]. " |
| 1642 | "op_id[%lu], task_type[%s] endpoint[%s]", |
| 1643 | op_data->op_info_.op_id(), |
| 1644 | ::fedb::api::TaskType_Name(task->task_info_->task_type()).c_str(), iter->first.c_str()); |
| 1645 | task->task_info_->set_status(::fedb::api::kFailed); |
| 1646 | } |
| 1647 | } |
| 1648 | } else { |
| 1649 | client_map.insert(std::make_pair(iter->first, iter->second->client_)); |
| 1650 | } |
| 1651 | } |
| 1652 | } |
| 1653 | uint64_t last_task_rpc_version = task_rpc_version_.load(std::memory_order_acquire); |
| 1654 | for (auto iter = client_map.begin(); iter != client_map.end(); ++iter) { |
| 1655 | ::fedb::api::TaskStatusResponse response; |
| 1656 | // get task status from tablet |
| 1657 | if (iter->second->GetTaskStatus(response)) { |
| 1658 | std::lock_guard<std::mutex> lock(mu_); |
| 1659 | if (last_task_rpc_version != task_rpc_version_.load(std::memory_order_acquire)) { |
| 1660 | DEBUGLOG("task_rpc_version mismatch"); |
| 1661 | break; |
| 1662 | } |
| 1663 | std::string endpoint = iter->first; |
| 1664 | for (const auto& op_list : task_vec_) { |
| 1665 | std::string endpoint_role = "tablet"; |
| 1666 | if (UpdateTask(op_list, endpoint, endpoint_role, is_recover_op, response) < 0) { |
| 1667 | continue; |
| 1668 | } |
| 1669 | } |
| 1670 | } |
nothing calls this directly
no test coverage detected