summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2022-08-29 19:42:58 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-11 18:36:57 +0000
commit3bf0d522db3017a344e5f093706539e97659897b (patch)
treebb96225582c0598763d532a811d2618ee9f06ebc /jstests/noPassthrough
parentaab9685c531bed030dc8bba914d695d7c66fc08b (diff)
downloadmongo-3bf0d522db3017a344e5f093706539e97659897b.tar.gz
SERVER-68477 createIndexes overwrites NaN expireAfterSeconds before starting index build
(cherry picked from commit 58796facf40c99ddf8bb537adf563dc43aa0a863)
Diffstat (limited to 'jstests/noPassthrough')
-rw-r--r--jstests/noPassthrough/ttl_expire_nan.js29
-rw-r--r--jstests/noPassthrough/ttl_expire_nan_warning_on_startup.js12
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