From 320e3b4aca116b1384a94057a0632d759d8f6cef Mon Sep 17 00:00:00 2001 From: Kevin Pulo Date: Wed, 14 Nov 2018 03:53:28 +0000 Subject: SERVER-37616 tuneable range deleter batch size (cherry picked from commit 9bd063b1409d7be2e164911a4d90f1aba5864715) --- src/mongo/db/s/collection_range_deleter.cpp | 15 +++++++++++++++ src/mongo/db/s/collection_range_deleter.h | 10 +++++++++- src/mongo/db/s/metadata_manager.cpp | 4 +--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/mongo/db/s/collection_range_deleter.cpp b/src/mongo/db/s/collection_range_deleter.cpp index 0d0d6021437..ed7c303a041 100644 --- a/src/mongo/db/s/collection_range_deleter.cpp +++ b/src/mongo/db/s/collection_range_deleter.cpp @@ -62,6 +62,14 @@ namespace mongo { +MONGO_EXPORT_SERVER_PARAMETER(rangeDeleterBatchSize, int, 0) + ->withValidator([](const int& newVal) { + if (newVal < 0) { + return Status(ErrorCodes::BadValue, "rangeDeleterBatchSize must not be negative"); + } + return Status::OK(); + }); + MONGO_EXPORT_SERVER_PARAMETER(rangeDeleterBatchDelayMS, int, 20) ->withValidator([](const int& newVal) { if (newVal < 0) { @@ -108,6 +116,13 @@ boost::optional CollectionRangeDeleter::cleanUpNextRange( int maxToDelete, CollectionRangeDeleter* forTestOnly) { + if (maxToDelete <= 0) { + maxToDelete = rangeDeleterBatchSize.load(); + if (maxToDelete <= 0) { + maxToDelete = std::max(int(internalQueryExecYieldIterations.load()), 1); + } + } + StatusWith wrote = 0; auto range = boost::optional(boost::none); diff --git a/src/mongo/db/s/collection_range_deleter.h b/src/mongo/db/s/collection_range_deleter.h index d6631cdcf26..4949c1febde 100644 --- a/src/mongo/db/s/collection_range_deleter.h +++ b/src/mongo/db/s/collection_range_deleter.h @@ -44,6 +44,12 @@ class BSONObj; class Collection; class OperationContext; +// The maximum number of documents to delete in a single batch during range deletion. +// secondaryThrottle and rangeDeleterBatchDelayMS apply between each batch. +// Must be positive or 0 (the default), which means to use the value of +// internalQueryExecYieldIterations (or 1 if that's negative or zero). +extern AtomicInt32 rangeDeleterBatchSize; + // After completing a batch of document deletions, the time in millis to wait before commencing the // next batch of deletions. extern AtomicInt32 rangeDeleterBatchDelayMS; @@ -166,13 +172,15 @@ public: * If it should be scheduled to run again because there might be more documents to delete, * returns the time to begin, or boost::none otherwise. * + * Negative (or zero) value for 'maxToDelete' indicates some canonical default should be used. + * * Argument 'forTestOnly' is used in unit tests that exercise the CollectionRangeDeleter class, * so that they do not need to set up CollectionShardingState and MetadataManager objects. */ static boost::optional cleanUpNextRange(OperationContext*, NamespaceString const& nss, OID const& epoch, - int maxToDelete, + int maxToDelete = 0, CollectionRangeDeleter* forTestOnly = nullptr); private: diff --git a/src/mongo/db/s/metadata_manager.cpp b/src/mongo/db/s/metadata_manager.cpp index 54fc79ca1b4..bcfab6364e6 100644 --- a/src/mongo/db/s/metadata_manager.cpp +++ b/src/mongo/db/s/metadata_manager.cpp @@ -136,11 +136,9 @@ void scheduleCleanup(executor::TaskExecutor* executor, auto uniqueOpCtx = Client::getCurrent()->makeOperationContext(); auto opCtx = uniqueOpCtx.get(); - const int maxToDelete = std::max(int(internalQueryExecYieldIterations.load()), 1); - MONGO_FAIL_POINT_PAUSE_WHILE_SET(suspendRangeDeletion); - auto next = CollectionRangeDeleter::cleanUpNextRange(opCtx, nss, epoch, maxToDelete); + auto next = CollectionRangeDeleter::cleanUpNextRange(opCtx, nss, epoch); if (next) { scheduleCleanup(executor, std::move(nss), std::move(epoch), *next); } -- cgit v1.2.1