From cd49c442dcc0fc3fd1222e678706d396b9ef485c Mon Sep 17 00:00:00 2001 From: Ben Judd Date: Mon, 4 Jun 2018 13:43:50 -0400 Subject: SERVER-30388 Validating ttlMonitorSleepSecs to avoid busy wait with non-positive values --- jstests/noPassthrough/ttlMonitorSleepSecs_parameter.js | 18 ++++++++++++++++++ src/mongo/db/ttl.cpp | 7 ++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 jstests/noPassthrough/ttlMonitorSleepSecs_parameter.js diff --git a/jstests/noPassthrough/ttlMonitorSleepSecs_parameter.js b/jstests/noPassthrough/ttlMonitorSleepSecs_parameter.js new file mode 100644 index 00000000000..93eaa49500e --- /dev/null +++ b/jstests/noPassthrough/ttlMonitorSleepSecs_parameter.js @@ -0,0 +1,18 @@ +// Tests the ttlMonitorSleepSecs parameter + +(function() { + 'use strict'; + + load('jstests/noPassthrough/libs/server_parameter_helpers.js'); + + testNumericServerParameter('ttlMonitorSleepSecs', + true, // is Startup Param + false, // is runtime param + 60, // default value + 30, // valid, non-default value + true, // has lower bound + 0, // out of bound value (below lower bound) + false, // has upper bound + 'unused' // out of bounds value (above upper bound) + ); +})(); diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp index ee50be543fd..fa606a7b526 100644 --- a/src/mongo/db/ttl.cpp +++ b/src/mongo/db/ttl.cpp @@ -70,7 +70,12 @@ ServerStatusMetricField ttlDeletedDocumentsDisplay("ttl.deletedDocume &ttlDeletedDocuments); MONGO_EXPORT_SERVER_PARAMETER(ttlMonitorEnabled, bool, true); -MONGO_EXPORT_SERVER_PARAMETER(ttlMonitorSleepSecs, int, 60); // used for testing +MONGO_EXPORT_SERVER_PARAMETER(ttlMonitorSleepSecs, int, 60) + ->withValidator([](const int& newVal) { + if (newVal <= 0) + return Status(ErrorCodes::BadValue, "ttlMonitorSleepSecs must be strictly positive"); + return Status::OK(); + }); // used for testing class TTLMonitor : public BackgroundJob { public: -- cgit v1.2.1