Skip to content

Commit 20cfa56

Browse files
committed
SERVER-37643 replace MultiIndexBlock reference in test with IndexCatalog::createIndexOnEmptyCollection
1 parent cb67f20 commit 20cfa56

File tree

5 files changed

+37
-45
lines changed

5 files changed

+37
-45
lines changed

src/mongo/db/catalog/SConscript

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ env.CppUnitTest(
477477
],
478478
LIBDEPS=[
479479
'catalog_helpers',
480-
'multi_index_block',
481480
'$BUILD_DIR/mongo/db/auth/authmocks',
482481
'$BUILD_DIR/mongo/db/db_raii',
483482
'$BUILD_DIR/mongo/db/namespace_string',

src/mongo/db/catalog/rename_collection_test.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737
#include "mongo/db/catalog/collection_catalog_entry.h"
3838
#include "mongo/db/catalog/collection_options.h"
3939
#include "mongo/db/catalog/database_holder.h"
40-
#include "mongo/db/catalog/multi_index_block.h"
40+
#include "mongo/db/catalog/index_catalog.h"
4141
#include "mongo/db/catalog/rename_collection.h"
4242
#include "mongo/db/catalog/uuid_catalog.h"
4343
#include "mongo/db/client.h"
4444
#include "mongo/db/concurrency/write_conflict_exception.h"
4545
#include "mongo/db/db_raii.h"
46+
#include "mongo/db/index/index_descriptor.h"
4647
#include "mongo/db/jsobj.h"
4748
#include "mongo/db/namespace_string.h"
4849
#include "mongo/db/op_observer.h"
@@ -399,15 +400,15 @@ bool _isTempCollection(OperationContext* opCtx, const NamespaceString& nss) {
399400
}
400401

401402
/**
402-
* Creates an index using the given index name with a bogus key spec.
403+
* Creates an index on an empty collection using the given index name with a bogus key spec.
403404
*/
404-
void _createIndex(OperationContext* opCtx,
405-
const NamespaceString& nss,
406-
const std::string& indexName) {
407-
writeConflictRetry(opCtx, "_createIndex", nss.ns(), [=] {
405+
void _createIndexOnEmptyCollection(OperationContext* opCtx,
406+
const NamespaceString& nss,
407+
const std::string& indexName) {
408+
writeConflictRetry(opCtx, "_createIndexOnEmptyCollection", nss.ns(), [=] {
408409
AutoGetCollection autoColl(opCtx, nss, MODE_X);
409410
auto collection = autoColl.getCollection();
410-
ASSERT_TRUE(collection) << "Cannot create index in collection " << nss
411+
ASSERT_TRUE(collection) << "Cannot create index on empty collection " << nss
411412
<< " because collection " << nss.ns() << " does not exist.";
412413

413414
auto indexInfoObj = BSON(
@@ -416,10 +417,9 @@ void _createIndex(OperationContext* opCtx,
416417
<< "ns"
417418
<< nss.ns());
418419

419-
MultiIndexBlock indexer(opCtx, collection);
420-
ASSERT_OK(indexer.init(indexInfoObj).getStatus());
420+
auto indexCatalog = collection->getIndexCatalog();
421421
WriteUnitOfWork wuow(opCtx);
422-
ASSERT_OK(indexer.commit());
422+
ASSERT_OK(indexCatalog->createIndexOnEmptyCollection(opCtx, indexInfoObj).getStatus());
423423
wuow.commit();
424424
});
425425

@@ -503,7 +503,7 @@ TEST_F(RenameCollectionTest, LongIndexNameAllowedForTargetCollection) {
503503

504504
_createCollection(_opCtx.get(), _sourceNss);
505505
const std::string indexName(longestIndexNameAllowedForSource, 'a');
506-
_createIndex(_opCtx.get(), _sourceNss, indexName);
506+
_createIndexOnEmptyCollection(_opCtx.get(), _sourceNss, indexName);
507507
ASSERT_OK(renameCollection(_opCtx.get(), _sourceNss, _targetNssDifferentDb, {}));
508508
}
509509

@@ -522,7 +522,7 @@ TEST_F(RenameCollectionTest, LongIndexNameAllowedForTemporaryCollectionForRename
522522

523523
_createCollection(_opCtx.get(), _sourceNss);
524524
const std::string indexName(longestIndexNameAllowedForTarget, 'a');
525-
_createIndex(_opCtx.get(), _sourceNss, indexName);
525+
_createIndexOnEmptyCollection(_opCtx.get(), _sourceNss, indexName);
526526
ASSERT_OK(renameCollection(_opCtx.get(), _sourceNss, _targetNssDifferentDb, {}));
527527
}
528528

@@ -1005,7 +1005,7 @@ void _testRenameCollectionAcrossDatabaseOplogEntries(
10051005
const std::vector<std::string>& expectedOplogEntries) {
10061006
ASSERT_NOT_EQUALS(sourceNss.db(), targetNss.db());
10071007
_createCollection(opCtx, sourceNss);
1008-
_createIndex(opCtx, sourceNss, "a_1");
1008+
_createIndexOnEmptyCollection(opCtx, sourceNss, "a_1");
10091009
_insertDocument(opCtx, sourceNss, BSON("_id" << 0));
10101010
oplogEntries->clear();
10111011
if (forApplyOps) {
@@ -1091,7 +1091,7 @@ TEST_F(RenameCollectionTest,
10911091

10921092
TEST_F(RenameCollectionTest, RenameCollectionAcrossDatabaseDropsTemporaryCollectionOnException) {
10931093
_createCollection(_opCtx.get(), _sourceNss);
1094-
_createIndex(_opCtx.get(), _sourceNss, "a_1");
1094+
_createIndexOnEmptyCollection(_opCtx.get(), _sourceNss, "a_1");
10951095
_insertDocument(_opCtx.get(), _sourceNss, BSON("_id" << 0));
10961096
_opObserver->onInsertsThrows = true;
10971097
_opObserver->oplogEntries.clear();

src/mongo/db/repl/SConscript

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ env.CppUnitTest(
277277
'replmocks',
278278
'storage_interface_impl',
279279
'$BUILD_DIR/mongo/db/auth/authmocks',
280-
'$BUILD_DIR/mongo/db/catalog/multi_index_block',
281280
'$BUILD_DIR/mongo/db/service_context_d_test_fixture',
282281
],
283282
)
@@ -587,7 +586,6 @@ env.CppUnitTest(
587586
],
588587
LIBDEPS=[
589588
'$BUILD_DIR/mongo/db/auth/authmocks',
590-
'$BUILD_DIR/mongo/db/catalog/multi_index_block',
591589
'oplog_interface_local',
592590
'rollback_test_fixture',
593591
'rs_rollback',

src/mongo/db/repl/rs_rollback_test.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "mongo/db/catalog/database_holder.h"
4040
#include "mongo/db/catalog/drop_indexes.h"
4141
#include "mongo/db/catalog/index_catalog.h"
42-
#include "mongo/db/catalog/multi_index_block.h"
4342
#include "mongo/db/catalog/uuid_catalog.h"
4443
#include "mongo/db/client.h"
4544
#include "mongo/db/concurrency/d_concurrency.h"
@@ -169,20 +168,17 @@ OplogInterfaceMock::Operation makeOpAndRecordId(long long seconds, long long has
169168
return std::make_pair(makeOp(seconds, hash), RecordId(++recordId));
170169
}
171170

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
173172
// 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) {
178177
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();
181179
WriteUnitOfWork wunit(opCtx);
182-
ASSERT_OK(indexer.commit());
180+
ASSERT_OK(indexCatalog->createIndexOnEmptyCollection(opCtx, indexSpec).getStatus());
183181
wunit.commit();
184-
auto indexCatalog = coll->getIndexCatalog();
185-
ASSERT(indexCatalog);
186182
return indexCatalog->numIndexesReady(opCtx);
187183
}
188184

@@ -481,7 +477,7 @@ TEST_F(RSRollbackTest, RollbackCreateIndexCommand) {
481477
<< "name"
482478
<< "a_1");
483479

484-
int numIndexes = createIndexForColl(_opCtx.get(), collection, nss, indexSpec);
480+
int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), collection, nss, indexSpec);
485481
ASSERT_EQUALS(2, numIndexes);
486482

487483
auto commonOperation = makeOpAndRecordId(1, 1);
@@ -679,7 +675,7 @@ TEST_F(RSRollbackTest, RollingBackCreateIndexAndRenameWithLongName) {
679675
<< "name"
680676
<< longName);
681677

682-
int numIndexes = createIndexForColl(_opCtx.get(), collection, nss, indexSpec);
678+
int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), collection, nss, indexSpec);
683679
ASSERT_EQUALS(2, numIndexes);
684680

685681
auto commonOperation = makeOpAndRecordId(1, 1);
@@ -734,7 +730,7 @@ TEST_F(RSRollbackTest, RollingBackDropAndCreateOfSameIndexNameWithDifferentSpecs
734730
<< "name"
735731
<< "a_1");
736732

737-
int numIndexes = createIndexForColl(_opCtx.get(), collection, nss, indexSpec);
733+
int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), collection, nss, indexSpec);
738734
ASSERT_EQUALS(2, numIndexes);
739735

740736
auto commonOperation = makeOpAndRecordId(1, 1);
@@ -862,7 +858,7 @@ TEST_F(RSRollbackTest, RollbackDropIndexOnCollectionWithTwoExistingIndexes) {
862858

863859
// Create the necessary indexes. Index 0 is created and dropped in the sequence of ops that will
864860
// 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"));
866862
ASSERT_EQUALS(2, numIndexes);
867863

868864
auto commonOp = makeOpAndRecordId(1, 1);
@@ -929,9 +925,9 @@ TEST_F(RSRollbackTest, RollbackMultipleCreateIndexesOnSameCollection) {
929925
auto commonOp = makeOpAndRecordId(1, 1);
930926

931927
// 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"));
935931
ASSERT_EQUALS(4, numIndexesOnColl(_opCtx.get(), nss, coll));
936932

937933
// The ops that will be rolled back.
@@ -969,7 +965,7 @@ TEST_F(RSRollbackTest, RollbackCreateDropRecreateIndexOnCollection) {
969965
<< "name"
970966
<< idxName("0"));
971967

972-
int numIndexes = createIndexForColl(_opCtx.get(), coll, nss, indexSpec);
968+
int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), coll, nss, indexSpec);
973969
ASSERT_EQUALS(2, numIndexes);
974970

975971
auto commonOp = makeOpAndRecordId(1, 1);

src/mongo/db/repl/storage_interface_impl_test.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@
3939
#include "mongo/db/catalog/collection_options.h"
4040
#include "mongo/db/catalog/database.h"
4141
#include "mongo/db/catalog/document_validation.h"
42-
#include "mongo/db/catalog/multi_index_block.h"
42+
#include "mongo/db/catalog/index_catalog.h"
4343
#include "mongo/db/client.h"
4444
#include "mongo/db/concurrency/d_concurrency.h"
4545
#include "mongo/db/concurrency/write_conflict_exception.h"
4646
#include "mongo/db/db_raii.h"
47+
#include "mongo/db/index/index_access_method.h"
4748
#include "mongo/db/index/index_descriptor.h"
4849
#include "mongo/db/namespace_string.h"
4950
#include "mongo/db/operation_context.h"
@@ -129,23 +130,21 @@ void createCollection(OperationContext* opCtx,
129130
}
130131

131132
/**
132-
* Create an index on the given collection. Returns the number of indexes that exist on the
133+
* Create an index on an empty collection. Returns the number of indexes that exist on the
133134
* collection after the given index is created.
134135
*/
135-
int createIndexForColl(OperationContext* opCtx, NamespaceString nss, BSONObj indexSpec) {
136+
int _createIndexOnEmptyCollection(OperationContext* opCtx, NamespaceString nss, BSONObj indexSpec) {
136137
Lock::DBLock dbLock(opCtx, nss.db(), MODE_X);
137138
AutoGetCollection autoColl(opCtx, nss, MODE_X);
138139
auto coll = autoColl.getCollection();
139140

140-
MultiIndexBlock indexer(opCtx, coll);
141-
ASSERT_OK(indexer.init(indexSpec).getStatus());
141+
auto indexCatalog = coll->getIndexCatalog();
142+
ASSERT(indexCatalog);
142143

143144
WriteUnitOfWork wunit(opCtx);
144-
ASSERT_OK(indexer.commit());
145+
ASSERT_OK(indexCatalog->createIndexOnEmptyCollection(opCtx, indexSpec).getStatus());
145146
wunit.commit();
146147

147-
auto indexCatalog = coll->getIndexCatalog();
148-
ASSERT(indexCatalog);
149148
return indexCatalog->numIndexesReady(opCtx);
150149
}
151150

@@ -2687,7 +2686,7 @@ TEST_F(StorageInterfaceImplTest, SetIndexIsMultikeySucceeds) {
26872686
auto indexSpec =
26882687
BSON("name" << indexName << "ns" << nss.ns() << "key" << BSON("a.b" << 1) << "v"
26892688
<< static_cast<int>(kIndexVersion));
2690-
ASSERT_EQUALS(createIndexForColl(opCtx, nss, indexSpec), 2);
2689+
ASSERT_EQUALS(_createIndexOnEmptyCollection(opCtx, nss, indexSpec), 2);
26912690

26922691
MultikeyPaths paths = {{1}};
26932692
ASSERT_OK(storage.setIndexIsMultikey(opCtx, nss, indexName, paths, Timestamp(3, 3)));

0 commit comments

Comments
 (0)