diff options
-rw-r--r-- | src/mongo/db/catalog/multi_index_block.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/catalog/multi_index_block.h | 4 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/mongo/db/catalog/multi_index_block.cpp b/src/mongo/db/catalog/multi_index_block.cpp index 6ee21034efc..d1d9d146262 100644 --- a/src/mongo/db/catalog/multi_index_block.cpp +++ b/src/mongo/db/catalog/multi_index_block.cpp @@ -203,6 +203,9 @@ StatusWith<std::vector<BSONObj>> MultiIndexBlock::init(OperationContext* opCtx, Collection* collection, const std::vector<BSONObj>& indexSpecs, OnInitFn onInit) { + invariant(opCtx->lockState()->isCollectionLockedForMode(collection->ns(), MODE_IX), + str::stream() << "Collection " << collection->ns() << " with UUID " + << collection->uuid() << " is holding the incorrect lock"); if (State::kAborted == _getState()) { return {ErrorCodes::IndexBuildAborted, str::stream() << "Index build aborted: " << _abortReason @@ -742,6 +745,10 @@ Status MultiIndexBlock::commit(OperationContext* opCtx, Collection* collection, OnCreateEachFn onCreateEach, OnCommitFn onCommit) { + invariant(opCtx->lockState()->isCollectionLockedForMode(collection->ns(), MODE_X), + str::stream() << "Collection " << collection->ns() << " with UUID " + << collection->uuid() << " is holding the incorrect lock"); + // UUIDs are not guaranteed during startup because the check happens after indexes are rebuilt. if (_collectionUUID) { invariant(_collectionUUID.get() == collection->uuid()); diff --git a/src/mongo/db/catalog/multi_index_block.h b/src/mongo/db/catalog/multi_index_block.h index 7ffb1470d77..178b0a971c0 100644 --- a/src/mongo/db/catalog/multi_index_block.h +++ b/src/mongo/db/catalog/multi_index_block.h @@ -128,7 +128,7 @@ public: * * Does not need to be called inside of a WriteUnitOfWork (but can be due to nesting). * - * Requires holding an exclusive database lock. + * Requires holding an intent lock on the collection. */ using OnInitFn = std::function<Status(std::vector<BSONObj>& specs)>; StatusWith<std::vector<BSONObj>> init(OperationContext* opCtx, @@ -227,7 +227,7 @@ public: * `onCreateEach` will be called after each index has been marked as "ready". * `onCommit` will be called after all indexes have been marked "ready". * - * Requires holding an exclusive database lock. + * Requires holding an exclusive lock on the collection. */ using OnCommitFn = std::function<void()>; using OnCreateEachFn = std::function<void(const BSONObj& spec)>; |