MCPcopy Create free account
hub / github.com/Tencent/phxqueue / KeepMaster

Method KeepMaster

phxqueue/store/keepmasterthread.cpp:153–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151}
152
153void 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);

Callers

nothing calls this directly

Calls 10

as_integerFunction · 0.85
GetStoreOptionMethod · 0.80
GetStoreConfigMethod · 0.80
GetStoreByAddrMethod · 0.80
GetTopicIDMethod · 0.45
GetNodeMethod · 0.45
NeedDropMasterMethod · 0.45
OnIMMasterMethod · 0.45
OnSnatchMasterMethod · 0.45

Tested by

no test coverage detected