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

Method CheckMaster

phxqueue/store/store.cpp:397–438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

395
396
397comm::RetCode Store::CheckMaster(const int paxos_group_id, comm::proto::Addr &redirect_addr) {
398 QLVerb("CheckMaster");
399
400 comm::RetCode ret;
401
402 if (impl_->node->IsIMMaster(paxos_group_id))
403 return comm::RetCode::RET_OK;
404
405 auto &&node_info = impl_->node->GetMaster(paxos_group_id);
406 if (node_info.GetIP().empty() || 0 == node_info.GetPort() || "0.0.0.0" == node_info.GetIP())
407 return comm::RetCode::RET_ERR_NO_MASTER;
408
409 auto &&topic_id(impl_->topic_id);
410
411 shared_ptr<const config::StoreConfig> store_config;
412 if (comm::RetCode::RET_OK !=
413 (ret = config::GlobalConfig::GetThreadInstance()->
414 GetStoreConfig(topic_id, store_config))) {
415 QLErr("GetStoreConfigByPubID ret %d topic_id %d", as_integer(ret), topic_id);
416 return ret;
417 }
418
419 shared_ptr<const config::proto::Store> store;
420 if (comm::RetCode::RET_OK != (ret = store_config->GetStoreByAddr(impl_->addr, store))) {
421 QLErr("GetStoreByAddr ret %d", as_integer(ret));
422 return ret;
423 }
424
425 QLVerb("find master");
426 for (size_t i{0}; i < store->addrs_size(); ++i) {
427 auto &&tmp_addr = store->addrs(i);
428 if (tmp_addr.ip() == node_info.GetIP() &&
429 tmp_addr.paxos_port() == node_info.GetPort()) {
430 redirect_addr.CopyFrom(tmp_addr);
431 QLVerb("master found. redirect_addr(%s:%d)",
432 redirect_addr.ip().c_str(), redirect_addr.port());
433
434 return comm::RetCode::RET_ERR_NOT_MASTER;
435 }
436 }
437 return comm::RetCode::RET_ERR_RANGE_ADDR;
438}
439
440
441comm::RetCode Store::Add(const comm::proto::AddRequest &req, comm::proto::AddResponse &resp) {

Callers

nothing calls this directly

Calls 3

as_integerFunction · 0.85
GetStoreConfigMethod · 0.80
GetStoreByAddrMethod · 0.80

Tested by

no test coverage detected