summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFaustoleyva54 <fausto.leyva@mongodb.com>2022-01-04 15:20:44 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-05 21:46:33 +0000
commit32522b3fca6ab3a6ece67912c3c9af63654ecbbb (patch)
tree0d9863dc3283fb82705e1f544697da1541cd8dba
parent23376f506bf0ee9cb64cdf212a618224a1184859 (diff)
downloadmongo-32522b3fca6ab3a6ece67912c3c9af63654ecbbb.tar.gz
SERVER-62050 Remove _opCtx from AutoGetCollection
-rw-r--r--src/mongo/db/catalog/coll_mod.cpp31
-rw-r--r--src/mongo/db/catalog/coll_mod_index.cpp12
-rw-r--r--src/mongo/db/catalog/collection_test.cpp4
-rw-r--r--src/mongo/db/catalog/create_collection.cpp2
-rw-r--r--src/mongo/db/catalog/create_collection_test.cpp2
-rw-r--r--src/mongo/db/catalog/drop_indexes.cpp8
-rw-r--r--src/mongo/db/catalog/index_builds_manager.cpp2
-rw-r--r--src/mongo/db/catalog/index_builds_manager_test.cpp2
-rw-r--r--src/mongo/db/catalog/index_signature_test.cpp4
-rw-r--r--src/mongo/db/catalog/multi_index_block_test.cpp8
-rw-r--r--src/mongo/db/catalog/rename_collection_test.cpp4
-rw-r--r--src/mongo/db/catalog/validate_state_test.cpp4
-rw-r--r--src/mongo/db/catalog_raii.cpp37
-rw-r--r--src/mongo/db/catalog_raii.h13
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp2
-rw-r--r--src/mongo/db/commands/feature_compatibility_version.cpp2
-rw-r--r--src/mongo/db/commands/find_and_modify.cpp2
-rw-r--r--src/mongo/db/commands/mr_test.cpp6
-rw-r--r--src/mongo/db/commands/resize_oplog.cpp3
-rw-r--r--src/mongo/db/index_builds_coordinator.cpp8
-rw-r--r--src/mongo/db/op_observer_impl_test.cpp4
-rw-r--r--src/mongo/db/pipeline/process_interface/non_shardsvr_process_interface.cpp2
-rw-r--r--src/mongo/db/repl/collection_bulk_loader_impl.cpp25
-rw-r--r--src/mongo/db/repl/storage_interface_impl.cpp20
-rw-r--r--src/mongo/db/repl/storage_interface_impl_test.cpp5
-rw-r--r--src/mongo/db/s/implicit_collection_creation_test.cpp4
-rw-r--r--src/mongo/db/s/resharding/resharding_data_copy_util.cpp2
-rw-r--r--src/mongo/db/s/session_catalog_migration_destination_test.cpp4
-rw-r--r--src/mongo/db/s/shard_local.cpp2
-rw-r--r--src/mongo/dbtests/dbtests.cpp2
-rw-r--r--src/mongo/dbtests/indexupdatetests.cpp12
-rw-r--r--src/mongo/dbtests/multikey_paths_test.cpp2
-rw-r--r--src/mongo/dbtests/query_stage_collscan.cpp2
-rw-r--r--src/mongo/dbtests/storage_timestamp_tests.cpp26
-rw-r--r--src/mongo/dbtests/validate_tests.cpp2
-rw-r--r--src/mongo/dbtests/wildcard_multikey_persistence_test.cpp2
36 files changed, 139 insertions, 133 deletions
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp
index 34a7371f7f8..c7a7c3436cd 100644
--- a/src/mongo/db/catalog/coll_mod.cpp
+++ b/src/mongo/db/catalog/coll_mod.cpp
@@ -731,8 +731,10 @@ Status _collModInternal(OperationContext* opCtx,
// Handle collMod operation type appropriately.
if (cmd.getExpireAfterSeconds()) {
- _setClusteredExpireAfterSeconds(
- opCtx, oldCollOptions, coll.getWritableCollection(), *cmd.getExpireAfterSeconds());
+ _setClusteredExpireAfterSeconds(opCtx,
+ oldCollOptions,
+ coll.getWritableCollection(opCtx),
+ *cmd.getExpireAfterSeconds());
}
// Handle index modifications.
@@ -745,20 +747,20 @@ Status _collModInternal(OperationContext* opCtx,
mode);
if (cmrNew.collValidator) {
- coll.getWritableCollection()->setValidator(opCtx, *cmrNew.collValidator);
+ coll.getWritableCollection(opCtx)->setValidator(opCtx, *cmrNew.collValidator);
}
if (cmrNew.collValidationAction)
- uassertStatusOKWithContext(coll.getWritableCollection()->setValidationAction(
+ uassertStatusOKWithContext(coll.getWritableCollection(opCtx)->setValidationAction(
opCtx, *cmrNew.collValidationAction),
"Failed to set validationAction");
if (cmrNew.collValidationLevel) {
- uassertStatusOKWithContext(coll.getWritableCollection()->setValidationLevel(
+ uassertStatusOKWithContext(coll.getWritableCollection(opCtx)->setValidationLevel(
opCtx, *cmrNew.collValidationLevel),
"Failed to set validationLevel");
}
if (cmrNew.recordPreImages != oldCollOptions.recordPreImages) {
- coll.getWritableCollection()->setRecordPreImages(opCtx, cmrNew.recordPreImages);
+ coll.getWritableCollection(opCtx)->setRecordPreImages(opCtx, cmrNew.recordPreImages);
}
// TODO SERVER-58584: remove the feature flag.
@@ -766,7 +768,7 @@ Status _collModInternal(OperationContext* opCtx,
cmrNew.changeStreamPreAndPostImagesOptions.has_value() &&
*cmrNew.changeStreamPreAndPostImagesOptions !=
oldCollOptions.changeStreamPreAndPostImagesOptions) {
- coll.getWritableCollection()->setChangeStreamPreAndPostImages(
+ coll.getWritableCollection(opCtx)->setChangeStreamPreAndPostImages(
opCtx, *cmrNew.changeStreamPreAndPostImagesOptions);
}
@@ -776,21 +778,21 @@ Status _collModInternal(OperationContext* opCtx,
uassertStatusOK(res);
auto [newOptions, changed] = res.getValue();
if (changed) {
- coll.getWritableCollection()->setTimeseriesOptions(opCtx, newOptions);
+ coll.getWritableCollection(opCtx)->setTimeseriesOptions(opCtx, newOptions);
}
}
// Remove any invalid index options for indexes belonging to this collection.
std::vector<std::string> indexesWithInvalidOptions =
- coll.getWritableCollection()->removeInvalidIndexOptions(opCtx);
+ coll.getWritableCollection(opCtx)->removeInvalidIndexOptions(opCtx);
for (const auto& indexWithInvalidOptions : indexesWithInvalidOptions) {
const IndexDescriptor* desc =
coll->getIndexCatalog()->findIndexByName(opCtx, indexWithInvalidOptions);
invariant(desc);
// Notify the index catalog that the definition of this index changed.
- coll.getWritableCollection()->getIndexCatalog()->refreshEntry(
- opCtx, coll.getWritableCollection(), desc, CreateIndexEntryFlags::kIsReady);
+ coll.getWritableCollection(opCtx)->getIndexCatalog()->refreshEntry(
+ opCtx, coll.getWritableCollection(opCtx), desc, CreateIndexEntryFlags::kIsReady);
}
// TODO SERVER-60911: When kLatest is 5.3, only check when upgrading from or downgrading to
@@ -803,15 +805,16 @@ Status _collModInternal(OperationContext* opCtx,
// time-series collections that are missing the flag. This indicates that the
// time-series collection existed in earlier server versions and may have mixed-schema
// data.
- coll.getWritableCollection()->setTimeseriesBucketsMayHaveMixedSchemaData(opCtx, true);
+ coll.getWritableCollection(opCtx)->setTimeseriesBucketsMayHaveMixedSchemaData(opCtx,
+ true);
} else if (coll->getTimeseriesBucketsMayHaveMixedSchemaData() &&
serverGlobalParams.featureCompatibility
.isFCVDowngradingOrAlreadyDowngradedFromLatest()) {
// While downgrading the FCV from 5.2, collMod is called as part of the downgrade
// process to remove the 'timeseriesBucketsMayHaveMixedSchemaData' catalog entry
// flag for time-series collections that have the flag.
- coll.getWritableCollection()->setTimeseriesBucketsMayHaveMixedSchemaData(opCtx,
- boost::none);
+ coll.getWritableCollection(opCtx)->setTimeseriesBucketsMayHaveMixedSchemaData(
+ opCtx, boost::none);
}
// Only observe non-view collMods, as view operations are observed as operations on the
diff --git a/src/mongo/db/catalog/coll_mod_index.cpp b/src/mongo/db/catalog/coll_mod_index.cpp
index 878a702dcbd..93de283d952 100644
--- a/src/mongo/db/catalog/coll_mod_index.cpp
+++ b/src/mongo/db/catalog/coll_mod_index.cpp
@@ -74,7 +74,7 @@ void _processCollModIndexRequestExpireAfterSeconds(OperationContext* opCtx,
});
// Change the value of "expireAfterSeconds" on disk.
- autoColl->getWritableCollection()->updateTTLSetting(
+ autoColl->getWritableCollection(opCtx)->updateTTLSetting(
opCtx, idx->indexName(), indexExpireAfterSeconds);
return;
}
@@ -84,7 +84,7 @@ void _processCollModIndexRequestExpireAfterSeconds(OperationContext* opCtx,
*oldExpireSecs = oldExpireSecsElement.safeNumberLong();
if (**oldExpireSecs != indexExpireAfterSeconds) {
// Change the value of "expireAfterSeconds" on disk.
- autoColl->getWritableCollection()->updateTTLSetting(
+ autoColl->getWritableCollection(opCtx)->updateTTLSetting(
opCtx, idx->indexName(), indexExpireAfterSeconds);
}
}
@@ -102,7 +102,7 @@ void _processCollModIndexRequestHidden(OperationContext* opCtx,
*oldHidden = idx->hidden();
// Make sure when we set 'hidden' to false, we can remove the hidden field from catalog.
if (*oldHidden != *newHidden) {
- autoColl->getWritableCollection()->updateHiddenSetting(
+ autoColl->getWritableCollection(opCtx)->updateHiddenSetting(
opCtx, idx->indexName(), indexHidden);
}
}
@@ -185,7 +185,7 @@ void _processCollModIndexRequestUnique(OperationContext* opCtx,
}
*newUnique = true;
- autoColl->getWritableCollection()->updateUniqueSetting(opCtx, idx->indexName());
+ autoColl->getWritableCollection(opCtx)->updateUniqueSetting(opCtx, idx->indexName());
}
} // namespace
@@ -251,8 +251,8 @@ void processCollModIndexRequest(OperationContext* opCtx,
// Notify the index catalog that the definition of this index changed. This will invalidate the
// local idx pointer. On rollback of this WUOW, the local var idx pointer will be valid again.
- autoColl->getWritableCollection()->getIndexCatalog()->refreshEntry(
- opCtx, autoColl->getWritableCollection(), idx, flags);
+ autoColl->getWritableCollection(opCtx)->getIndexCatalog()->refreshEntry(
+ opCtx, autoColl->getWritableCollection(opCtx), idx, flags);
opCtx->recoveryUnit()->onCommit(
[oldExpireSecs, newExpireSecs, oldHidden, newHidden, newUnique, result](
diff --git a/src/mongo/db/catalog/collection_test.cpp b/src/mongo/db/catalog/collection_test.cpp
index a95c7a9b93f..759a01fcd52 100644
--- a/src/mongo/db/catalog/collection_test.cpp
+++ b/src/mongo/db/catalog/collection_test.cpp
@@ -228,7 +228,7 @@ void CollectionTest::makeCollectionForMultikey(NamespaceString nss, StringData i
auto opCtx = operationContext();
{
AutoGetCollection autoColl(opCtx, nss, MODE_IX);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(opCtx);
WriteUnitOfWork wuow(opCtx);
ASSERT(db->createCollection(opCtx, nss));
wuow.commit();
@@ -237,7 +237,7 @@ void CollectionTest::makeCollectionForMultikey(NamespaceString nss, StringData i
{
AutoGetCollection autoColl(opCtx, nss, MODE_X);
WriteUnitOfWork wuow(opCtx);
- auto collWriter = autoColl.getWritableCollection();
+ auto collWriter = autoColl.getWritableCollection(opCtx);
ASSERT_OK(collWriter->getIndexCatalog()->createIndexOnEmptyCollection(
opCtx, collWriter, BSON("v" << 2 << "name" << indexName << "key" << BSON("a" << 1))));
wuow.commit();
diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp
index 454793339f4..2ce0f9b5558 100644
--- a/src/mongo/db/catalog/create_collection.cpp
+++ b/src/mongo/db/catalog/create_collection.cpp
@@ -369,7 +369,7 @@ Status _createTimeseries(OperationContext* opCtx,
str::stream() << "Collection already exists. NS: " << ns);
}
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(opCtx);
if (auto view = ViewCatalog::get(db)->lookup(opCtx, ns)) {
if (view->timeseries()) {
return {ErrorCodes::NamespaceExists,
diff --git a/src/mongo/db/catalog/create_collection_test.cpp b/src/mongo/db/catalog/create_collection_test.cpp
index a8cdc840d87..3141d18905c 100644
--- a/src/mongo/db/catalog/create_collection_test.cpp
+++ b/src/mongo/db/catalog/create_collection_test.cpp
@@ -102,7 +102,7 @@ void CreateCollectionTest::validateValidator(const std::string& validatorStr,
return writeConflictRetry(opCtx.get(), "create", newNss.ns(), [&] {
AutoGetCollection autoColl(opCtx.get(), newNss, MODE_IX);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(opCtx.get());
ASSERT_TRUE(db) << "Cannot create collection " << newNss << " because database "
<< newNss.db() << " does not exist.";
diff --git a/src/mongo/db/catalog/drop_indexes.cpp b/src/mongo/db/catalog/drop_indexes.cpp
index 8d0ec2229e2..faf02f818a9 100644
--- a/src/mongo/db/catalog/drop_indexes.cpp
+++ b/src/mongo/db/catalog/drop_indexes.cpp
@@ -459,7 +459,7 @@ DropIndexesReply dropIndexes(OperationContext* opCtx,
// Iterate through all the aborted indexes and drop any indexes that are ready in
// the index catalog. This would indicate that while we yielded our locks during the
// abort phase, a new identical index was created.
- auto indexCatalog = collection->getWritableCollection()->getIndexCatalog();
+ auto indexCatalog = collection->getWritableCollection(opCtx)->getIndexCatalog();
const bool includeUnfinished = false;
for (const auto& indexName : indexNames) {
auto desc = indexCatalog->findIndexByName(opCtx, indexName, includeUnfinished);
@@ -469,7 +469,7 @@ DropIndexesReply dropIndexes(OperationContext* opCtx,
}
uassertStatusOK(dropIndexByDescriptor(
- opCtx, collection->getWritableCollection(), indexCatalog, desc));
+ opCtx, collection->getWritableCollection(opCtx), indexCatalog, desc));
}
wuow.commit();
@@ -502,7 +502,7 @@ DropIndexesReply dropIndexes(OperationContext* opCtx,
// This is necessary to check shard version.
OldClientContext ctx(opCtx, (*collection)->ns().ns());
- dropReadyIndexes(opCtx, collection->getWritableCollection(), indexNames, &reply);
+ dropReadyIndexes(opCtx, collection->getWritableCollection(opCtx), indexNames, &reply);
wunit.commit();
});
@@ -554,7 +554,7 @@ Status dropIndexesForApplyOps(OperationContext* opCtx,
DropIndexesReply ignoredReply;
dropReadyIndexes(
- opCtx, collection.getWritableCollection(), swIndexNames.getValue(), &ignoredReply);
+ opCtx, collection.getWritableCollection(opCtx), swIndexNames.getValue(), &ignoredReply);
wunit.commit();
return Status::OK();
diff --git a/src/mongo/db/catalog/index_builds_manager.cpp b/src/mongo/db/catalog/index_builds_manager.cpp
index b6955e9691b..155a411aec2 100644
--- a/src/mongo/db/catalog/index_builds_manager.cpp
+++ b/src/mongo/db/catalog/index_builds_manager.cpp
@@ -419,7 +419,7 @@ StatusWith<int> IndexBuildsManager::_moveRecordToLostAndFound(
AutoGetCollection autoColl(opCtx, lostAndFoundNss, MODE_IX);
// Ensure the database exists.
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(opCtx);
invariant(db, lostAndFoundNss.ns());
WriteUnitOfWork wuow(opCtx);
diff --git a/src/mongo/db/catalog/index_builds_manager_test.cpp b/src/mongo/db/catalog/index_builds_manager_test.cpp
index 649c4b0e749..8e986dad1b5 100644
--- a/src/mongo/db/catalog/index_builds_manager_test.cpp
+++ b/src/mongo/db/catalog/index_builds_manager_test.cpp
@@ -81,7 +81,7 @@ std::vector<BSONObj> makeSpecs(const NamespaceString& nss, std::vector<std::stri
TEST_F(IndexBuildsManagerTest, IndexBuildsManagerSetUpAndTearDown) {
AutoGetCollection autoColl(operationContext(), _nss, MODE_X);
- CollectionWriter collection(autoColl);
+ CollectionWriter collection(operationContext(), autoColl);
auto specs = makeSpecs(_nss, {"a", "b"});
ASSERT_OK(_indexBuildsManager.setUpIndexBuild(
diff --git a/src/mongo/db/catalog/index_signature_test.cpp b/src/mongo/db/catalog/index_signature_test.cpp
index fcf1d3d0b21..6595cfb29bf 100644
--- a/src/mongo/db/catalog/index_signature_test.cpp
+++ b/src/mongo/db/catalog/index_signature_test.cpp
@@ -48,9 +48,9 @@ public:
// Build the specified index on the collection.
WriteUnitOfWork wuow(opCtx());
// Get the index catalog associated with the test collection.
- auto* indexCatalog = _coll->getWritableCollection()->getIndexCatalog();
+ auto* indexCatalog = _coll->getWritableCollection(opCtx())->getIndexCatalog();
auto status = indexCatalog->createIndexOnEmptyCollection(
- opCtx(), _coll->getWritableCollection(), spec);
+ opCtx(), _coll->getWritableCollection(opCtx()), spec);
if (!status.isOK()) {
return status.getStatus();
}
diff --git a/src/mongo/db/catalog/multi_index_block_test.cpp b/src/mongo/db/catalog/multi_index_block_test.cpp
index ccaed706b7c..f867de098ed 100644
--- a/src/mongo/db/catalog/multi_index_block_test.cpp
+++ b/src/mongo/db/catalog/multi_index_block_test.cpp
@@ -91,7 +91,7 @@ TEST_F(MultiIndexBlockTest, CommitWithoutInsertingDocuments) {
auto indexer = getIndexer();
AutoGetCollection autoColl(operationContext(), getNSS(), MODE_X);
- CollectionWriter coll(autoColl);
+ CollectionWriter coll(operationContext(), autoColl);
auto specs = unittest::assertGet(indexer->init(
operationContext(), coll, std::vector<BSONObj>(), MultiIndexBlock::kNoopOnInitFn));
@@ -114,7 +114,7 @@ TEST_F(MultiIndexBlockTest, CommitAfterInsertingSingleDocument) {
auto indexer = getIndexer();
AutoGetCollection autoColl(operationContext(), getNSS(), MODE_X);
- CollectionWriter coll(autoColl);
+ CollectionWriter coll(operationContext(), autoColl);
auto specs = unittest::assertGet(indexer->init(
operationContext(), coll, std::vector<BSONObj>(), MultiIndexBlock::kNoopOnInitFn));
@@ -147,7 +147,7 @@ TEST_F(MultiIndexBlockTest, AbortWithoutCleanupAfterInsertingSingleDocument) {
auto indexer = getIndexer();
AutoGetCollection autoColl(operationContext(), getNSS(), MODE_X);
- CollectionWriter coll(autoColl);
+ CollectionWriter coll(operationContext(), autoColl);
auto specs = unittest::assertGet(indexer->init(
operationContext(), coll, std::vector<BSONObj>(), MultiIndexBlock::kNoopOnInitFn));
@@ -167,7 +167,7 @@ TEST_F(MultiIndexBlockTest, InitWriteConflictException) {
auto indexer = getIndexer();
AutoGetCollection autoColl(operationContext(), getNSS(), MODE_X);
- CollectionWriter coll(autoColl);
+ CollectionWriter coll(operationContext(), autoColl);
BSONObj spec = BSON("key" << BSON("a" << 1) << "name"
<< "a_1"
diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp
index 57863d4e453..e51ad09c0d1 100644
--- a/src/mongo/db/catalog/rename_collection_test.cpp
+++ b/src/mongo/db/catalog/rename_collection_test.cpp
@@ -471,10 +471,10 @@ void _createIndexOnEmptyCollection(OperationContext* opCtx,
<< BSON("a" << 1) << "name" << indexName);
WriteUnitOfWork wuow(opCtx);
- auto indexCatalog = collection.getWritableCollection()->getIndexCatalog();
+ auto indexCatalog = collection.getWritableCollection(opCtx)->getIndexCatalog();
ASSERT_OK(indexCatalog
->createIndexOnEmptyCollection(
- opCtx, collection.getWritableCollection(), indexInfoObj)
+ opCtx, collection.getWritableCollection(opCtx), indexInfoObj)
.getStatus());
wuow.commit();
});
diff --git a/src/mongo/db/catalog/validate_state_test.cpp b/src/mongo/db/catalog/validate_state_test.cpp
index fcb82204717..45868b0ad87 100644
--- a/src/mongo/db/catalog/validate_state_test.cpp
+++ b/src/mongo/db/catalog/validate_state_test.cpp
@@ -142,8 +142,8 @@ void dropIndex(OperationContext* opCtx, const NamespaceString& nss, const std::s
auto indexDescriptor = collection->getIndexCatalog()->findIndexByName(opCtx, indexName);
ASSERT(indexDescriptor);
- ASSERT_OK(collection.getWritableCollection()->getIndexCatalog()->dropIndex(
- opCtx, collection.getWritableCollection(), indexDescriptor));
+ ASSERT_OK(collection.getWritableCollection(opCtx)->getIndexCatalog()->dropIndex(
+ opCtx, collection.getWritableCollection(opCtx), indexDescriptor));
ASSERT_OK(opCtx->recoveryUnit()->setTimestamp(
repl::ReplicationCoordinator::get(opCtx)->getMyLastAppliedOpTime().getTimestamp() + 1));
diff --git a/src/mongo/db/catalog_raii.cpp b/src/mongo/db/catalog_raii.cpp
index 3625d81ff4a..155cdabc8b0 100644
--- a/src/mongo/db/catalog_raii.cpp
+++ b/src/mongo/db/catalog_raii.cpp
@@ -78,8 +78,7 @@ AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
LockMode modeColl,
AutoGetCollectionViewMode viewMode,
Date_t deadline)
- : _opCtx(opCtx),
- _autoDb(opCtx,
+ : _autoDb(opCtx,
!nsOrUUID.dbname().empty() ? nsOrUUID.dbname() : nsOrUUID.nss()->db(),
isSharedLockMode(modeColl) ? MODE_IS : MODE_IX,
deadline) {
@@ -179,27 +178,26 @@ AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
!_view || viewMode == AutoGetCollectionViewMode::kViewsPermitted);
}
-Collection* AutoGetCollection::getWritableCollection(CollectionCatalog::LifetimeMode mode) {
+Collection* AutoGetCollection::getWritableCollection(OperationContext* opCtx,
+ CollectionCatalog::LifetimeMode mode) {
// Acquire writable instance if not already available
if (!_writableColl) {
- auto catalog = CollectionCatalog::get(_opCtx);
+ auto catalog = CollectionCatalog::get(opCtx);
_writableColl =
- catalog->lookupCollectionByNamespaceForMetadataWrite(_opCtx, mode, _resolvedNss);
+ catalog->lookupCollectionByNamespaceForMetadataWrite(opCtx, mode, _resolvedNss);
if (mode != CollectionCatalog::LifetimeMode::kInplace) {
// Makes the internal CollectionPtr Yieldable and resets the writable Collection when
// the write unit of work finishes so we re-fetches and re-clones the Collection if a
// new write unit of work is opened.
- _opCtx->recoveryUnit()->registerChange(
- [this](boost::optional<Timestamp> commitTime) {
- _coll = CollectionPtr(
- getOperationContext(), _coll.get(), LookupCollectionForYieldRestore());
+ opCtx->recoveryUnit()->registerChange(
+ [this, opCtx](boost::optional<Timestamp> commitTime) {
+ _coll = CollectionPtr(opCtx, _coll.get(), LookupCollectionForYieldRestore());
_writableColl = nullptr;
},
- [this, originalCollection = _coll.get()]() {
- _coll = CollectionPtr(getOperationContext(),
- originalCollection,
- LookupCollectionForYieldRestore());
+ [this, originalCollection = _coll.get(), opCtx]() {
+ _coll =
+ CollectionPtr(opCtx, originalCollection, LookupCollectionForYieldRestore());
_writableColl = nullptr;
});
}
@@ -337,16 +335,17 @@ CollectionWriter::CollectionWriter(OperationContext* opCtx,
};
}
-CollectionWriter::CollectionWriter(AutoGetCollection& autoCollection,
+CollectionWriter::CollectionWriter(OperationContext* opCtx,
+ AutoGetCollection& autoCollection,
CollectionCatalog::LifetimeMode mode)
: _collection(&autoCollection.getCollection()),
- _opCtx(autoCollection.getOperationContext()),
+ _opCtx(opCtx),
_mode(mode),
_sharedImpl(std::make_shared<SharedImpl>(this)) {
- _sharedImpl->_writableCollectionInitializer =
- [&autoCollection](CollectionCatalog::LifetimeMode mode) {
- return autoCollection.getWritableCollection(mode);
- };
+ _sharedImpl->_writableCollectionInitializer = [&autoCollection,
+ opCtx](CollectionCatalog::LifetimeMode mode) {
+ return autoCollection.getWritableCollection(opCtx, mode);
+ };
}
CollectionWriter::CollectionWriter(Collection* writableCollection)
diff --git a/src/mongo/db/catalog_raii.h b/src/mongo/db/catalog_raii.h
index 69f2abac298..b62d791c1ce 100644
--- a/src/mongo/db/catalog_raii.h
+++ b/src/mongo/db/catalog_raii.h
@@ -137,8 +137,8 @@ public:
/**
* Returns the database, creating it if it does not exist.
*/
- Database* ensureDbExists() {
- return _autoDb.ensureDbExists(_opCtx);
+ Database* ensureDbExists(OperationContext* opCtx) {
+ return _autoDb.ensureDbExists(opCtx);
}
/**
@@ -174,13 +174,10 @@ public:
* the original Collection pointer.
*/
Collection* getWritableCollection(
+ OperationContext* opCtx,
CollectionCatalog::LifetimeMode mode =
CollectionCatalog::LifetimeMode::kManagedInWriteUnitOfWork);
- OperationContext* getOperationContext() const {
- return _opCtx;
- }
-
protected:
template <typename AutoGetCollectionType, typename EmplaceAutoGetCollectionFunc>
friend class AutoGetCollectionForReadBase;
@@ -192,7 +189,6 @@ protected:
return _coll;
}
- OperationContext* _opCtx = nullptr;
AutoGetDb _autoDb;
boost::optional<Lock::CollectionLock> _collLock;
CollectionPtr _coll = nullptr;
@@ -361,7 +357,8 @@ public:
CollectionCatalog::LifetimeMode mode =
CollectionCatalog::LifetimeMode::kManagedInWriteUnitOfWork);
// Acts as an adaptor for AutoGetCollection
- CollectionWriter(AutoGetCollection& autoCollection,
+ CollectionWriter(OperationContext* opCtx,
+ AutoGetCollection& autoCollection,
CollectionCatalog::LifetimeMode mode =
CollectionCatalog::LifetimeMode::kManagedInWriteUnitOfWork);
// Acts as an adaptor for a writable Collection that has been retrieved elsewhere
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index ce3bbfbb0fa..0f6b55952ca 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -162,7 +162,7 @@ public:
uasserted(ErrorCodes::NamespaceNotFound, "collection does not exist");
}
- CollectionWriter collection(autoColl);
+ CollectionWriter collection(opCtx, autoColl);
IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection(
collection->uuid());
diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp
index 906cdf7923c..f641012f28d 100644
--- a/src/mongo/db/commands/feature_compatibility_version.cpp
+++ b/src/mongo/db/commands/feature_compatibility_version.cpp
@@ -247,7 +247,7 @@ void runUpdateCommand(OperationContext* opCtx, const FeatureCompatibilityVersion
boost::optional<BSONObj> FeatureCompatibilityVersion::findFeatureCompatibilityVersionDocument(
OperationContext* opCtx) {
AutoGetCollection autoColl(opCtx, NamespaceString::kServerConfigurationNamespace, MODE_IX);
- invariant(autoColl.ensureDbExists(), NamespaceString::kServerConfigurationNamespace.ns());
+ invariant(autoColl.ensureDbExists(opCtx), NamespaceString::kServerConfigurationNamespace.ns());
const auto query = BSON("_id" << multiversion::kParameterName);
const auto swFcv = repl::StorageInterface::get(opCtx)->findById(
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp
index b197962fe8e..6518620c51c 100644
--- a/src/mongo/db/commands/find_and_modify.cpp
+++ b/src/mongo/db/commands/find_and_modify.cpp
@@ -416,7 +416,7 @@ write_ops::FindAndModifyCommandReply CmdFindAndModify::Invocation::writeConflict
ParsedUpdate* parsedUpdate) {
AutoGetCollection autoColl(opCtx, nsString, MODE_IX);
- Database* db = autoColl.ensureDbExists();
+ Database* db = autoColl.ensureDbExists(opCtx);
{
stdx::lock_guard<Client> lk(*opCtx->getClient());
diff --git a/src/mongo/db/commands/mr_test.cpp b/src/mongo/db/commands/mr_test.cpp
index d5b84f9483a..ad7c8d6ab38 100644
--- a/src/mongo/db/commands/mr_test.cpp
+++ b/src/mongo/db/commands/mr_test.cpp
@@ -540,8 +540,10 @@ TEST_F(MapReduceCommandTest, ReplacingExistingOutputCollectionPreservesIndexes)
_opCtx.get(), "ReplacingExistingOutputCollectionPreservesIndexes", outputNss.ns(), [&] {
WriteUnitOfWork wuow(_opCtx.get());
ASSERT_OK(
- coll.getWritableCollection()->getIndexCatalog()->createIndexOnEmptyCollection(
- _opCtx.get(), coll.getWritableCollection(), indexSpec));
+ coll.getWritableCollection(_opCtx.get())
+ ->getIndexCatalog()
+ ->createIndexOnEmptyCollection(
+ _opCtx.get(), coll.getWritableCollection(_opCtx.get()), indexSpec));
wuow.commit();
});
}
diff --git a/src/mongo/db/commands/resize_oplog.cpp b/src/mongo/db/commands/resize_oplog.cpp
index 5476c4ea249..840a7ed81c0 100644
--- a/src/mongo/db/commands/resize_oplog.cpp
+++ b/src/mongo/db/commands/resize_oplog.cpp
@@ -97,7 +97,8 @@ public:
if (auto sizeMB = params.getSize()) {
const long long sizeBytes = *sizeMB * 1024 * 1024;
- uassertStatusOK(coll.getWritableCollection()->updateCappedSize(opCtx, sizeBytes));
+ uassertStatusOK(
+ coll.getWritableCollection(opCtx)->updateCappedSize(opCtx, sizeBytes));
}
if (auto minRetentionHoursOpt = params.getMinRetentionHours()) {
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp
index 1641ee9870d..c243a40f998 100644
--- a/src/mongo/db/index_builds_coordinator.cpp
+++ b/src/mongo/db/index_builds_coordinator.cpp
@@ -855,7 +855,7 @@ void IndexBuildsCoordinator::applyStartIndexBuild(OperationContext* opCtx,
invariant(coll,
str::stream() << "Collection with UUID " << collUUID << " was dropped.");
- IndexCatalog* indexCatalog = coll.getWritableCollection()->getIndexCatalog();
+ IndexCatalog* indexCatalog = coll.getWritableCollection(opCtx)->getIndexCatalog();
const bool includeUnfinished = false;
for (const auto& spec : oplogEntry.indexSpecs) {
@@ -866,7 +866,7 @@ void IndexBuildsCoordinator::applyStartIndexBuild(OperationContext* opCtx,
if (auto desc = indexCatalog->findIndexByName(opCtx, name, includeUnfinished)) {
uassertStatusOK(
- indexCatalog->dropIndex(opCtx, coll.getWritableCollection(), desc));
+ indexCatalog->dropIndex(opCtx, coll.getWritableCollection(opCtx), desc));
}
}
@@ -1737,7 +1737,7 @@ IndexBuildsCoordinator::_filterSpecsAndRegisterBuild(OperationContext* opCtx,
// AutoGetCollection throws an exception if it is unable to look up the collection by UUID.
NamespaceStringOrUUID nssOrUuid{dbName.toString(), collectionUUID};
AutoGetCollection autoColl(opCtx, nssOrUuid, MODE_X);
- CollectionWriter collection(autoColl);
+ CollectionWriter collection(opCtx, autoColl);
const auto& ns = collection.get()->ns();
auto css = CollectionShardingState::get(opCtx, ns);
@@ -1822,7 +1822,7 @@ IndexBuildsCoordinator::PostSetupAction IndexBuildsCoordinator::_setUpIndexBuild
const NamespaceStringOrUUID nssOrUuid{replState->dbName, replState->collectionUUID};
AutoGetCollection coll(opCtx, nssOrUuid, MODE_X);
- CollectionWriter collection(coll);
+ CollectionWriter collection(opCtx, coll);
CollectionShardingState::get(opCtx, collection->ns())->checkShardVersionOrThrow(opCtx);
auto replCoord = repl::ReplicationCoordinator::get(opCtx);
diff --git a/src/mongo/db/op_observer_impl_test.cpp b/src/mongo/db/op_observer_impl_test.cpp
index fabf4919dbb..4b3b0b0fa64 100644
--- a/src/mongo/db/op_observer_impl_test.cpp
+++ b/src/mongo/db/op_observer_impl_test.cpp
@@ -174,9 +174,9 @@ public:
WriteUnitOfWork wunit(opCtx);
AutoGetCollection collRaii(opCtx, nss, LockMode::MODE_X);
if (collRaii) {
- invariant(collRaii.getWritableCollection()->truncate(opCtx).isOK());
+ invariant(collRaii.getWritableCollection(opCtx)->truncate(opCtx).isOK());
} else {
- auto db = collRaii.ensureDbExists();
+ auto db = collRaii.ensureDbExists(opCtx);
invariant(db->createCollection(opCtx, nss));
}
wunit.commit();
diff --git a/src/mongo/db/pipeline/process_interface/non_shardsvr_process_interface.cpp b/src/mongo/db/pipeline/process_interface/non_shardsvr_process_interface.cpp
index cb29fdd6b51..b54f190ae0b 100644
--- a/src/mongo/db/pipeline/process_interface/non_shardsvr_process_interface.cpp
+++ b/src/mongo/db/pipeline/process_interface/non_shardsvr_process_interface.cpp
@@ -146,7 +146,7 @@ StatusWith<MongoProcessInterface::UpdateResult> NonShardServerProcessInterface::
void NonShardServerProcessInterface::createIndexesOnEmptyCollection(
OperationContext* opCtx, const NamespaceString& ns, const std::vector<BSONObj>& indexSpecs) {
AutoGetCollection autoColl(opCtx, ns, MODE_X);
- CollectionWriter collection(autoColl);
+ CollectionWriter collection(opCtx, autoColl);
writeConflictRetry(
opCtx, "CommonMongodProcessInterface::createIndexesOnEmptyCollection", ns.ns(), [&] {
uassert(ErrorCodes::DatabaseDropPending,
diff --git a/src/mongo/db/repl/collection_bulk_loader_impl.cpp b/src/mongo/db/repl/collection_bulk_loader_impl.cpp
index c06603c61ab..ab18ac012ff 100644
--- a/src/mongo/db/repl/collection_bulk_loader_impl.cpp
+++ b/src/mongo/db/repl/collection_bulk_loader_impl.cpp
@@ -85,7 +85,7 @@ Status CollectionBulkLoaderImpl::init(const std::vector<BSONObj>& secondaryIndex
// The opCtx is accessed indirectly through _secondaryIndexesBlock.
UnreplicatedWritesBlock uwb(_opCtx.get());
// This enforces the buildIndexes setting in the replica set configuration.
- CollectionWriter collWriter(*_collection);
+ CollectionWriter collWriter(_opCtx.get(), *_collection);
auto indexCatalog = collWriter.getWritableCollection()->getIndexCatalog();
auto specs = indexCatalog->removeExistingIndexesNoChecks(
_opCtx.get(), collWriter.get(), secondaryIndexSpecs);
@@ -245,11 +245,11 @@ Status CollectionBulkLoaderImpl::commit() {
status = writeConflictRetry(
_opCtx.get(), "CollectionBulkLoaderImpl::commit", _nss.ns(), [this] {
WriteUnitOfWork wunit(_opCtx.get());
- auto status =
- _secondaryIndexesBlock->commit(_opCtx.get(),
- _collection->getWritableCollection(),
- MultiIndexBlock::kNoopOnCreateEachFn,
- MultiIndexBlock::kNoopOnCommitFn);
+ auto status = _secondaryIndexesBlock->commit(
+ _opCtx.get(),
+ _collection->getWritableCollection(_opCtx.get()),
+ MultiIndexBlock::kNoopOnCreateEachFn,
+ MultiIndexBlock::kNoopOnCommitFn);
if (!status.isOK()) {
return status;
}
@@ -308,10 +308,11 @@ Status CollectionBulkLoaderImpl::commit() {
status = writeConflictRetry(
_opCtx.get(), "CollectionBulkLoaderImpl::commit", _nss.ns(), [this] {
WriteUnitOfWork wunit(_opCtx.get());
- auto status = _idIndexBlock->commit(_opCtx.get(),
- _collection->getWritableCollection(),
- MultiIndexBlock::kNoopOnCreateEachFn,
- MultiIndexBlock::kNoopOnCommitFn);
+ auto status =
+ _idIndexBlock->commit(_opCtx.get(),
+ _collection->getWritableCollection(_opCtx.get()),
+ MultiIndexBlock::kNoopOnCreateEachFn,
+ MultiIndexBlock::kNoopOnCommitFn);
if (!status.isOK()) {
return status;
}
@@ -343,14 +344,14 @@ Status CollectionBulkLoaderImpl::commit() {
void CollectionBulkLoaderImpl::_releaseResources() {
invariant(&cc() == _opCtx->getClient());
if (_secondaryIndexesBlock) {
- CollectionWriter collWriter(*_collection);
+ CollectionWriter collWriter(_opCtx.get(), *_collection);
_secondaryIndexesBlock->abortIndexBuild(
_opCtx.get(), collWriter, MultiIndexBlock::kNoopOnCleanUpFn);
_secondaryIndexesBlock.reset();
}
if (_idIndexBlock) {
- CollectionWriter collWriter(*_collection);
+ CollectionWriter collWriter(_opCtx.get(), *_collection);
_idIndexBlock->abortIndexBuild(_opCtx.get(), collWriter, MultiIndexBlock::kNoopOnCleanUpFn);
_idIndexBlock.reset();
}
diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp
index 6e16222e547..5dd66d101d2 100644
--- a/src/mongo/db/repl/storage_interface_impl.cpp
+++ b/src/mongo/db/repl/storage_interface_impl.cpp
@@ -259,19 +259,21 @@ StorageInterfaceImpl::createCollectionForBulkLoading(
if (options.capped) {
WriteUnitOfWork wunit(opCtx.get());
if (!idIndexSpec.isEmpty()) {
- auto status = autoColl->getWritableCollection()
- ->getIndexCatalog()
- ->createIndexOnEmptyCollection(
- opCtx.get(), autoColl->getWritableCollection(), idIndexSpec);
+ auto status =
+ autoColl->getWritableCollection(opCtx.get())
+ ->getIndexCatalog()
+ ->createIndexOnEmptyCollection(
+ opCtx.get(), autoColl->getWritableCollection(opCtx.get()), idIndexSpec);
if (!status.getStatus().isOK()) {
return status.getStatus();
}
}
for (auto&& spec : secondaryIndexSpecs) {
- auto status = autoColl->getWritableCollection()
- ->getIndexCatalog()
- ->createIndexOnEmptyCollection(
- opCtx.get(), autoColl->getWritableCollection(), spec);
+ auto status =
+ autoColl->getWritableCollection(opCtx.get())
+ ->getIndexCatalog()
+ ->createIndexOnEmptyCollection(
+ opCtx.get(), autoColl->getWritableCollection(opCtx.get()), spec);
if (!status.getStatus().isOK()) {
return status.getStatus();
}
@@ -553,7 +555,7 @@ Status StorageInterfaceImpl::truncateCollection(OperationContext* opCtx,
}
WriteUnitOfWork wunit(opCtx);
- const auto status = autoColl.getWritableCollection()->truncate(opCtx);
+ const auto status = autoColl.getWritableCollection(opCtx)->truncate(opCtx);
if (!status.isOK()) {
return status;
}
diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp
index 2b9444bec57..a5ce6180321 100644
--- a/src/mongo/db/repl/storage_interface_impl_test.cpp
+++ b/src/mongo/db/repl/storage_interface_impl_test.cpp
@@ -133,11 +133,12 @@ int _createIndexOnEmptyCollection(OperationContext* opCtx, NamespaceString nss,
AutoGetCollection coll(opCtx, nss, MODE_X);
WriteUnitOfWork wunit(opCtx);
- auto indexCatalog = coll.getWritableCollection()->getIndexCatalog();
+ auto indexCatalog = coll.getWritableCollection(opCtx)->getIndexCatalog();
ASSERT(indexCatalog);
ASSERT_OK(
- indexCatalog->createIndexOnEmptyCollection(opCtx, coll.getWritableCollection(), indexSpec)
+ indexCatalog
+ ->createIndexOnEmptyCollection(opCtx, coll.getWritableCollection(opCtx), indexSpec)
.getStatus());
wunit.commit();
diff --git a/src/mongo/db/s/implicit_collection_creation_test.cpp b/src/mongo/db/s/implicit_collection_creation_test.cpp
index cd299acf0c8..02dbe9ed456 100644
--- a/src/mongo/db/s/implicit_collection_creation_test.cpp
+++ b/src/mongo/db/s/implicit_collection_creation_test.cpp
@@ -44,7 +44,7 @@ class ImplicitCollectionCreationTest : public ShardServerTestFixture {};
TEST_F(ImplicitCollectionCreationTest, ImplicitCreateDisallowedByDefault) {
NamespaceString nss("ImplicitCreateDisallowedByDefaultDB.TestColl");
AutoGetCollection autoColl(operationContext(), nss, MODE_IX);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(operationContext());
WriteUnitOfWork wuow(operationContext());
ASSERT_THROWS_CODE(
uassertStatusOK(db->userCreateNS(operationContext(), nss, CollectionOptions{})),
@@ -58,7 +58,7 @@ TEST_F(ImplicitCollectionCreationTest, AllowImplicitCollectionCreate) {
OperationShardingState::ScopedAllowImplicitCollectionCreate_UNSAFE unsafeCreateCollection(
operationContext());
AutoGetCollection autoColl(operationContext(), nss, MODE_IX);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(operationContext());
WriteUnitOfWork wuow(operationContext());
ASSERT_OK(db->userCreateNS(operationContext(), nss, CollectionOptions{}));
wuow.commit();
diff --git a/src/mongo/db/s/resharding/resharding_data_copy_util.cpp b/src/mongo/db/s/resharding/resharding_data_copy_util.cpp
index 9e6b143efa6..a0410be86b5 100644
--- a/src/mongo/db/s/resharding/resharding_data_copy_util.cpp
+++ b/src/mongo/db/s/resharding/resharding_data_copy_util.cpp
@@ -66,7 +66,7 @@ void ensureCollectionExists(OperationContext* opCtx,
}
WriteUnitOfWork wuow(opCtx);
- coll.ensureDbExists()->createCollection(opCtx, nss, options);
+ coll.ensureDbExists(opCtx)->createCollection(opCtx, nss, options);
wuow.commit();
});
}
diff --git a/src/mongo/db/s/session_catalog_migration_destination_test.cpp b/src/mongo/db/s/session_catalog_migration_destination_test.cpp
index 518f122762c..6adf3a843b5 100644
--- a/src/mongo/db/s/session_catalog_migration_destination_test.cpp
+++ b/src/mongo/db/s/session_catalog_migration_destination_test.cpp
@@ -1988,10 +1988,10 @@ TEST_F(SessionCatalogMigrationDestinationTest, MigratingKnownStmtWhileOplogTrunc
auto lastOpTimeBeforeMigrate = getLastWriteOpTime();
{
+ // Empty the oplog collection.
AutoGetCollection oplogColl(opCtx, NamespaceString::kRsOplogNamespace, MODE_X);
WriteUnitOfWork wuow(opCtx);
- ASSERT_OK(
- oplogColl.getWritableCollection()->truncate(opCtx)); // Empties the oplog collection.
+ ASSERT_OK(oplogColl.getWritableCollection(opCtx)->truncate(opCtx));
wuow.commit();
}
diff --git a/src/mongo/db/s/shard_local.cpp b/src/mongo/db/s/shard_local.cpp
index ee7d9bada11..6583338ba41 100644
--- a/src/mongo/db/s/shard_local.cpp
+++ b/src/mongo/db/s/shard_local.cpp
@@ -150,7 +150,7 @@ Status ShardLocal::createIndexOnConfig(OperationContext* opCtx,
options.uuid = UUID::gen();
writeConflictRetry(opCtx, "ShardLocal::createIndexOnConfig", ns.ns(), [&] {
WriteUnitOfWork wunit(opCtx);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(opCtx);
collection = db->createCollection(opCtx, ns, options);
invariant(collection,
str::stream() << "Failed to create collection " << ns.ns()
diff --git a/src/mongo/dbtests/dbtests.cpp b/src/mongo/dbtests/dbtests.cpp
index 1e90dfc482a..2f0f6799f63 100644
--- a/src/mongo/dbtests/dbtests.cpp
+++ b/src/mongo/dbtests/dbtests.cpp
@@ -165,7 +165,7 @@ WriteContextForTests::WriteContextForTests(OperationContext* opCtx, StringData n
const bool doShardVersionCheck = false;
_clientContext.emplace(opCtx, _nss.ns(), doShardVersionCheck);
- auto db = _autoDb->ensureDbExistsopCtx);
+ auto db = _autoDb->ensureDbExists(opCtx);
invariant(db, _nss.ns());
invariant(db == _clientContext->db());
diff --git a/src/mongo/dbtests/indexupdatetests.cpp b/src/mongo/dbtests/indexupdatetests.cpp
index 13f405678bd..81de6756956 100644
--- a/src/mongo/dbtests/indexupdatetests.cpp
+++ b/src/mongo/dbtests/indexupdatetests.cpp
@@ -65,7 +65,7 @@ public:
AutoGetCollection autoColl(_opCtx, _nss, LockMode::MODE_IX);
WriteUnitOfWork wuow(_opCtx);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(_opCtx);
ASSERT(db->createCollection(_opCtx, _nss)) << _nss;
wuow.commit();
}
@@ -75,7 +75,7 @@ public:
AutoGetCollection autoColl(_opCtx, _nss, LockMode::MODE_X);
WriteUnitOfWork wuow(_opCtx);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(_opCtx);
ASSERT_OK(db->dropCollection(_opCtx, _nss, {})) << _nss;
wuow.commit();
}
@@ -132,7 +132,7 @@ class InsertBuildIgnoreUnique : public IndexBuildBase {
public:
void run() {
AutoGetCollection autoColl(_opCtx, _nss, LockMode::MODE_X);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(_opCtx);
ASSERT(db) << _nss;
auto& coll = collection();
{
@@ -186,7 +186,7 @@ public:
// Create a new collection.
{
AutoGetCollection autoColl(_opCtx, _nss, LockMode::MODE_IX);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(_opCtx);
ASSERT(db) << _nss;
auto& coll = collection();
@@ -242,7 +242,7 @@ public:
void run() {
{
AutoGetCollection autoColl(_opCtx, _nss, LockMode::MODE_X);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(_opCtx);
ASSERT(db) << _nss;
auto& coll = collection();
@@ -292,7 +292,7 @@ public:
{
// Recreate the collection as capped, without an _id index.
AutoGetCollection autoColl(_opCtx, _nss, LockMode::MODE_X);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(_opCtx);
WriteUnitOfWork wunit(_opCtx);
ASSERT_OK(db->dropCollection(_opCtx, _nss));
diff --git a/src/mongo/dbtests/multikey_paths_test.cpp b/src/mongo/dbtests/multikey_paths_test.cpp
index 06a1d88c1d7..00c175ec284 100644
--- a/src/mongo/dbtests/multikey_paths_test.cpp
+++ b/src/mongo/dbtests/multikey_paths_test.cpp
@@ -59,7 +59,7 @@ public:
void setUp() final {
AutoGetCollection autoColl(_opCtx.get(), _nss, MODE_IX);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(_opCtx.get());
WriteUnitOfWork wuow(_opCtx.get());
ASSERT(db->createCollection(_opCtx.get(), _nss));
diff --git a/src/mongo/dbtests/query_stage_collscan.cpp b/src/mongo/dbtests/query_stage_collscan.cpp
index 7eca1c0bfb2..cd041e97f4a 100644
--- a/src/mongo/dbtests/query_stage_collscan.cpp
+++ b/src/mongo/dbtests/query_stage_collscan.cpp
@@ -182,7 +182,7 @@ public:
AutoGetCollection autoColl(&_opCtx, ns, MODE_IX);
{
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(&_opCtx);
WriteUnitOfWork wuow(&_opCtx);
CollectionOptions collOptions;
diff --git a/src/mongo/dbtests/storage_timestamp_tests.cpp b/src/mongo/dbtests/storage_timestamp_tests.cpp
index 7ba0257b1ec..0eb9f571e45 100644
--- a/src/mongo/dbtests/storage_timestamp_tests.cpp
+++ b/src/mongo/dbtests/storage_timestamp_tests.cpp
@@ -243,18 +243,18 @@ public:
if (collRaii) {
WriteUnitOfWork wunit(_opCtx);
- invariant(collRaii.getWritableCollection()->truncate(_opCtx).isOK());
+ invariant(collRaii.getWritableCollection(_opCtx)->truncate(_opCtx).isOK());
if (_opCtx->recoveryUnit()->getCommitTimestamp().isNull()) {
ASSERT_OK(_opCtx->recoveryUnit()->setTimestamp(Timestamp(1, 1)));
}
- collRaii.getWritableCollection()->getIndexCatalog()->dropAllIndexes(
- _opCtx, collRaii.getWritableCollection(), false);
+ collRaii.getWritableCollection(_opCtx)->getIndexCatalog()->dropAllIndexes(
+ _opCtx, collRaii.getWritableCollection(_opCtx), false);
wunit.commit();
return;
}
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_IX);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(_opCtx);
WriteUnitOfWork wunit(_opCtx);
if (_opCtx->recoveryUnit()->getCommitTimestamp().isNull()) {
ASSERT_OK(_opCtx->recoveryUnit()->setTimestamp(Timestamp(1, 1)));
@@ -2085,7 +2085,7 @@ public:
reset(nss);
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X);
- CollectionWriter coll(autoColl);
+ CollectionWriter coll(_opCtx, autoColl);
RecordId catalogId = autoColl.getCollection()->getCatalogId();
@@ -2148,7 +2148,7 @@ public:
// timestamp.
ASSERT_OK(
indexer.commit(_opCtx,
- autoColl.getWritableCollection(),
+ autoColl.getWritableCollection(_opCtx),
[&](const BSONObj& indexSpec) {
if (SimulatePrimary) {
// The timestamping responsibility for each index is placed
@@ -2216,7 +2216,7 @@ public:
reset(nss);
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X);
- CollectionWriter collection(autoColl);
+ CollectionWriter collection(_opCtx, autoColl);
// Build an index on `{a: 1}`.
MultiIndexBlock indexer;
@@ -2708,7 +2708,7 @@ public:
reset(nss);
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X);
- CollectionWriter coll(autoColl);
+ CollectionWriter coll(_opCtx, autoColl);
const LogicalTime insertTimestamp = _clock->tickClusterTime(1);
{
@@ -2783,7 +2783,7 @@ public:
reset(nss);
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X);
- CollectionWriter coll(autoColl);
+ CollectionWriter coll(_opCtx, autoColl);
const LogicalTime insertTimestamp = _clock->tickClusterTime(1);
{
@@ -2930,7 +2930,7 @@ public:
reset(nss);
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X);
- CollectionWriter collection(autoColl);
+ CollectionWriter collection(_opCtx, autoColl);
// Indexing of parallel arrays is not allowed, so these are deemed "bad".
const auto badDoc1 =
@@ -3488,7 +3488,7 @@ public:
RAIIServerParameterControllerForTest storeImageInSideCollection(
"storeFindAndModifyImagesInSideCollection", true);
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X);
- CollectionWriter collection(autoColl);
+ CollectionWriter collection(_opCtx, autoColl);
const auto newObj = BSON("_id" << 0 << "a" << 1 << "b" << 1);
CollectionUpdateArgs args;
args.stmtIds = {1};
@@ -3550,7 +3550,7 @@ public:
// Enable in-place mutation for this document
ASSERT_EQUALS(mmb::Document::kInPlaceEnabled, doc.getCurrentInPlaceMode());
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X);
- CollectionWriter collection(autoColl);
+ CollectionWriter collection(_opCtx, autoColl);
const auto newObj = BSON("_id" << 0 << "a" << 0);
CollectionUpdateArgs args;
args.stmtIds = {1};
@@ -3598,7 +3598,7 @@ public:
RAIIServerParameterControllerForTest storeImageInSideCollection(
"storeFindAndModifyImagesInSideCollection", true);
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X);
- CollectionWriter collection(autoColl);
+ CollectionWriter collection(_opCtx, autoColl);
const auto bsonObj = BSON("_id" << 0 << "a" << 1);
{
diff --git a/src/mongo/dbtests/validate_tests.cpp b/src/mongo/dbtests/validate_tests.cpp
index 7fe436054d6..634fe828e05 100644
--- a/src/mongo/dbtests/validate_tests.cpp
+++ b/src/mongo/dbtests/validate_tests.cpp
@@ -80,7 +80,7 @@ public:
const bool createIdIndex = !clustered;
AutoGetCollection autoColl(&_opCtx, _nss, MODE_IX);
- auto db = autoColl.ensureDbExists();
+ auto db = autoColl.ensureDbExists(&_opCtx);
ASSERT_TRUE(db) << _nss;
WriteUnitOfWork wuow(&_opCtx);
diff --git a/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp b/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp
index 112a0205348..388dd6b2f29 100644
--- a/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp
+++ b/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp
@@ -203,7 +203,7 @@ protected:
Lock::DBLock dbLock(opCtx(), nss.db(), MODE_X);
AutoGetCollection autoColl(opCtx(), nss, MODE_X);
- CollectionWriter coll(autoColl);
+ CollectionWriter coll(opCtx(), autoColl);
MultiIndexBlock indexer;
ScopeGuard abortOnExit(