summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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);