Beispiel #1
0
    // Our own config must be the first one.
    bool ReplSetImpl::_loadConfigFinish(OperationContext* txn, vector<ReplSetConfig*>& cfgs) {
        int v = -1;
        ReplSetConfig *highest = 0;
        int myVersion = -2000;
        int n = 0;
        for (vector<ReplSetConfig*>::iterator i = cfgs.begin(); i != cfgs.end(); i++) {
            ReplSetConfig* cfg = *i;
            DEV { LOG(1) << n+1 << " config shows version " << cfg->version << rsLog; }
            if (++n == 1) myVersion = cfg->version;
            if (cfg->ok() && cfg->version > v) {
                highest = cfg;
                v = cfg->version;
            }
        }
        verify(highest);

        if (!initFromConfig(txn, *highest))
            return false;

        if (highest->version > myVersion && highest->version >= 0) {
            log() << "replSet got config version " << highest->version
                  << " from a remote, saving locally" << rsLog;
            highest->saveConfigLocally(txn, BSONObj());
        }
        return true;
    }
Beispiel #2
0
    void ReplSet::haveNewConfig(ReplSetConfig& newConfig, bool addComment) {
        bo comment;
        if( addComment )
            comment = BSON( "msg" << "Reconfig set" << "version" << newConfig.version );

        newConfig.saveConfigLocally(comment);

        try {
            BSONObj oldConfForAudit = config().asBson();
            BSONObj newConfForAudit = newConfig.asBson();
            audit::logReplSetReconfig(ClientBasic::getCurrent(),
                                      &oldConfForAudit,
                                      &newConfForAudit);
            if (initFromConfig(newConfig, true)) {
                log() << "replSet replSetReconfig new config saved locally" << rsLog;
            }
        }
        catch(DBException& e) {
            log() << "replSet error unexpected exception in haveNewConfig() : " << e.toString() << rsLog;
            _fatal();
        }
        catch(...) {
            log() << "replSet error unexpected exception in haveNewConfig()" << rsLog;
            _fatal();
        }
    }
Beispiel #3
0
    void ReplSet::haveNewConfig(OperationContext* txn, ReplSetConfig& newConfig, bool addComment) {
        bo comment;
        if( addComment )
            comment = BSON( "msg" << "Reconfig set" << "version" << newConfig.version );

        newConfig.saveConfigLocally(txn, comment);

        try {
            BSONObj oldConfForAudit = config().asBson();
            BSONObj newConfForAudit = newConfig.asBson();
            audit::logReplSetReconfig(ClientBasic::getCurrent(),
                                      &oldConfForAudit,
                                      &newConfForAudit);
            if (initFromConfig(txn, newConfig, true)) {
                log() << "replSet replSetReconfig new config saved locally" << rsLog;
            }
        }
        catch (const DBException& e) {
            log() << "replSet error unexpected exception in haveNewConfig() : " << e.toString() << rsLog;
            fassertFailedNoTrace(18755);
        }
        catch (...) {
            std::terminate();
        }
    }
Beispiel #4
0
Datei: rs.cpp Projekt: sivy/mongo
    // Our own config must be the first one.
    bool ReplSetImpl::_loadConfigFinish(vector<ReplSetConfig>& cfgs) { 
        int v = -1;
        ReplSetConfig *highest = 0;
        int myVersion = -2000;
        int n = 0;
        for( vector<ReplSetConfig>::iterator i = cfgs.begin(); i != cfgs.end(); i++ ) { 
            ReplSetConfig& cfg = *i;
            if( ++n == 1 ) myVersion = cfg.version;
            if( cfg.ok() && cfg.version > v ) { 
                highest = &cfg;
                v = cfg.version;
            }
        }
        assert( highest );

        if( !initFromConfig(*highest) ) 
            return false;

        if( highest->version > myVersion && highest->version >= 0 ) { 
            log() << "replSet got config version " << highest->version << " from a remote, saving locally" << rsLog;
            writelock lk("admin.");
            highest->saveConfigLocally(BSONObj());
        }
        return true;
    }
Beispiel #5
0
void ReplSet::haveNewConfig(ReplSetConfig& newConfig, bool addComment) {
    bo comment;
    if( addComment )
        comment = BSON( "msg" << "Reconfig set" << "version" << newConfig.version );

    newConfig.saveConfigLocally(comment);

    try {
        if (initFromConfig(newConfig, true)) {
            log() << "replSet replSetReconfig new config saved locally" << rsLog;
        }
    }
    catch(DBException& e) {
        if( e.getCode() == 13497 /* removed from set */ ) {
            cc().shutdown();
            dbexit( EXIT_CLEAN , "removed from replica set" ); // never returns
            assert(0);
        }
        log() << "replSet error unexpected exception in haveNewConfig() : " << e.toString() << rsLog;
        _fatal();
    }
    catch(...) {
        log() << "replSet error unexpected exception in haveNewConfig()" << rsLog;
        _fatal();
    }
}
Beispiel #6
0
 void ReplSet::haveNewConfig(ReplSetConfig& newConfig, bool addComment) { 
     lock l(this); // convention is to lock replset before taking the db rwlock
     writelock lk("");
     bo comment;
     if( addComment )
         comment = BSON( "msg" << "Reconfig set" << "version" << newConfig.version );
     newConfig.saveConfigLocally(comment);
     try { 
         initFromConfig(newConfig, true);
         log() << "replSet replSetReconfig new config saved locally" << rsLog;
     }
     catch(DBException& e) { 
         log() << "replSet error unexpected exception in haveNewConfig() : " << e.toString() << rsLog;
         _fatal();
     }
     catch(...) { 
         log() << "replSet error unexpected exception in haveNewConfig()" << rsLog;
         _fatal();
     }
 }
Beispiel #7
0
    void ReplSet::haveNewConfig(ReplSetConfig& newConfig, bool addComment) {
        bo comment;
        if( addComment )
            comment = BSON( "msg" << "Reconfig set" << "version" << newConfig.version );

        newConfig.saveConfigLocally(comment);

        try {
            if (initFromConfig(newConfig, true)) {
                log() << "replSet replSetReconfig new config saved locally" << rsLog;
            }
        }
        catch(DBException& e) {
            log() << "replSet error unexpected exception in haveNewConfig() : " << e.toString() << rsLog;
            _fatal();
        }
        catch(...) {
            log() << "replSet error unexpected exception in haveNewConfig()" << rsLog;
            _fatal();
        }
    }