| 151 | } |
| 152 | |
| 153 | void KeepMasterThread::KeepMaster() { |
| 154 | comm::RetCode ret; |
| 155 | |
| 156 | const int topic_id(impl_->store->GetTopicID()); |
| 157 | |
| 158 | shared_ptr<const config::TopicConfig> topic_config; |
| 159 | if (comm::RetCode::RET_OK != |
| 160 | (ret = config::GlobalConfig::GetThreadInstance()-> |
| 161 | GetTopicConfigByTopicID(topic_id, topic_config))) { |
| 162 | QLErr("GetTopicConfigByTopicID ret %d topic_id %d", ret, topic_id); |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | auto opt(impl_->store->GetStoreOption()); |
| 167 | |
| 168 | comm::proto::Addr addr; |
| 169 | addr.set_ip(opt->ip); |
| 170 | addr.set_port(opt->port); |
| 171 | addr.set_paxos_port(opt->paxos_port); |
| 172 | |
| 173 | shared_ptr<const config::StoreConfig> store_config; |
| 174 | if (comm::RetCode::RET_OK != |
| 175 | (ret = config::GlobalConfig::GetThreadInstance()-> |
| 176 | GetStoreConfig(topic_id, store_config))) { |
| 177 | QLErr("GetStoreConfig ret %d topic_id %d", as_integer(ret), topic_id); |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | shared_ptr<const config::proto::Store> store; |
| 182 | if (comm::RetCode::RET_OK != (ret = store_config->GetStoreByAddr(addr, store))) { |
| 183 | QLErr("GetStoreByAddr ret %d", as_integer(ret)); |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | int idx_in_store{-1}; |
| 188 | for (size_t i{0}; i < store->addrs_size(); ++i) { |
| 189 | if (addr.ip() == store->addrs(i).ip() && |
| 190 | addr.port() == store->addrs(i).port() && |
| 191 | addr.paxos_port() == store->addrs(i).paxos_port()) { |
| 192 | idx_in_store = i; |
| 193 | break; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | auto node(impl_->store->GetNode()); |
| 198 | |
| 199 | if (-1 == idx_in_store) return; |
| 200 | |
| 201 | for (int paxos_group_id{0}; paxos_group_id < opt->ngroup; ++paxos_group_id) { |
| 202 | if (static_cast<double>(paxos_group_id) / opt->ngroup * 100.0 + 0.5 > impl_->master_rate) { |
| 203 | QLInfo("MASTERSTAT: master_rate too low, need drop master. " |
| 204 | "paxos_group_id %d master_rate %d", paxos_group_id, impl_->master_rate); |
| 205 | node->DropMaster(paxos_group_id); |
| 206 | continue; |
| 207 | } |
| 208 | |
| 209 | if (impl_->store->NeedDropMaster(paxos_group_id)) { |
| 210 | QLInfo("MASTERSTAT: NeedDropMaster return true. paxos_group_id %d", paxos_group_id); |
nothing calls this directly
no test coverage detected