summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/collection_compact.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/catalog/collection_compact.cpp
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/catalog/collection_compact.cpp')
-rw-r--r--src/mongo/db/catalog/collection_compact.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/mongo/db/catalog/collection_compact.cpp b/src/mongo/db/catalog/collection_compact.cpp
index b6cc7cb444d..4fed779eaae 100644
--- a/src/mongo/db/catalog/collection_compact.cpp
+++ b/src/mongo/db/catalog/collection_compact.cpp
@@ -74,10 +74,10 @@ StatusWith<int64_t> compactCollection(OperationContext* opCtx,
Database* database = autoDb.getDb();
uassert(ErrorCodes::NamespaceNotFound, "database does not exist", database);
- // The collection lock will be upgraded to an exclusive lock if the record store does not
- // support online compaction.
+ // The collection lock will be downgraded to an intent lock if the record store supports
+ // online compaction.
boost::optional<Lock::CollectionLock> collLk;
- collLk.emplace(opCtx, collectionNss, MODE_IX);
+ collLk.emplace(opCtx, collectionNss, MODE_X);
CollectionPtr collection = getCollectionForCompact(opCtx, collectionNss);
DisableDocumentValidation validationDisabler(opCtx);
@@ -91,9 +91,10 @@ StatusWith<int64_t> compactCollection(OperationContext* opCtx,
str::stream() << "cannot compact collection with record store: "
<< recordStore->name());
- if (!recordStore->supportsOnlineCompaction()) {
- // Storage engines that disallow online compaction should compact under an exclusive lock.
- collLk.emplace(opCtx, collectionNss, MODE_X);
+ 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);
// Ensure the collection was not dropped during the re-lock.
collection = getCollectionForCompact(opCtx, collectionNss);