summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/multi_index_block_test.cpp
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2020-08-14 10:23:04 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-02 23:53:39 +0000
commitbf5914a20b596ba3bde772b42e579e028f733bac (patch)
tree2b26469571786d9adb5e95c47990c2416bfab9c4 /src/mongo/db/catalog/multi_index_block_test.cpp
parent6b3e341703b781bb1ff7b1263406a0f1d28dd77c (diff)
downloadmongo-bf5914a20b596ba3bde772b42e579e028f733bac.tar.gz
SERVER-50317 Const correct uses of Collection
Most of the code should only need a const Collection now. AutoGetCollection returns a const Collection by default. There is a placeholder getWritableCollection() interface that will handle the necessary steps we need for lock free reads in the future. Added some operators to AutoGetCollection so it behaves more like a smart pointer.
Diffstat (limited to 'src/mongo/db/catalog/multi_index_block_test.cpp')
-rw-r--r--src/mongo/db/catalog/multi_index_block_test.cpp48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/mongo/db/catalog/multi_index_block_test.cpp b/src/mongo/db/catalog/multi_index_block_test.cpp
index ed5da9d7957..4f379451bec 100644
--- a/src/mongo/db/catalog/multi_index_block_test.cpp
+++ b/src/mongo/db/catalog/multi_index_block_test.cpp
@@ -90,11 +90,12 @@ void MultiIndexBlockTest::tearDown() {
TEST_F(MultiIndexBlockTest, CommitWithoutInsertingDocuments) {
auto indexer = getIndexer();
- AutoGetCollection autoColl(operationContext(), getNSS(), MODE_X);
- Collection* coll = autoColl.getCollection();
+ AutoGetCollection coll(operationContext(), getNSS(), MODE_X);
- auto specs = unittest::assertGet(indexer->init(
- operationContext(), coll, std::vector<BSONObj>(), MultiIndexBlock::kNoopOnInitFn));
+ auto specs = unittest::assertGet(indexer->init(operationContext(),
+ coll.getWritableCollection(),
+ std::vector<BSONObj>(),
+ MultiIndexBlock::kNoopOnInitFn));
ASSERT_EQUALS(0U, specs.size());
ASSERT_OK(indexer->dumpInsertsFromBulk(operationContext()));
@@ -103,7 +104,7 @@ TEST_F(MultiIndexBlockTest, CommitWithoutInsertingDocuments) {
{
WriteUnitOfWork wunit(operationContext());
ASSERT_OK(indexer->commit(operationContext(),
- coll,
+ coll.getWritableCollection(),
MultiIndexBlock::kNoopOnCreateEachFn,
MultiIndexBlock::kNoopOnCommitFn));
wunit.commit();
@@ -113,11 +114,12 @@ TEST_F(MultiIndexBlockTest, CommitWithoutInsertingDocuments) {
TEST_F(MultiIndexBlockTest, CommitAfterInsertingSingleDocument) {
auto indexer = getIndexer();
- AutoGetCollection autoColl(operationContext(), getNSS(), MODE_X);
- Collection* coll = autoColl.getCollection();
+ AutoGetCollection coll(operationContext(), getNSS(), MODE_X);
- auto specs = unittest::assertGet(indexer->init(
- operationContext(), coll, std::vector<BSONObj>(), MultiIndexBlock::kNoopOnInitFn));
+ auto specs = unittest::assertGet(indexer->init(operationContext(),
+ coll.getWritableCollection(),
+ std::vector<BSONObj>(),
+ MultiIndexBlock::kNoopOnInitFn));
ASSERT_EQUALS(0U, specs.size());
ASSERT_OK(indexer->insertSingleDocumentForInitialSyncOrRecovery(operationContext(), {}, {}));
@@ -127,24 +129,26 @@ TEST_F(MultiIndexBlockTest, CommitAfterInsertingSingleDocument) {
{
WriteUnitOfWork wunit(operationContext());
ASSERT_OK(indexer->commit(operationContext(),
- coll,
+ coll.getWritableCollection(),
MultiIndexBlock::kNoopOnCreateEachFn,
MultiIndexBlock::kNoopOnCommitFn));
wunit.commit();
}
// abort() should have no effect after the index build is committed.
- indexer->abortIndexBuild(operationContext(), coll, MultiIndexBlock::kNoopOnCleanUpFn);
+ indexer->abortIndexBuild(
+ operationContext(), coll.getWritableCollection(), MultiIndexBlock::kNoopOnCleanUpFn);
}
TEST_F(MultiIndexBlockTest, AbortWithoutCleanupAfterInsertingSingleDocument) {
auto indexer = getIndexer();
- AutoGetCollection autoColl(operationContext(), getNSS(), MODE_X);
- Collection* coll = autoColl.getCollection();
+ AutoGetCollection coll(operationContext(), getNSS(), MODE_X);
- auto specs = unittest::assertGet(indexer->init(
- operationContext(), coll, std::vector<BSONObj>(), MultiIndexBlock::kNoopOnInitFn));
+ auto specs = unittest::assertGet(indexer->init(operationContext(),
+ coll.getWritableCollection(),
+ std::vector<BSONObj>(),
+ MultiIndexBlock::kNoopOnInitFn));
ASSERT_EQUALS(0U, specs.size());
ASSERT_OK(indexer->insertSingleDocumentForInitialSyncOrRecovery(operationContext(), {}, {}));
auto isResumable = false;
@@ -154,8 +158,7 @@ TEST_F(MultiIndexBlockTest, AbortWithoutCleanupAfterInsertingSingleDocument) {
TEST_F(MultiIndexBlockTest, InitWriteConflictException) {
auto indexer = getIndexer();
- AutoGetCollection autoColl(operationContext(), getNSS(), MODE_X);
- Collection* coll = autoColl.getCollection();
+ AutoGetCollection coll(operationContext(), getNSS(), MODE_X);
BSONObj spec = BSON("key" << BSON("a" << 1) << "name"
<< "a_1"
@@ -164,7 +167,7 @@ TEST_F(MultiIndexBlockTest, InitWriteConflictException) {
{
WriteUnitOfWork wuow(operationContext());
ASSERT_THROWS_CODE(indexer->init(operationContext(),
- coll,
+ coll.getWritableCollection(),
{spec},
[](std::vector<BSONObj>& specs) -> Status {
throw WriteConflictException();
@@ -175,12 +178,17 @@ TEST_F(MultiIndexBlockTest, InitWriteConflictException) {
{
WriteUnitOfWork wuow(operationContext());
- ASSERT_OK(indexer->init(operationContext(), coll, {spec}, MultiIndexBlock::kNoopOnInitFn)
+ ASSERT_OK(indexer
+ ->init(operationContext(),
+ coll.getWritableCollection(),
+ {spec},
+ MultiIndexBlock::kNoopOnInitFn)
.getStatus());
wuow.commit();
}
- indexer->abortIndexBuild(operationContext(), coll, MultiIndexBlock::kNoopOnCleanUpFn);
+ indexer->abortIndexBuild(
+ operationContext(), coll.getWritableCollection(), MultiIndexBlock::kNoopOnCleanUpFn);
}
} // namespace