summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Pulo <kevin.pulo@mongodb.com>2018-11-14 03:53:28 +0000
committerKevin Pulo <kevin.pulo@mongodb.com>2018-12-05 06:08:45 +0000
commit7eee9975a4732419df7ef30d4db14ccf2994c42a (patch)
tree62479ecf8e9d4cc0ac277672cb47c0f03fb95653
parent9785e3d698dd305e1a486280481183eec83e92d6 (diff)
downloadmongo-7eee9975a4732419df7ef30d4db14ccf2994c42a.tar.gz
SERVER-37616 tuneable range deleter batch size
(cherry picked from commit 9bd063b1409d7be2e164911a4d90f1aba5864715)
-rw-r--r--src/mongo/db/s/collection_range_deleter.cpp15
-rw-r--r--src/mongo/db/s/collection_range_deleter.h10
-rw-r--r--src/mongo/db/s/metadata_manager.cpp4
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 3b573395c57..95ae8282374 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<Date_t> CollectionRangeDeleter::cleanUpNextRange(
int maxToDelete,
CollectionRangeDeleter* forTestOnly) {
+ if (maxToDelete <= 0) {
+ maxToDelete = rangeDeleterBatchSize.load();
+ if (maxToDelete <= 0) {
+ maxToDelete = std::max(int(internalQueryExecYieldIterations.load()), 1);
+ }
+ }
+
StatusWith<int> wrote = 0;
auto range = boost::optional<ChunkRange>(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<Date_t> 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 bf47163ee29..e1771c7b70b 100644
--- a/src/mongo/db/s/metadata_manager.cpp
+++ b/src/mongo/db/s/metadata_manager.cpp
@@ -149,11 +149,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);
}