summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2013-10-15 13:52:56 -0400
committerDan Pasette <dan@mongodb.com>2013-12-19 20:35:55 -0500
commit294234af4ec017aed633fe3292d1d3669cbb26a7 (patch)
treebd3dd6d0316660fc7583752e5f7fd6b856cbae96
parent8bc5cef78b701ee3165b3f97f86f7b97ca49e2b4 (diff)
downloadmongo-294234af4ec017aed633fe3292d1d3669cbb26a7.tar.gz
SERVER-11194 ignore non-numeric expiresAfterSeconds on TTL indexes
-rw-r--r--jstests/slowNightly/ttl1.js38
-rw-r--r--src/mongo/db/ttl.cpp6
2 files changed, 37 insertions, 7 deletions
diff --git a/jstests/slowNightly/ttl1.js b/jstests/slowNightly/ttl1.js
index f795d8bc0ff..50dae5670e3 100644
--- a/jstests/slowNightly/ttl1.js
+++ b/jstests/slowNightly/ttl1.js
@@ -1,21 +1,33 @@
/**
* Part 1: Simple test of TTL. Create a new collection with 24 docs, with timestamps at one hour
* intervals, from now-minus-23 hours ago until now. Also add some docs with non-date
- * values. Then create a TTL index that expires all docs older than ~5.5 hours (20000
- * seconds). Wait 70 seconds (TTL monitor runs every 60) and check that 18 docs deleted.
- * Part 2: Add a second TTL index on an identical field. The second index expires docs older than
+ * values. Then create a TTL index that expires all docs older than a string. Wait 70
+ * seconds (TTL monitor runs every 60) and check that no documents were deleted.
+ * Part 2: Add a second TTL index that expires all docs older than ~5.5 hours (20000
+ * seconds). Wait 70 seconds and check that 18 docs deleted.
+ * Part 3: Add a third TTL index on an identical field. The second index expires docs older than
* ~2.8 hours (10000 seconds). Wait 70 seconds and check that 3 more docs deleted.
*/
+assertEntryMatches = function(array, regex) {
+ var found = false;
+ for (i=0; i<array.length; i++) {
+ if (regex.test(array[i])) {
+ found = true;
+ }
+ }
+ assert(found,
+ "The regex: " + regex + " did not match any entries in the array: " + array.join('\n'));
+}
// Part 1
var t = db.ttl1;
t.drop();
var now = (new Date()).getTime();
-for ( i=0; i<24; i++ ){
- var past = new Date( now - ( 3600 * 1000 * i ) );
- t.insert( { x : past , y : past } );
+for (i=0; i<24; i++) {
+ var past = new Date(now - (3600 * 1000 * i));
+ t.insert({x: past, y: past, z: past});
}
t.insert( { a : 1 } ) //no x value
t.insert( { x: null } ) //non-date value
@@ -27,6 +39,18 @@ db.getLastError();
assert.eq( 30 , t.count() );
+t.ensureIndex( { z : 1 } , { expireAfterSeconds : "20000" } );
+
+sleep(70 * 1000);
+
+assert.eq(t.count(), 30);
+
+var loggedWarning = false;
+var log = db.adminCommand({getLog: "global"}).log;
+var msg = RegExp("ttl indexes require the expireAfterSeconds" +
+ " field to be numeric but received a type of:");
+assertEntryMatches(log, msg);
+// Part 2
t.ensureIndex( { x : 1 } , { expireAfterSeconds : 20000 } );
assert.soon(
@@ -41,7 +65,7 @@ assert.eq( 12 , t.count() );
assert.lte( 18, db.serverStatus().metrics.ttl.deletedDocuments );
assert.lte( 1, db.serverStatus().metrics.ttl.passes );
-// Part 2
+// Part 3
t.ensureIndex( { y : 1 } , { expireAfterSeconds : 10000 } );
assert.soon(
diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp
index 66c0ee7ee7f..55531724110 100644
--- a/src/mongo/db/ttl.cpp
+++ b/src/mongo/db/ttl.cpp
@@ -81,6 +81,12 @@ namespace mongo {
error() << "key for ttl index can only have 1 field" << endl;
continue;
}
+ if (!idx[secondsExpireField].isNumber()) {
+ log() << "ttl indexes require the " << secondsExpireField << " field to be "
+ << "numeric but received a type of: "
+ << typeName(idx[secondsExpireField].type());
+ continue;
+ }
BSONObj query;
{