masterReadOnly(const node& nd, bool toReadOnly) { if (toReadOnly) { m_db = createDb(nd.host.c_str(), nd.user.c_str(), nd.passwd.c_str(), true); //db->execSql("flush tables with read lock"); //validateStatus(db, _T("flush tables")); m_db->execSql("set global read_only=ON"); validateStatus(m_db, _T("read_only ON")); } }
void promoteMaster(const masterNode& master, database_ptr db, connMgr_ptr mgr, binlogPos* bpos, bool readOnlyControl) { replicationParam pm; pm.master = master; pm.type = isMariadb(db) ? REP_TYPE_GTID_MA : REP_TYPE_GTID_MY; if (m_isSwitchOver) { pm.master.channel = getChannlName(mgr, m_nd.host.c_str()); const_cast<masterNode&>(master).channel = pm.master.channel; } else pm.master.channel = m_channel; nfSetHostName(m_nf, master.host.c_str()); notify(m_nf, HA_NF_PROMOTE_MASTER, _T("")); notify(m_nf, HA_NF_PROMOTE_CHANNEL, m_channel.c_str()); replSlave rpl(db, pm, mgr.get()); rpl.stop(one); setMasterRoleStatus(mgr); notify(m_nf, HA_NF_ROLE_MASTER, _T("")); if (bpos) { // Sync SQLthread binlog pos to old master rpl.startUntil(*bpos); notify(m_nf, HA_NF_WAIT_POS_START, _T("")); rpl.waitForSlaveSync(*bpos, 2, NULL); notify(m_nf, HA_NF_WAIT_POS_COMP, *bpos); rpl.stop(one); notify(m_nf, HA_SLAVE_STOP, _T("")); } rpl.resetAll(); // reset only this channel if (readOnlyControl) { db->execSql("set global read_only=OFF"); validateStatus(db, _T("read_only off")); notify(m_nf, HA_SET_READ_ONLY, _T("")); } }
~masterReadOnly() { if (m_db) m_db->execSql("set global read_only=OFF"); }