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

Method KeepMaster

phxqueue/scheduler/keepmasterthread.cpp:120–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120comm::RetCode KeepMasterThread::KeepMaster() {
121 const int topic_id{impl_->scheduler->GetTopicID()};
122
123 comm::SchedulerKeepMasterBP::GetThreadInstance()->OnKeepMaster(topic_id);
124
125 if (impl_->scheduler->NeedDropMaster()) {
126 QLInfo("MASTERSTAT: NeedDropMaster return true");
127
128 return comm::RetCode::RET_ERR_SVR_BLOCK;
129 }
130
131 comm::RetCode ret;
132
133 string client_id{impl_->scheduler->GetSchedulerOption()->ip};
134
135 int lock_id{-1};
136 if (comm::RetCode::RET_OK != (ret = GetLockID(lock_id))) {
137 QLErr("GetLockID ret %d", as_integer(ret));
138
139 return ret;
140 }
141
142 shared_ptr<const config::TopicConfig> topic_config;
143 if (comm::RetCode::RET_OK != (ret = config::GlobalConfig::GetThreadInstance()->GetTopicConfigByTopicID(topic_id, topic_config))) {
144 QLErr("GetTopicConfigByTopicID ret %d", as_integer(ret));
145
146 return ret;
147 }
148
149 const string lock_key(topic_config->GetProto().topic().scheduler_lock_key());
150
151 static thread_local uint64_t version{0};
152 static thread_local uint64_t overdue_time_ms{0};
153 uint64_t now{comm::utils::Time::GetSteadyClockMS()};
154 bool need_acquire_lock{false};
155 {
156 comm::proto::GetLockInfoRequest req;
157 comm::proto::GetLockInfoResponse resp;
158 req.set_topic_id(topic_id);
159 req.set_lock_id(lock_id);
160 req.set_lock_key(lock_key);
161 ret = impl_->scheduler->RawGetLockInfo(req, resp);
162 if (comm::RetCode::RET_ERR_KEY_NOT_EXIST != ret && comm::RetCode::RET_OK != ret) {
163 QLErr("MASTERSTAT: RawGetLockInfo err %d", as_integer(ret));
164 comm::SchedulerKeepMasterBP::GetThreadInstance()->OnRawGetLockInfoFail(topic_id, req);
165
166 return ret;
167 }
168 comm::SchedulerKeepMasterBP::GetThreadInstance()->OnRawGetLockInfoSucc(topic_id, req, resp);
169
170 QLInfo("MASTERSTAT: RawGetLockInfo ret %d lock_key %s old_version %" PRIu64 " old_overdue_time_ms %" PRIu64, as_integer(ret), lock_key.c_str(), version, overdue_time_ms);
171 if (comm::RetCode::RET_ERR_KEY_NOT_EXIST == ret) {
172 version = 0;
173 overdue_time_ms = now;
174 } else if (version != resp.lock_info().version()) {
175 version = resp.lock_info().version();
176 overdue_time_ms = now + resp.lock_info().lease_time_ms();
177 }

Callers

nothing calls this directly

Calls 15

as_integerFunction · 0.85
OnKeepMasterMethod · 0.80
GetSchedulerOptionMethod · 0.80
RawGetLockInfoMethod · 0.80
OnRawGetLockInfoFailMethod · 0.80
OnRawGetLockInfoSuccMethod · 0.80
RawAcquireLockMethod · 0.80
RenewMasterMethod · 0.80
GetSchedulerMgrMethod · 0.80
GetTopicIDMethod · 0.45
NeedDropMasterMethod · 0.45

Tested by

no test coverage detected