summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/internal_transactions_index_setFCV.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/multiVersion/internal_transactions_index_setFCV.js')
-rw-r--r--jstests/multiVersion/internal_transactions_index_setFCV.js76
1 files changed, 67 insertions, 9 deletions
diff --git a/jstests/multiVersion/internal_transactions_index_setFCV.js b/jstests/multiVersion/internal_transactions_index_setFCV.js
index 712e8249a54..a3ce2ead44a 100644
--- a/jstests/multiVersion/internal_transactions_index_setFCV.js
+++ b/jstests/multiVersion/internal_transactions_index_setFCV.js
@@ -41,7 +41,8 @@ function assertPartialIndexDoesNotExist(node) {
* Verifies the partial index is dropped/created on FCV transitions and retryable writes work in all
* FCVs.
*/
-function runTest(setFCVConn, modifyIndexConns, verifyIndexConns, rst) {
+function runTest(
+ setFCVConn, modifyIndexConns, verifyIndexConns, rst, alwaysCreateFeatureFlagEnabled) {
// Start at latest FCV which should have the index.
assert.commandWorked(setFCVConn.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
verifyIndexConns.forEach(conn => {
@@ -54,8 +55,12 @@ function runTest(setFCVConn, modifyIndexConns, verifyIndexConns, rst) {
assertPartialIndexDoesNotExist(conn);
});
+ assert.commandWorked(setFCVConn.getDB("foo").runCommand(
+ {insert: "bar", documents: [{x: 1}], lsid: {id: UUID()}, txnNumber: NumberLong(11)}));
+
if (rst) {
- // On step up to primary the index should not be created.
+ // On step up to primary the index should not be created. Note this tests the empty
+ // collection case when alwaysCreateFeatureFlagEnabled is true.
let primary = rst.getPrimary();
// Clear the collection so we'd try to create the index.
@@ -69,8 +74,21 @@ function runTest(setFCVConn, modifyIndexConns, verifyIndexConns, rst) {
rst.awaitReplication();
verifyIndexConns.forEach(conn => {
reconnect(conn);
- assertPartialIndexDoesNotExist(conn);
+ if (alwaysCreateFeatureFlagEnabled) {
+ assertPartialIndexExists(conn);
+ } else {
+ assertPartialIndexDoesNotExist(conn);
+ }
});
+
+ if (alwaysCreateFeatureFlagEnabled) {
+ // The test expects no index after this block, so remove it.
+ modifyIndexConns.forEach(conn => {
+ assert.commandWorked(
+ conn.getCollection("config.transactions").dropIndex("parent_lsid"));
+ });
+ }
+ rst.awaitReplication();
}
assert.commandWorked(setFCVConn.getDB("foo").runCommand(
@@ -93,11 +111,15 @@ function runTest(setFCVConn, modifyIndexConns, verifyIndexConns, rst) {
});
if (rst) {
- // On step up to primary the index should not be created.
+ // On step up to primary the index should not be created. Note this tests the non-empty
+ // collection case when alwaysCreateFeatureFlagEnabled is true.
let primary = rst.getPrimary();
- // Clear the collection so we'd try to create the index.
- assert.commandWorked(primary.getDB("config").transactions.remove({}));
+ // Clear the collection so we'd try to create the index. Skip if the always create index
+ // feature flag is on because we'd try to create the index anyway.
+ if (!alwaysCreateFeatureFlagEnabled) {
+ assert.commandWorked(primary.getDB("config").transactions.remove({}));
+ }
assert.commandWorked(
primary.adminCommand({replSetStepDown: ReplSetTest.kForeverSecs, force: true}));
assert.commandWorked(primary.adminCommand({replSetFreeze: 0}));
@@ -107,8 +129,21 @@ function runTest(setFCVConn, modifyIndexConns, verifyIndexConns, rst) {
rst.awaitReplication();
verifyIndexConns.forEach(conn => {
reconnect(conn);
- assertPartialIndexDoesNotExist(conn);
+ if (alwaysCreateFeatureFlagEnabled) {
+ assertPartialIndexExists(conn);
+ } else {
+ assertPartialIndexDoesNotExist(conn);
+ }
});
+
+ if (alwaysCreateFeatureFlagEnabled) {
+ // The test expects no index after this block, so remove it.
+ modifyIndexConns.forEach(conn => {
+ assert.commandWorked(
+ conn.getCollection("config.transactions").dropIndex("parent_lsid"));
+ });
+ }
+ rst.awaitReplication();
}
assert.commandWorked(setFCVConn.getDB("foo").runCommand(
@@ -124,8 +159,11 @@ function runTest(setFCVConn, modifyIndexConns, verifyIndexConns, rst) {
// On step up to primary the index should be created.
let primary = rst.getPrimary();
- // Clear the collection so we'll try to create the index.
- assert.commandWorked(primary.getDB("config").transactions.remove({}));
+ // Clear the collection so we'd try to create the index. Skip if the always create index
+ // feature flag is on because we'd try to create the index anyway.
+ if (!alwaysCreateFeatureFlagEnabled) {
+ assert.commandWorked(primary.getDB("config").transactions.remove({}));
+ }
assert.commandWorked(
primary.adminCommand({replSetStepDown: ReplSetTest.kForeverSecs, force: true}));
assert.commandWorked(primary.adminCommand({replSetFreeze: 0}));
@@ -193,6 +231,26 @@ function runTest(setFCVConn, modifyIndexConns, verifyIndexConns, rst) {
}
{
+ // Enabling featureFlagAlwaysCreateConfigTransactionsPartialIndexOnStepUp should not lead to
+ // creating the index if the internal transactions feature flag is not enabled.
+ const featureFlagRst = new ReplSetTest({
+ nodes: 2,
+ nodeOptions:
+ {setParameter: "featureFlagAlwaysCreateConfigTransactionsPartialIndexOnStepUp=true"}
+ });
+ featureFlagRst.startSet();
+ featureFlagRst.initiate();
+ // Note setFCV always waits for majority write concern so in a two node cluster secondaries will
+ // always have replicated the setFCV writes.
+ runTest(featureFlagRst.getPrimary(),
+ [featureFlagRst.getPrimary()],
+ [featureFlagRst.getPrimary(), featureFlagRst.getSecondary()],
+ featureFlagRst,
+ true /* alwaysCreateFeatureFlagEnabled */);
+ featureFlagRst.stopSet();
+}
+
+{
const conn = MongoRunner.runMongod();
const configTxnsCollection = conn.getCollection("config.transactions");