diff options
author | Matthew Saltz <matthew.saltz@mongodb.com> | 2020-03-26 15:34:03 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-27 16:05:14 +0000 |
commit | efbe46ec29d5a7ba6bd1786a5c9b47fd44b731d3 (patch) | |
tree | 7fb917942c004208149d71c3236b6b42774e26da | |
parent | 45db64dd0947fa13373a0ed03ce7c3da9d97f12b (diff) | |
download | mongo-efbe46ec29d5a7ba6bd1786a5c9b47fd44b731d3.tar.gz |
SERVER-46849 Submit range deletion task in an onCommit handler
-rw-r--r-- | src/mongo/db/s/shard_server_op_observer.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/mongo/db/s/shard_server_op_observer.cpp b/src/mongo/db/s/shard_server_op_observer.cpp index 3cf0b4f6157..38855ba3aa4 100644 --- a/src/mongo/db/s/shard_server_op_observer.cpp +++ b/src/mongo/db/s/shard_server_op_observer.cpp @@ -120,6 +120,27 @@ private: }; /** + * Used to submit a range deletion task once it is certain that the update/insert to + * config.rangeDeletions is committed. + */ +class SubmitRangeDeletionHandler final : public RecoveryUnit::Change { +public: + SubmitRangeDeletionHandler(OperationContext* opCtx, RangeDeletionTask task) + : _opCtx(opCtx), _task(std::move(task)) {} + + void commit(boost::optional<Timestamp>) override { + migrationutil::submitRangeDeletionTask(_opCtx, _task).getAsync([](auto) {}); + } + + void rollback() override {} + +private: + OperationContext* _opCtx; + RangeDeletionTask _task; +}; + + +/** * Invalidates the in-memory routing table cache when a collection is dropped, so the next caller * with routing information will provoke a routing table refresh and see the drop. * @@ -243,8 +264,10 @@ void ShardServerOpObserver::onInserts(OperationContext* opCtx, auto deletionTask = RangeDeletionTask::parse( IDLParserErrorContext("ShardServerOpObserver"), insertedDoc); - if (!deletionTask.getPending()) - migrationutil::submitRangeDeletionTask(opCtx, deletionTask).getAsync([](auto) {}); + if (!deletionTask.getPending()) { + opCtx->recoveryUnit()->registerChange( + std::make_unique<SubmitRangeDeletionHandler>(opCtx, deletionTask)); + } } if (collDesc.isSharded()) { @@ -366,7 +389,8 @@ void ShardServerOpObserver::onUpdate(OperationContext* opCtx, const OplogUpdateE if (deletionTask.getDonorShardId() != ShardingState::get(opCtx)->shardId()) { // Range deletion tasks for moved away chunks are scheduled through the // MigrationCoordinator, so only schedule a task for received chunks. - migrationutil::submitRangeDeletionTask(opCtx, deletionTask).getAsync([](auto) {}); + opCtx->recoveryUnit()->registerChange( + std::make_unique<SubmitRangeDeletionHandler>(opCtx, deletionTask)); } } } |