diff options
Diffstat (limited to 'jstests/noPassthrough')
-rw-r--r-- | jstests/noPassthrough/ttl_expire_nan.js | 29 | ||||
-rw-r--r-- | jstests/noPassthrough/ttl_expire_nan_warning_on_startup.js | 12 |
2 files changed, 39 insertions, 2 deletions
diff --git a/jstests/noPassthrough/ttl_expire_nan.js b/jstests/noPassthrough/ttl_expire_nan.js index 6ab095192c4..8e07b9a1c2b 100644 --- a/jstests/noPassthrough/ttl_expire_nan.js +++ b/jstests/noPassthrough/ttl_expire_nan.js @@ -11,6 +11,7 @@ (function() { 'use strict'; +load("jstests/libs/fail_point_util.js"); load('jstests/noPassthrough/libs/index_build.js'); const rst = new ReplSetTest({ @@ -26,7 +27,16 @@ let primary = rst.getPrimary(); const db = primary.getDB('test'); const coll = db.t; -assert.commandWorked(coll.createIndex({t: 1}, {expireAfterSeconds: NaN})); +// The test cases here revolve around having a TTL index in the catalog with a NaN +// 'expireAfterSeconds'. The current createIndexes behavior will overwrite NaN with int32::max +// unless we use a fail point. +const fp = configureFailPoint(primary, 'skipTTLIndexNaNExpireAfterSecondsValidation'); +try { + assert.commandWorked(coll.createIndex({t: 1}, {expireAfterSeconds: NaN})); +} finally { + fp.off(); +} + assert.commandWorked(coll.insert({_id: 0, t: ISODate()})); // Wait for "TTL indexes require the expire field to be numeric, skipping TTL job" log message. @@ -89,5 +99,22 @@ assert.eq(collModOplogEntries.length, 'TTL index with NaN expireAfterSeconds was not fixed using collMod during step-up: ' + tojson(rst.findOplog(primary, {op: {$ne: 'n'}}, /*limit=*/10).toArray())); +// Confirm that createIndexes will overwrite a NaN 'expireAfterSeconds' in a TTL index before saving +// it to the catalog and replicating it downstream. +const coll2 = db.w; +assert.commandWorked(coll2.createIndex({t: 1}, {expireAfterSeconds: NaN})); +assert.commandWorked(coll2.insert({_id: 0, t: ISODate()})); + +// TTL index should be replicated to the secondary with a non-NaN 'expireAfterSeconds'. +checkLog.containsJson(secondary, 20384, { + namespace: coll2.getFullName(), + properties: (spec) => { + jsTestLog('TTL index on secondary (with overwritten NaN expireAfterSeconds): ' + + tojson(spec)); + return spec.hasOwnProperty('expireAfterSeconds') && !isNaN(spec.expireAfterSeconds) && + spec.expireAfterSeconds === newNodeSpec.expireAfterSeconds; + } +}); + rst.stopSet(); })(); diff --git a/jstests/noPassthrough/ttl_expire_nan_warning_on_startup.js b/jstests/noPassthrough/ttl_expire_nan_warning_on_startup.js index d4b1d41f1fe..a285adc69a5 100644 --- a/jstests/noPassthrough/ttl_expire_nan_warning_on_startup.js +++ b/jstests/noPassthrough/ttl_expire_nan_warning_on_startup.js @@ -10,6 +10,7 @@ (function() { 'use strict'; +load("jstests/libs/fail_point_util.js"); load('jstests/noPassthrough/libs/index_build.js'); const rst = new ReplSetTest({nodes: [{}, {rsConfig: {votes: 0, priority: 0}}]}); @@ -20,7 +21,16 @@ let primary = rst.getPrimary(); const db = primary.getDB('test'); const coll = db.t; -assert.commandWorked(coll.createIndex({t: 1}, {expireAfterSeconds: NaN})); +// The test cases here revolve around having a TTL index in the catalog with a NaN +// 'expireAfterSeconds'. The current createIndexes behavior will overwrite NaN with int32::max +// unless we use a fail point. +const fp = configureFailPoint(primary, 'skipTTLIndexNaNExpireAfterSecondsValidation'); +try { + assert.commandWorked(coll.createIndex({t: 1}, {expireAfterSeconds: NaN})); +} finally { + fp.off(); +} + assert.commandWorked(coll.insert({_id: 0, t: ISODate()})); // Force checkpoint in storage engine to ensure index is part of the catalog in |