| 
39 | 39 | #include "mongo/db/catalog/database_holder.h"  | 
40 | 40 | #include "mongo/db/catalog/drop_indexes.h"  | 
41 | 41 | #include "mongo/db/catalog/index_catalog.h"  | 
42 |  | -#include "mongo/db/catalog/multi_index_block.h"  | 
43 | 42 | #include "mongo/db/catalog/uuid_catalog.h"  | 
44 | 43 | #include "mongo/db/client.h"  | 
45 | 44 | #include "mongo/db/concurrency/d_concurrency.h"  | 
@@ -169,20 +168,17 @@ OplogInterfaceMock::Operation makeOpAndRecordId(long long seconds, long long has  | 
169 | 168 |     return std::make_pair(makeOp(seconds, hash), RecordId(++recordId));  | 
170 | 169 | }  | 
171 | 170 | 
 
  | 
172 |  | -// Create an index on the given collection. Returns the number of indexes that exist on the  | 
 | 171 | +// Create an index on an empty collection. Returns the number of indexes that exist on the  | 
173 | 172 | // collection after the given index is created.  | 
174 |  | -int createIndexForColl(OperationContext* opCtx,  | 
175 |  | -                       Collection* coll,  | 
176 |  | -                       NamespaceString nss,  | 
177 |  | -                       BSONObj indexSpec) {  | 
 | 173 | +int _createIndexOnEmptyCollection(OperationContext* opCtx,  | 
 | 174 | +                                  Collection* coll,  | 
 | 175 | +                                  NamespaceString nss,  | 
 | 176 | +                                  BSONObj indexSpec) {  | 
178 | 177 |     Lock::DBLock dbLock(opCtx, nss.db(), MODE_X);  | 
179 |  | -    MultiIndexBlock indexer(opCtx, coll);  | 
180 |  | -    ASSERT_OK(indexer.init(indexSpec).getStatus());  | 
 | 178 | +    auto indexCatalog = coll->getIndexCatalog();  | 
181 | 179 |     WriteUnitOfWork wunit(opCtx);  | 
182 |  | -    ASSERT_OK(indexer.commit());  | 
 | 180 | +    ASSERT_OK(indexCatalog->createIndexOnEmptyCollection(opCtx, indexSpec).getStatus());  | 
183 | 181 |     wunit.commit();  | 
184 |  | -    auto indexCatalog = coll->getIndexCatalog();  | 
185 |  | -    ASSERT(indexCatalog);  | 
186 | 182 |     return indexCatalog->numIndexesReady(opCtx);  | 
187 | 183 | }  | 
188 | 184 | 
 
  | 
@@ -481,7 +477,7 @@ TEST_F(RSRollbackTest, RollbackCreateIndexCommand) {  | 
481 | 477 |                                << "name"  | 
482 | 478 |                                << "a_1");  | 
483 | 479 | 
 
  | 
484 |  | -    int numIndexes = createIndexForColl(_opCtx.get(), collection, nss, indexSpec);  | 
 | 480 | +    int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), collection, nss, indexSpec);  | 
485 | 481 |     ASSERT_EQUALS(2, numIndexes);  | 
486 | 482 | 
 
  | 
487 | 483 |     auto commonOperation = makeOpAndRecordId(1, 1);  | 
@@ -679,7 +675,7 @@ TEST_F(RSRollbackTest, RollingBackCreateIndexAndRenameWithLongName) {  | 
679 | 675 |                                << "name"  | 
680 | 676 |                                << longName);  | 
681 | 677 | 
 
  | 
682 |  | -    int numIndexes = createIndexForColl(_opCtx.get(), collection, nss, indexSpec);  | 
 | 678 | +    int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), collection, nss, indexSpec);  | 
683 | 679 |     ASSERT_EQUALS(2, numIndexes);  | 
684 | 680 | 
 
  | 
685 | 681 |     auto commonOperation = makeOpAndRecordId(1, 1);  | 
@@ -734,7 +730,7 @@ TEST_F(RSRollbackTest, RollingBackDropAndCreateOfSameIndexNameWithDifferentSpecs  | 
734 | 730 |                                << "name"  | 
735 | 731 |                                << "a_1");  | 
736 | 732 | 
 
  | 
737 |  | -    int numIndexes = createIndexForColl(_opCtx.get(), collection, nss, indexSpec);  | 
 | 733 | +    int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), collection, nss, indexSpec);  | 
738 | 734 |     ASSERT_EQUALS(2, numIndexes);  | 
739 | 735 | 
 
  | 
740 | 736 |     auto commonOperation = makeOpAndRecordId(1, 1);  | 
@@ -862,7 +858,7 @@ TEST_F(RSRollbackTest, RollbackDropIndexOnCollectionWithTwoExistingIndexes) {  | 
862 | 858 | 
 
  | 
863 | 859 |     // Create the necessary indexes. Index 0 is created and dropped in the sequence of ops that will  | 
864 | 860 |     // be rolled back, so we only create index 1.  | 
865 |  | -    int numIndexes = createIndexForColl(_opCtx.get(), coll, nss, idxSpec(nss, "1"));  | 
 | 861 | +    int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), coll, nss, idxSpec(nss, "1"));  | 
866 | 862 |     ASSERT_EQUALS(2, numIndexes);  | 
867 | 863 | 
 
  | 
868 | 864 |     auto commonOp = makeOpAndRecordId(1, 1);  | 
@@ -929,9 +925,9 @@ TEST_F(RSRollbackTest, RollbackMultipleCreateIndexesOnSameCollection) {  | 
929 | 925 |     auto commonOp = makeOpAndRecordId(1, 1);  | 
930 | 926 | 
 
  | 
931 | 927 |     // Create all of the necessary indexes.  | 
932 |  | -    createIndexForColl(_opCtx.get(), coll, nss, idxSpec(nss, "0"));  | 
933 |  | -    createIndexForColl(_opCtx.get(), coll, nss, idxSpec(nss, "1"));  | 
934 |  | -    createIndexForColl(_opCtx.get(), coll, nss, idxSpec(nss, "2"));  | 
 | 928 | +    _createIndexOnEmptyCollection(_opCtx.get(), coll, nss, idxSpec(nss, "0"));  | 
 | 929 | +    _createIndexOnEmptyCollection(_opCtx.get(), coll, nss, idxSpec(nss, "1"));  | 
 | 930 | +    _createIndexOnEmptyCollection(_opCtx.get(), coll, nss, idxSpec(nss, "2"));  | 
935 | 931 |     ASSERT_EQUALS(4, numIndexesOnColl(_opCtx.get(), nss, coll));  | 
936 | 932 | 
 
  | 
937 | 933 |     // The ops that will be rolled back.  | 
@@ -969,7 +965,7 @@ TEST_F(RSRollbackTest, RollbackCreateDropRecreateIndexOnCollection) {  | 
969 | 965 |                                << "name"  | 
970 | 966 |                                << idxName("0"));  | 
971 | 967 | 
 
  | 
972 |  | -    int numIndexes = createIndexForColl(_opCtx.get(), coll, nss, indexSpec);  | 
 | 968 | +    int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), coll, nss, indexSpec);  | 
973 | 969 |     ASSERT_EQUALS(2, numIndexes);  | 
974 | 970 | 
 
  | 
975 | 971 |     auto commonOp = makeOpAndRecordId(1, 1);  | 
 | 
0 commit comments