MCPcopy Create free account
hub / github.com/Tencent/phxsql / MasterInit

Method MasterInit

phxbinlogsvr/core/monitor/agent_monitor.cpp:209–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

207}
208
209int AgentMonitor::MasterInit() {
210 MasterInfo master_info;
211 int ret = master_manager_->GetMasterInfo(&master_info);
212 if (ret) {
213 return ret;
214 }
215
216 LogVerbose("%s master info %u version %u", __func__, master_info.svr_id(), master_info.version());
217
218 if (master_info.svr_id() == option_->GetBinLogSvrConfig()->GetEngineSvrID()
219 && !master_manager_->IsTimeOut(master_info)) {
220 if (!init_) {
221 //do not check root privilege beacuse its readonly option has not been set
222 //after master has beed started, check again
223 ret = MasterMonitor::CheckMasterInit(option_);
224 if (ret == OK) {
225 if (!MasterMonitor::IsMySqlInit(option_)) {
226 MySqlManager * mysql_manager = MySqlManager::GetGlobalMySqlManager(option_);
227 string current_admin_username = mysql_manager->GetAdminUserName();
228 string current_admin_pwd = mysql_manager->GetAdminPwd();
229 if (current_admin_username == "") {
230 ret = master_agent_->SetMySqlAdminInfo("", "", "root", "");
231
232 if (ret) {
233 ColorLogError("%s master set admin info failed ", __func__);
234 return ret;
235 }
236 }
237
238 string current_replica_username = mysql_manager->GetReplicaUserName();
239 string current_replica_pwd = mysql_manager->GetReplicaPwd();
240 if (current_replica_username == "") {
241 ret = master_agent_->SetMySqlReplicaInfo("", "", "replica", "replica123");
242 if (ret) {
243 ColorLogError("%s master set replica info failed ", __func__);
244 return ret;
245 }
246 }
247 init_ = true;
248 }
249 LogVerbose("%s master init done, version %u", __func__, master_info.version());
250 }
251 } else
252 LogVerbose("%s master init has done, version %u, skip check init", __func__, master_info.version());
253 } else {
254 LogVerbose("%s i'm not master, skip check init", __func__);
255 }
256
257 return ret;
258}
259
260int AgentMonitor::CheckMasterInit() {
261 int ret = OK;

Callers

nothing calls this directly

Calls 12

LogVerboseFunction · 0.85
ColorLogErrorFunction · 0.85
GetMasterInfoMethod · 0.80
GetEngineSvrIDMethod · 0.80
GetBinLogSvrConfigMethod · 0.80
IsTimeOutMethod · 0.45
GetAdminUserNameMethod · 0.45
GetAdminPwdMethod · 0.45
SetMySqlAdminInfoMethod · 0.45
GetReplicaUserNameMethod · 0.45
GetReplicaPwdMethod · 0.45
SetMySqlReplicaInfoMethod · 0.45

Tested by

no test coverage detected