diff options
author | Louis Williams <louis.williams@mongodb.com> | 2020-04-10 10:02:34 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-10 14:16:22 +0000 |
commit | 3d929ed533a72446353b18b5d60770aed33b58f1 (patch) | |
tree | 09bd3562511aef88eb6aa1ef3b6c45b8d73c16e9 /src/mongo/db/cloner.cpp | |
parent | 76d4548a751a56c8faf1887114685b540203a650 (diff) | |
download | mongo-3d929ed533a72446353b18b5d60770aed33b58f1.tar.gz |
SERVER-46560 Make abort index build deterministic
This redesigns user index build abort to have the following behavior:
- Take a collection X lock to stop the index build from making progress
- If we are no longer primary, return an error
- Check whether we can abort the index build (i.e. it is not already committing
or aborting)
- Delete the index catalog entry and write the abortIndexBuild oplog entry in a WUOW
- Interrupt the index builder thread
- Wait for the thread to exit
- Release locks
Diffstat (limited to 'src/mongo/db/cloner.cpp')
-rw-r--r-- | src/mongo/db/cloner.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index 1a45051af97..d7ec0c03de7 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -393,10 +393,6 @@ void Cloner::copyIndexes(OperationContext* opCtx, // implementations anyway as long as that is supported. MultiIndexBlock indexer; - // The code below throws, so ensure build cleanup occurs. - ON_BLOCK_EXIT( - [&] { indexer.cleanUpAfterBuild(opCtx, collection, MultiIndexBlock::kNoopOnCleanUpFn); }); - // Emit startIndexBuild and commitIndexBuild oplog entries if supported by the current FCV. auto opObserver = opCtx->getServiceContext()->getOpObserver(); auto fromMigrate = false; @@ -436,6 +432,11 @@ void Cloner::copyIndexes(OperationContext* opCtx, } auto indexInfoObjs = uassertStatusOK(indexer.init(opCtx, collection, indexesToBuild, onInitFn)); + + // The code below throws, so ensure build cleanup occurs. + auto abortOnExit = makeGuard( + [&] { indexer.abortIndexBuild(opCtx, collection, MultiIndexBlock::kNoopOnCleanUpFn); }); + uassertStatusOK(indexer.insertAllDocumentsInCollection(opCtx, collection)); uassertStatusOK(indexer.checkConstraints(opCtx)); @@ -463,6 +464,7 @@ void Cloner::copyIndexes(OperationContext* opCtx, } })); wunit.commit(); + abortOnExit.dismiss(); } bool Cloner::copyCollection(OperationContext* opCtx, |