diff options
author | Paolo Polato <paolo.polato@mongodb.com> | 2022-05-16 15:33:30 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-05-16 16:59:50 +0000 |
commit | 5b39b570b4f4f4c4c0c054bb3e0b20f51d0312b6 (patch) | |
tree | 444a8a22b41d07f77fc1d95c52995b3eef1d7385 | |
parent | 34b7213aeed8a78a45ac01c376900884f5b9ca60 (diff) | |
download | mongo-5b39b570b4f4f4c4c0c054bb3e0b20f51d0312b6.tar.gz |
SERVER-66383 Persist the progress of ClusterChunksResizePolicy without holding the state mutex
(cherry picked from commit bbd45c53cc35a4e2c614be62d13e307ab56ddc95)
-rw-r--r-- | src/mongo/db/s/balancer/cluster_chunks_resize_policy_impl.cpp | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/mongo/db/s/balancer/cluster_chunks_resize_policy_impl.cpp b/src/mongo/db/s/balancer/cluster_chunks_resize_policy_impl.cpp index 53d316edf25..c05d998fe86 100644 --- a/src/mongo/db/s/balancer/cluster_chunks_resize_policy_impl.cpp +++ b/src/mongo/db/s/balancer/cluster_chunks_resize_policy_impl.cpp @@ -332,6 +332,30 @@ boost::optional<DefragmentationAction> ClusterChunksResizePolicyImpl::getNextStr void ClusterChunksResizePolicyImpl::applyActionResult(OperationContext* opCtx, const DefragmentationAction& action, const DefragmentationActionResponse& result) { + std::string completedNss; + ScopeGuard onExitGuard([&] { + if (!completedNss.empty()) { + PersistentTaskStore<CollectionType> store(CollectionType::ConfigNS); + try { + store.update( + opCtx, + BSON(CollectionType::kNssFieldName << completedNss), + BSON("$set" << BSON(CollectionType::kChunksAlreadySplitForDowngradeFieldName + << true)), + WriteConcerns::kMajorityWriteConcernNoTimeout); + } catch (const DBException& e) { + LOGV2(6417111, + "Could not mark collection as already processed by ClusterChunksResizePolicy", + "namespace"_attr = completedNss, + "error"_attr = redact(e)); + } + } + + // Notify the reception of an operation outcome, even if it did not lead to a change of the + // internal state. + _onStateUpdated(); + }); + stdx::lock_guard<Latch> lk(_stateMutex); if (!_activeRequestPromise.is_initialized()) { return; @@ -412,7 +436,6 @@ void ClusterChunksResizePolicyImpl::applyActionResult(OperationContext* opCtx, action); if (updatedEntryIt == _collectionsBeingProcessed.end()) { - _onStateUpdated(); return; } @@ -421,17 +444,7 @@ void ClusterChunksResizePolicyImpl::applyActionResult(OperationContext* opCtx, LOGV2(6417107, "Collection chunks resize process completed", "namespace"_attr = collectionState.getNss().ns()); - PersistentTaskStore<CollectionType> store(CollectionType::ConfigNS); - try { - store.update( - opCtx, - BSON(CollectionType::kNssFieldName << collectionState.getNss().ns()), - BSON("$set" << BSON(CollectionType::kChunksAlreadySplitForDowngradeFieldName - << true)), - WriteConcerns::kMajorityWriteConcernNoTimeout); - } catch (const ExceptionFor<ErrorCodes::NoMatchingDocument>&) { - // ignore - } + completedNss = collectionState.getNss().ns(); _collectionsBeingProcessed.erase(updatedEntryIt); } else if (collectionState.restartNeeded()) { @@ -443,7 +456,6 @@ void ClusterChunksResizePolicyImpl::applyActionResult(OperationContext* opCtx, std::move(*refreshedState)); } } - _onStateUpdated(); } boost::optional<CollectionState> ClusterChunksResizePolicyImpl::_buildInitialStateFor( |