summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Judd <ben.judd@10gen.com>2018-06-04 13:43:50 -0400
committerBen Judd <ben.judd@10gen.com>2018-06-11 09:56:44 -0400
commitcd49c442dcc0fc3fd1222e678706d396b9ef485c (patch)
tree12f112c6d5280ab530277935d527b315b4ee4eb2
parentb07dea7210fbe8ee16669ae0d2f54f929201ec2d (diff)
downloadmongo-cd49c442dcc0fc3fd1222e678706d396b9ef485c.tar.gz
SERVER-30388 Validating ttlMonitorSleepSecs to avoid busy wait with non-positive values
-rw-r--r--jstests/noPassthrough/ttlMonitorSleepSecs_parameter.js18
-rw-r--r--src/mongo/db/ttl.cpp7
2 files changed, 24 insertions, 1 deletions
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<Counter64> 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: