| 96 | } |
| 97 | |
| 98 | void RandomKeySelector::Update() { |
| 99 | tera::ErrorCode err; |
| 100 | while (true) { |
| 101 | { |
| 102 | MutexLock locker(&quit_mutex_); |
| 103 | if (quit_) { |
| 104 | return; |
| 105 | } |
| 106 | cond_.TimeWaitInUs(FLAGS_observer_update_table_info_period_s * 1000000); |
| 107 | } |
| 108 | |
| 109 | // update data first |
| 110 | std::shared_ptr<std::map<std::string, std::vector<tera::TabletInfo>>> table_update_copy( |
| 111 | new std::map<std::string, std::vector<tera::TabletInfo>>); |
| 112 | |
| 113 | // updated table |
| 114 | for (uint32_t i = 0; i < observe_tables_.size(); ++i) { |
| 115 | std::string table_name = observe_tables_[i]; |
| 116 | |
| 117 | std::vector<tera::TabletInfo> tablets; |
| 118 | client_->GetTabletLocation(table_name, &tablets, &err); |
| 119 | if (tera::ErrorCode::kOK != err.GetType()) { |
| 120 | LOG(ERROR) << "Update table info failed, tablename:" << table_name |
| 121 | << " err:" << err.ToString(); |
| 122 | continue; |
| 123 | } |
| 124 | |
| 125 | table_update_copy->insert( |
| 126 | std::pair<std::string, std::vector<tera::TabletInfo>>(table_name, tablets)); |
| 127 | } |
| 128 | |
| 129 | // update pointer |
| 130 | MutexLock locker(&table_mutex_); |
| 131 | tables_.swap(table_update_copy); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | } // namespace observer |
| 136 | } // namespace tera |
nothing calls this directly
no test coverage detected