diff options
Diffstat (limited to 'src/mongo/db/s/metadata_manager.cpp')
| -rw-r--r-- | src/mongo/db/s/metadata_manager.cpp | 49 |
1 files changed, 20 insertions, 29 deletions
diff --git a/src/mongo/db/s/metadata_manager.cpp b/src/mongo/db/s/metadata_manager.cpp index bcf333cbf6b..6f57d95f93a 100644 --- a/src/mongo/db/s/metadata_manager.cpp +++ b/src/mongo/db/s/metadata_manager.cpp @@ -36,7 +36,6 @@ #include "mongo/base/string_data.h" #include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/bson/util/builder.h" -#include "mongo/db/cursor_manager.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/range_arithmetic.h" #include "mongo/db/s/migration_util.h" @@ -277,15 +276,14 @@ SharedSemiFuture<void> MetadataManager::cleanUpRange(ChunkRange const& range, shouldDelayBeforeDeletion ? Seconds(orphanCleanupDelaySecs.load()) : Seconds(0); if (overlapMetadata) { - const auto openCursorsIds = - CursorManager::get(_serviceContext)->getCursorIdsForNamespace(_nss); - LOGV2_INFO_OPTIONS( - 7179200, - {logv2::LogComponent::kShardingRangeDeleter}, - "Range deletion will be scheduled after all possibly dependent queries finish", - "namespace"_attr = _nss, - "range"_attr = range.toString(), - "cursorsDirectlyReferringTheNamespace"_attr = openCursorsIds); + LOGV2_OPTIONS(21989, + {logv2::LogComponent::kShardingMigration}, + "Deletion of {namespace} range {range} will be scheduled after all possibly " + "dependent queries finish", + "Deletion of the collection's specified range will be scheduled after all " + "possibly dependent queries finish", + "namespace"_attr = _nss.ns(), + "range"_attr = redact(range.toString())); ++overlapMetadata->numContingentRangeDeletionTasks; // Schedule the range for deletion once the overlapping metadata object is destroyed // (meaning no more queries can be using the range) and obtain a future which will be @@ -375,6 +373,12 @@ SharedSemiFuture<void> MetadataManager::_submitRangeForDeletion( const ChunkRange& range, const UUID& migrationId, Seconds delayForActiveQueriesOnSecondariesToComplete) { + + int maxToDelete = rangeDeleterBatchSize.load(); + if (maxToDelete <= 0) { + maxToDelete = kRangeDeleterBatchSizeDefault; + } + auto cleanupComplete = removeDocumentsInRange(_executor, std::move(waitForActiveQueriesToComplete), @@ -383,6 +387,7 @@ SharedSemiFuture<void> MetadataManager::_submitRangeForDeletion( _metadata.back()->metadata->getKeyPattern().getOwned(), range, migrationId, + maxToDelete, delayForActiveQueriesOnSecondariesToComplete); _rangesScheduledForDeletion.emplace_front(range, cleanupComplete); @@ -390,25 +395,11 @@ SharedSemiFuture<void> MetadataManager::_submitRangeForDeletion( // from the _rangesScheduledForDeletion. std::list iterators are never invalidated, which // allows us to save the iterator pointing to the newly added element for use later when // deleting it. - cleanupComplete.thenRunOn(_executor).getAsync([self = shared_from_this(), - it = _rangesScheduledForDeletion.begin(), - range = range, - migrationId = migrationId](Status s) { - stdx::lock_guard<Latch> lg(self->_managerLock); - self->_rangesScheduledForDeletion.erase(it); - if (s.code() == ErrorCodes::IndexNotFound) { - // We cannot complete this range deletion right now because we do not have an index - // built on the shard key. This situation is expected for a hashed shard key and - // recoverable for a range shard key. This index may be rebuilt in the future, so - // reschedule the task at the end of the queue. - auto _ = self->_submitRangeForDeletion(lg, - SemiFuture<void>::makeReady(), - range, - migrationId, - Seconds(orphanCleanupDelaySecs.load())); - } - }); - + cleanupComplete.thenRunOn(_executor).getAsync( + [self = shared_from_this(), it = _rangesScheduledForDeletion.begin()](Status s) { + stdx::lock_guard<Latch> lg(self->_managerLock); + self->_rangesScheduledForDeletion.erase(it); + }); return cleanupComplete; } |
