void run() {
     // Recreate the collection as capped, without an _id index.
     Database* db = _ctx.ctx().db();
     db->dropCollection( &_txn, _ns );
     CollectionOptions options;
     options.capped = true;
     options.cappedSize = 10 * 1024;
     Collection* coll = db->createCollection( &_txn, _ns, options );
     coll->getIndexCatalog()->dropAllIndexes(&_txn, true );
     // Insert some documents.
     int32_t nDocs = 1000;
     for( int32_t i = 0; i < nDocs; ++i ) {
         coll->insertDocument( &_txn, BSON( "_id" << i ), true );
     }
     // Initialize curop.
     _txn.getCurOp()->reset();
     // Request an interrupt.
     getGlobalEnvironment()->setKillAllOperations();
     BSONObj indexInfo = BSON( "key" << BSON( "_id" << 1 ) <<
                               "ns" << _ns <<
                               "name" << "_id_" );
     // The call is not interrupted because mayInterrupt == false.
     ASSERT_FALSE(buildIndexInterrupted(indexInfo, false));
     // only want to interrupt the index build
     getGlobalEnvironment()->unsetKillAllOperations();
     // The new index is listed in the index catalog because the index build succeeded.
     ASSERT( coll->getIndexCatalog()->findIndexByName( "_id_" ) );
 }
Ejemplo n.º 2
0
 void run() {
     // Create a new collection.
     Database* db = _ctx.db();
     Collection* coll;
     {
         WriteUnitOfWork wunit(&_opCtx);
         ASSERT_OK(db->dropCollection(&_opCtx, _nss));
         coll = db->createCollection(&_opCtx, _nss);
         // Drop all indexes including id index.
         coll->getIndexCatalog()->dropAllIndexes(&_opCtx, true);
         // Insert some documents.
         int32_t nDocs = 1000;
         OpDebug* const nullOpDebug = nullptr;
         for (int32_t i = 0; i < nDocs; ++i) {
             ASSERT_OK(
                 coll->insertDocument(&_opCtx, InsertStatement(BSON("a" << i)), nullOpDebug));
         }
         wunit.commit();
     }
     // Request an interrupt.
     getGlobalServiceContext()->setKillAllOperations();
     BSONObj indexInfo = BSON("key" << BSON("a" << 1) << "ns" << _ns << "name"
                                    << "a_1"
                                    << "v"
                                    << static_cast<int>(kIndexVersion));
     // The call is interrupted because mayInterrupt == true.
     ASSERT_TRUE(buildIndexInterrupted(indexInfo));
     // only want to interrupt the index build
     getGlobalServiceContext()->unsetKillAllOperations();
     // The new index is not listed in the index catalog because the index build failed.
     ASSERT(!coll->getIndexCatalog()->findIndexByName(&_opCtx, "a_1"));
 }
Ejemplo n.º 3
0
    void run() {
        // Skip the test if the storage engine doesn't support capped collections.
        if (!getGlobalServiceContext()->getStorageEngine()->supportsCappedCollections()) {
            return;
        }

        // Recreate the collection as capped, without an _id index.
        Database* db = _ctx.db();
        Collection* coll;
        {
            WriteUnitOfWork wunit(&_opCtx);
            ASSERT_OK(db->dropCollection(&_opCtx, _nss));
            CollectionOptions options;
            options.capped = true;
            options.cappedSize = 10 * 1024;
            coll = db->createCollection(&_opCtx, _nss, options);
            coll->getIndexCatalog()->dropAllIndexes(&_opCtx, true);
            // Insert some documents.
            int32_t nDocs = 1000;
            OpDebug* const nullOpDebug = nullptr;
            for (int32_t i = 0; i < nDocs; ++i) {
                ASSERT_OK(coll->insertDocument(
                    &_opCtx, InsertStatement(BSON("_id" << i)), nullOpDebug, true));
            }
            wunit.commit();
        }
        // Request an interrupt.
        getGlobalServiceContext()->setKillAllOperations();
        BSONObj indexInfo = BSON("key" << BSON("_id" << 1) << "ns" << _ns << "name"
                                       << "_id_"
                                       << "v"
                                       << static_cast<int>(kIndexVersion));
        ASSERT_TRUE(buildIndexInterrupted(indexInfo));
        // only want to interrupt the index build
        getGlobalServiceContext()->unsetKillAllOperations();
        // The new index is not listed in the index catalog because the index build failed.
        ASSERT(!coll->getIndexCatalog()->findIndexByName(&_opCtx, "_id_"));
    }
 void run() {
     // Create a new collection.
     Database* db = _ctx.ctx().db();
     db->dropCollection( &_txn, _ns );
     Collection* coll = db->createCollection( &_txn, _ns );
     // Drop all indexes including id index.
     coll->getIndexCatalog()->dropAllIndexes(&_txn, true );
     // Insert some documents with enforceQuota=true.
     int32_t nDocs = 1000;
     for( int32_t i = 0; i < nDocs; ++i ) {
         coll->insertDocument( &_txn, BSON( "a" << i ), true );
     }
     // Initialize curop.
     _txn.getCurOp()->reset();
     // Request an interrupt.
     getGlobalEnvironment()->setKillAllOperations();
     BSONObj indexInfo = BSON( "key" << BSON( "a" << 1 ) << "ns" << _ns << "name" << "a_1" );
     // The call is interrupted because mayInterrupt == true.
     ASSERT_TRUE(buildIndexInterrupted(indexInfo, true));
     // only want to interrupt the index build
     getGlobalEnvironment()->unsetKillAllOperations();
     // The new index is not listed in the index catalog because the index build failed.
     ASSERT( !coll->getIndexCatalog()->findIndexByName( "a_1" ) );
 }