summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2020-01-24 11:17:16 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-01-24 20:03:54 +0000
commitcb499afd9f818a9fa0b33bb27810d65483c11700 (patch)
treecc2481ae61416f34a70dbbe968aa6dfb0ca6246f
parentfa1edf200322386eb5b7f64de6de2d163923a321 (diff)
downloadmongo-cb499afd9f818a9fa0b33bb27810d65483c11700.tar.gz
SERVER-45760 Clarify the required lock modes for MultiIndexBlock::init() and MultiIndexBlock::commit()
-rw-r--r--src/mongo/db/catalog/multi_index_block.cpp7
-rw-r--r--src/mongo/db/catalog/multi_index_block.h4
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)>;