Ejemplo n.º 1
0
void changeMaster(const node& nd, const masterNode& master, database_ptr db,
        connMgr_ptr mgr,  binlogPos* bpos, haNotify* nf)
{
    _TCHAR host[MAX_PATH];
    _TCHAR port[20];
    endPoint(db->uri(), host, MAX_PATH, port, 20);
    if (port[0])
    {
        _tcscat_s(host, MAX_PATH -_tcslen(host), _T(":"));
        _tcscat_s(host, MAX_PATH -_tcslen(host), port);
    }

    replicationParam pm;
    pm.master = master;
    pm.type = isMariadb(db) ? REP_TYPE_GTID_MA : REP_TYPE_GTID_MY;
    pm.master.channel = getChannlName(mgr, nd.host.c_str());

    nfSetHostName(nf, host);
    notify(nf, HA_NF_CANNELNAME, pm.master.channel.c_str());
    replSlave rpl(db, pm, mgr.get());
    rpl.stop(all);
    notify(nf, HA_SLAVE_STOP_ALL, _T(""));
    if (bpos)
    {
        rpl.changeMaster(bpos);
        notify(nf, HA_CHANGE_MASTER, bpos->gtid);
    }
    else
    {
        rpl.switchMaster(replSlave::slave_pos);
        notify(nf, HA_SWITCH_MASTER, "slave_pos");
    }
    rpl.start();
    notify(nf, HA_SLAVE_START, _T(""));
}
Ejemplo n.º 2
0
/* --------------------------------------------------------------------------------
 */
void createTestDataBase(database_ptr db, connectParams& params)
{
    params.setMode(TD_OPEN_EXCLUSIVE);
    createDatabase(db, params);
    openDatabase(db, params);
    createUserTableSchema(db->dbDef());
}
Ejemplo n.º 3
0
// =-=-=-=-=-=-=-
// function to load and return an initialized database plugin
    error load_database_plugin(
        database_ptr&      _plugin,
        const std::string& _plugin_name,
        const std::string& _inst_name,
        const std::string& _context ) {
        // =-=-=-=-=-=-=-
        // resolve plugin directory
        std::string plugin_home;
        error ret = resolve_plugin_path( PLUGIN_TYPE_DATABASE, plugin_home );
        if( !ret.ok() ) {
            return PASS( ret );
        }

        // =-=-=-=-=-=-=-
        // call generic plugin loader
        database* db = 0;
        ret = load_plugin< database >(
                  db,
                  _plugin_name,
                  plugin_home,
                  _inst_name,
                  _context );
        if ( ret.ok() && db ) {
            _plugin.reset( db );
            return SUCCESS();

        }
        else {
            return PASS( ret );

        }

    } // load_database_plugin
Ejemplo n.º 4
0
bool isMariadb(database_ptr db)
{
    btrVersions vers;
    db->getBtrVersion(&vers);
    validateStatus(db, _T("isMariadb"));
    btrVersion ver = vers.versions[VER_IDX_DB_SERVER];
    return ver.isMariaDB();
}
Ejemplo n.º 5
0
connMgr_ptr getMasterMgr(database_ptr db, const node& nd)
{
    connMgr_ptr mgr = createConnMgr(db.get());
    connectParams cp(_T("tdap"), nd.host.c_str(),
     _T(""), NULL, nd.user.c_str(), nd.passwd.c_str());
    mgr->connect(cp.uri());
    validateStatus(mgr, _T("getMasterMgr"));
    return  mgr;
}
Ejemplo n.º 6
0
 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"));
     }
 }
Ejemplo n.º 7
0
connMgr_ptr createMgr(database_ptr db, const _TCHAR* host, const node& nd, bool throwError)
{
    connectParams cp(_T("tdap"), host, _T(""), NULL,
                                nd.user.c_str(), nd.passwd.c_str());
        
    connMgr_ptr mgr = createConnMgr(db.get());
    if (!mgr->connect(cp.uri()))
    {
        if (throwError)
            validateStatus(mgr, _T("connMgr connect"));
    }
    return mgr;
}
Ejemplo n.º 8
0
    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(""));
        }
    }
 void set_iterator(database_ptr& db, const data_chunk& raw_address)
 {
     it_.reset(db->NewIterator(leveldb::ReadOptions()));
     it_->Seek(slice(raw_address));
 }
Ejemplo n.º 10
0
 ~masterReadOnly()
 {
     if (m_db)
         m_db->execSql("set global read_only=OFF");
 }
Ejemplo n.º 11
0
 void check()
 {
     m_db.reset();
 }