diff options
author | Justin Seyster <justin.seyster@mongodb.com> | 2018-03-30 15:25:47 -0400 |
---|---|---|
committer | Justin Seyster <justin.seyster@mongodb.com> | 2018-04-12 16:05:53 -0400 |
commit | bc19d43fdc4aab85264def96f638128c0ddb8483 (patch) | |
tree | 09b5a9a15982edd4998d4665d6c67f8fbd7c83e7 /src/mongo/db/s | |
parent | c6620182aebd1b62d31879ce4d9456ff197aea22 (diff) | |
download | mongo-bc19d43fdc4aab85264def96f638128c0ddb8483.tar.gz |
SERVER-27534 All writing operations must fail if the term changes.
The description of this SERVER ticket describes a nasty race that can
occur if elections happen inbetween two batches during a large
update. (The included test confirms that the race is possible.)
To fix this, we want to check the operation context for interrupts
with each batch, and we need to make sure the check happens _after_
the collection lock gets taken and before the batch
inserts/updates/deletes execute.
A recent change to locking gives us almost exactly this for free: if a
collection lock has to wait, it throws an exception when the operation
context is interrupted, ending the operation. If the lock doesn't
wait, though, there is no check.
This patch adds that check in. Acquiring a lock now always throws if
the operation context is interrupted, which closes the race window in
this bug.
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r-- | src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp index 220e2658a35..6eea5422c0a 100644 --- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp +++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp @@ -538,6 +538,9 @@ void MigrationChunkClonerSourceLegacy::_cleanup(OperationContext* opCtx) { } if (_deleteNotifyExec) { + // Don't allow an Interrupt exception to prevent _deleteNotifyExec from getting cleaned up. + UninterruptibleLockGuard noInterrupt(opCtx->lockState()); + AutoGetCollection autoColl(opCtx, _args.getNss(), MODE_IS); const auto cursorManager = autoColl.getCollection() ? autoColl.getCollection()->getCursorManager() : nullptr; |