コード例 #1
0
ファイル: indexupdatetests.cpp プロジェクト: violentesc/mongo
 void run() {
     // Recreate the collection as capped, without an _id index.
     _client.dropCollection( _ns );
     BSONObj info;
     ASSERT( _client.runCommand( "unittests",
                                 BSON( "create" << "indexupdate" <<
                                       "capped" << true <<
                                       "size" << ( 10 * 1024 ) <<
                                       "autoIndexId" << false ),
                                 info ) );
     // Insert some documents.
     int32_t nDocs = 1000;
     for( int32_t i = 0; i < nDocs; ++i ) {
         _client.insert( _ns, BSON( "_id" << i ) );
     }
     // Initialize curop.
     cc().curop()->reset();
     // Request an interrupt.
     killCurrentOp.killAll();
     BSONObj indexInfo = BSON( "key" << BSON( "_id" << 1 ) <<
                               "ns" << _ns <<
                               "name" << "_id" );
     // The call is not interrupted because mayInterrupt == false.
     theDataFileMgr.insertWithObjMod( "unittests.system.indexes", indexInfo, false );
     // The new index is listed in system.indexes because the index build succeeded.
     ASSERT_EQUALS( 1U, _client.count( "unittests.system.indexes", BSON( "ns" << _ns ) ) );
 }
コード例 #2
0
ファイル: indexupdatetests.cpp プロジェクト: violentesc/mongo
 void run() {
     // Insert some documents.
     int32_t nDocs = 1000;
     for( int32_t i = 0; i < nDocs; ++i ) {
         _client.insert( _ns, BSON( "a" << ( i / 4 ) ) );
     }
     // Find the documents that are dups.
     set<DiskLoc> dups;
     int32_t last = -1;
     for( boost::shared_ptr<Cursor> cursor = theDataFileMgr.findAll( _ns );
          cursor->ok();
          cursor->advance() ) {
         int32_t currA = cursor->current()[ "a" ].Int();
         if ( currA == last ) {
             dups.insert( cursor->currLoc() );
         }
         last = currA;
     }
     // Check the expected number of dups.
     ASSERT_EQUALS( static_cast<uint32_t>( nDocs / 4 * 3 ), dups.size() );
     // Drop the dups.
     BtreeBasedBuilder::doDropDups( _ns, nsdetails( _ns ), dups, true );
     // Check that the expected number of documents remain.
     ASSERT_EQUALS( static_cast<uint32_t>( nDocs / 4 ), _client.count( _ns ) );
 }
コード例 #3
0
ファイル: db.cpp プロジェクト: BobWeinerJr/mongo
 /**
  * Checks if this server was started without --replset but has a config in local.system.replset
  * (meaning that this is probably a replica set member started in stand-alone mode).
  *
  * @returns the number of documents in local.system.replset or 0 if this was started with
  *          --replset.
  */
 unsigned long long checkIfReplMissingFromCommandLine() {
     Lock::GlobalWrite lk; // this is helpful for the query below to work as you can't open files when readlocked
     if (!replSettings.usingReplSets()) {
         DBDirectClient c;
         return c.count("local.system.replset");
     }
     return 0;
 }
コード例 #4
0
ファイル: indexupdatetests.cpp プロジェクト: violentesc/mongo
 void run() {
     // Insert some documents.
     int32_t nDocs = 1000;
     for( int32_t i = 0; i < nDocs; ++i ) {
         _client.insert( _ns, BSON( "a" << ( i / 4 ) ) );
     }
     // Find the documents that are dups.
     set<DiskLoc> dups;
     int32_t last = -1;
     for( boost::shared_ptr<Cursor> cursor = theDataFileMgr.findAll( _ns );
          cursor->ok();
          cursor->advance() ) {
         int32_t currA = cursor->current()[ "a" ].Int();
         if ( currA == last ) {
             dups.insert( cursor->currLoc() );
         }
         last = currA;
     }
     // Check the expected number of dups.  There must be enough to trigger a RARELY
     // condition when deleting them.
     ASSERT_EQUALS( static_cast<uint32_t>( nDocs / 4 * 3 ), dups.size() );
     // Kill the current operation.
     cc().curop()->kill();
     if ( _mayInterrupt ) {
         // doDropDups() aborts.
         ASSERT_THROWS( BtreeBasedBuilder::doDropDups( _ns, nsdetails( _ns ), dups, _mayInterrupt ),
                        UserException );
         // Not all dups are dropped.
         ASSERT( static_cast<uint32_t>( nDocs / 4 ) < _client.count( _ns ) );
     }
     else {
         // doDropDups() succeeds.
         BtreeBasedBuilder::doDropDups( _ns, nsdetails( _ns ), dups, _mayInterrupt );
         // The expected number of documents were dropped.
         ASSERT_EQUALS( static_cast<uint32_t>( nDocs / 4 ), _client.count( _ns ) );
     }
 }
コード例 #5
0
ファイル: db.cpp プロジェクト: opinionaided/mongo
 void checkIfReplMissingFromCommandLine() {
     Lock::GlobalWrite lk; // _openAllFiles is false at this point, so this is helpful for the query below to work as you can't open files when readlocked
     if( !cmdLine.usingReplSets() ) { 
         Client::GodScope gs;
         DBDirectClient c;
         unsigned long long x = 
             c.count("local.system.replset");
         if( x ) { 
             log() << endl;
             log() << "** warning: mongod started without --replSet yet " << x << " documents are present in local.system.replset" << endl;
             log() << "**          restart with --replSet unless you are doing maintenance and no other clients are connected" << endl;
             log() << endl;
         }
     }
 }
