예제 #1
0
    /* grab initial copy of a database from the master */
    void ReplSource::resync(const std::string& dbName) {
        const std::string db(dbName);   // need local copy of the name, we're dropping the original
        string dummyNs = resyncDrop( db.c_str(), "internal" );
        Client::Context ctx( dummyNs );
        {
            log() << "resync: cloning database " << db << " to get an initial copy" << endl;
            ReplInfo r("resync: cloning a database");
            string errmsg;
            int errCode = 0;
            bool ok = Cloner::cloneFrom(hostName.c_str(), errmsg, cc().database()->name(), false,
                                        /*slaveOk*/ true, /*replauth*/ true, /*snapshot*/false,
                                        /*mayYield*/true, /*mayBeInterrupted*/false, &errCode);
            if ( !ok ) {
                if ( errCode == DatabaseDifferCaseCode ) {
                    resyncDrop( db.c_str(), "internal" );
                    log() << "resync: database " << db << " not valid on the master due to a name conflict, dropping." << endl;
                    return;
                }
                else {
                    problem() << "resync of " << db << " from " << hostName << " failed " << errmsg << endl;
                    throw SyncException();
                }
            }
        }

        log() << "resync: done with initial clone for db: " << db << endl;

        return;
    }
예제 #2
0
파일: repl.cpp 프로젝트: CoolCloud/mongo
 void ReplSource::forceResync( const char *requester ) {
     BSONObj info;
     {
         dbtemprelease t;
         oplogReader.connect(hostName);
         /* todo use getDatabaseNames() method here */
         bool ok = oplogReader.conn()->runCommand( "admin", BSON( "listDatabases" << 1 ), info );
         massert( 10385 ,  "Unable to get database list", ok );
     }
     BSONObjIterator i( info.getField( "databases" ).embeddedObject() );
     while( i.moreWithEOO() ) {
         BSONElement e = i.next();
         if ( e.eoo() )
             break;
         string name = e.embeddedObject().getField( "name" ).valuestr();
         if ( !e.embeddedObject().getBoolField( "empty" ) ) {
             if ( name != "local" ) {
                 if ( only.empty() || only == name ) {
                     resyncDrop( name.c_str(), requester );
                 }
             }
         }
     }
     syncedTo = OpTime();
     addDbNextPass.clear();
     save();
 }
예제 #3
0
파일: repl.cpp 프로젝트: CoolCloud/mongo
    /* grab initial copy of a database from the master */
    bool ReplSource::resync(string db) {
        string dummyNs = resyncDrop( db.c_str(), "internal" );
        Client::Context ctx( dummyNs );
        {
            log() << "resync: cloning database " << db << " to get an initial copy" << endl;
            ReplInfo r("resync: cloning a database");
            string errmsg;
            bool ok = cloneFrom(hostName.c_str(), errmsg, cc().database()->name, false, /*slaveok*/ true, /*replauth*/ true, /*snapshot*/false, /*mayYield*/true, /*mayBeInterrupted*/false);
            if ( !ok ) {
                problem() << "resync of " << db << " from " << hostName << " failed " << errmsg << endl;
                throw SyncException();
            }
        }

        log() << "resync: done with initial clone for db: " << db << endl;

        return true;
    }