summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2022-08-09 19:17:25 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-23 10:10:23 +0000
commitb646a5bade5c0b8e558b81f025b7c0f5c3bc783f (patch)
treeb4b032902012cbd8f561d6fa879c427a3f3af668 /src
parentfea0030c24c8d5658f2249bb15c8546350929e59 (diff)
downloadmongo-b646a5bade5c0b8e558b81f025b7c0f5c3bc783f.tar.gz
SERVER-68694 Reverse the compact commands locking order
(cherry picked from commit 4b8e1a96fce58426630f3d46170cf2c3a614c087)
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/catalog/collection_compact.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/mongo/db/catalog/collection_compact.cpp b/src/mongo/db/catalog/collection_compact.cpp
index 6f699daf158..233817947e4 100644
--- a/src/mongo/db/catalog/collection_compact.cpp
+++ b/src/mongo/db/catalog/collection_compact.cpp
@@ -76,10 +76,10 @@ StatusWith<int64_t> compactCollection(OperationContext* opCtx,
Database* database = autoDb.getDb();
uassert(ErrorCodes::NamespaceNotFound, "database does not exist", database);
- // The collection lock will be downgraded to an intent lock if the record store supports
- // online compaction.
+ // The collection lock will be upgraded to an exclusive lock if the record store does not
+ // support online compaction.
boost::optional<Lock::CollectionLock> collLk;
- collLk.emplace(opCtx, collectionNss, MODE_X);
+ collLk.emplace(opCtx, collectionNss, MODE_IX);
CollectionPtr collection = getCollectionForCompact(opCtx, database, collectionNss);
DisableDocumentValidation validationDisabler(opCtx);
@@ -93,10 +93,9 @@ StatusWith<int64_t> compactCollection(OperationContext* opCtx,
str::stream() << "cannot compact collection with record store: "
<< recordStore->name());
- if (recordStore->supportsOnlineCompaction()) {
- // Storage engines that allow online compaction should do so using an intent lock on the
- // collection.
- collLk.emplace(opCtx, collectionNss, MODE_IX);
+ if (!recordStore->supportsOnlineCompaction()) {
+ // Storage engines that disallow online compaction should compact under an exclusive lock.
+ collLk.emplace(opCtx, collectionNss, MODE_X);
// Ensure the collection was not dropped during the re-lock.
collection = getCollectionForCompact(opCtx, database, collectionNss);