コード例 #6
0
        void run() {
            // RARELY shoud be once/128x
            for (int i=0; i<150; i++) {
                insert();
                updateSucceed();
            }

            DBDirectClient client;
            int count = (int) client.count(cappedNs(), BSONObj());
            verify(count > 1);

            // Just to be sure, no _id index, right?
            Client::Context ctx(cappedNs());
            NamespaceDetails *nsd = nsdetails(cappedNs().c_str());
            verify(nsd->findIdIndex() == -1);
        }
コード例 #7
0
ファイル: indexupdatetests.cpp プロジェクト: dstorch/mongo
 void run() {
     // Insert some documents.
     int32_t nDocs = 1000;
     for( int32_t i = 0; i < nDocs; ++i ) {
         _client.insert( _ns, BSON( "a" << i ) );
     }
     // Initialize curop.
     cc().curop()->reset();
     // Request an interrupt.
     killCurrentOp.killAll();
     // The call is not interrupted.
     Helpers::ensureIndex( _ns, BSON( "a" << 1 ), false, "a_1" );
     // The new index is listed in system.indexes because the index build completed.
     ASSERT_EQUALS( 1U,
                    _client.count( "unittests.system.indexes",
                                   BSON( "ns" << _ns << "name" << "a_1" ) ) );
 }
コード例 #8
0
ファイル: indexupdatetests.cpp プロジェクト: violentesc/mongo
 void run() {
     // Insert some documents.
     int32_t nDocs = 1000;
     for( int32_t i = 0; i < nDocs; ++i ) {
         _client.insert( _ns, BSON( "a" << i ) );
     }
     // Initialize curop.
     cc().curop()->reset();
     // Request an interrupt.
     killCurrentOp.killAll();
     BSONObj indexInfo = BSON( "key" << BSON( "a" << 1 ) << "ns" << _ns << "name" << "a_1" );
     // The call is not interrupted because mayInterrupt == false.
     theDataFileMgr.insertWithObjMod( "unittests.system.indexes", indexInfo, false );
     // The new index is listed in system.indexes because the index build completed.
     ASSERT_EQUALS( 1U,
                    _client.count( "unittests.system.indexes",
                                   BSON( "ns" << _ns << "name" << "a_1" ) ) );
 }
コード例 #9
0
ファイル: indexupdatetests.cpp プロジェクト: Albert-B-P/mongo
 void run() {
     // Insert some documents.
     int32_t nDocs = 1000;
     for( int32_t i = 0; i < nDocs; ++i ) {
         _client.insert( _ns, BSON( "a" << i ) );
     }
     // Initialize curop.
     cc().curop()->reset();
     // Request an interrupt.  killAll() rather than kill() is required because the direct
     // client will build the index using a new opid.
     killCurrentOp.killAll();
     // The call is not interrupted.
     _client.ensureIndex( _ns, BSON( "a" << 1 ) );
     // only want to interrupt the index build
     killCurrentOp.reset();
     // The new index is listed in system.indexes because the index build completed.
     ASSERT_EQUALS( 1U,
                    _client.count( "unittests.system.indexes",
                                   BSON( "ns" << _ns << "name" << "a_1" ) ) );
 }
コード例 #10
0
ファイル: rs_config.cpp プロジェクト: CoolCloud/mongo
    ReplSetConfig::ReplSetConfig(const HostAndPort& h) {
        clear();
        int level = 2;
        DEV level = 0;

        BSONObj cfg;
        int v = -5;
        try {
            if( h.isSelf() ) {
                ;
            }
            else {
                /* first, make sure other node is configured to be a replset. just to be safe. */
                string setname = cmdLine.ourSetName();
                BSONObj cmd = BSON( "replSetHeartbeat" << setname );
                int theirVersion;
                BSONObj info;
                log() << "trying to contact " << h.toString() << rsLog;
                bool ok = requestHeartbeat(setname, "", h.toString(), info, -2, theirVersion);
                if( info["rs"].trueValue() ) {
                    // yes, it is a replicate set, although perhaps not yet initialized
                }
                else {
                    if( !ok ) {
                        log() << "replSet TEMP !ok heartbeating " << h.toString() << " on cfg load" << rsLog;
                        if( !info.isEmpty() )
                            log() << "replSet info " << h.toString() << " : " << info.toString() << rsLog;
                        return;
                    }
                    {
                        stringstream ss;
                        ss << "replSet error: member " << h.toString() << " is not in --replSet mode";
                        msgassertedNoTrace(13260, ss.str().c_str()); // not caught as not a user exception - we want it not caught
                        //for python err# checker: uassert(13260, "", false);
                    }
                }
            }

            v = -4;
            unsigned long long count = 0;
            try {
                ScopedConn conn(h.toString());
                v = -3;
                cfg = conn.findOne(rsConfigNs, Query()).getOwned();
                count = conn.count(rsConfigNs);
            }
            catch ( DBException& ) {
                if ( !h.isSelf() ) {
                    throw;
                }

                // on startup, socket is not listening yet
                DBDirectClient cli;
                cfg = cli.findOne( rsConfigNs, Query() ).getOwned();
                count = cli.count(rsConfigNs);
            }

            if( count > 1 )
                uasserted(13109, str::stream() << "multiple rows in " << rsConfigNs << " not supported host: " << h.toString());

            if( cfg.isEmpty() ) {
                version = EMPTYCONFIG;
                return;
            }
            version = -1;
        }
        catch( DBException& e) {
            version = v;
            log(level) << "replSet load config couldn't get from " << h.toString() << ' ' << e.what() << rsLog;
            return;
        }

        from(cfg);
        checkRsConfig();
        _ok = true;
        log(level) << "replSet load config ok from " << (h.isSelf() ? "self" : h.toString()) << rsLog;
    }