diff options
Diffstat (limited to 'src/mongo/db/catalog/collection_compact.cpp')
| -rw-r--r-- | src/mongo/db/catalog/collection_compact.cpp | 13 |
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); |
