diff options
-rw-r--r-- | jstests/libs/read_write_concern_defaults_propagation_common.js | 6 | ||||
-rw-r--r-- | jstests/libs/write_concern_util.js | 13 | ||||
-rw-r--r-- | jstests/noPassthrough/read_write_concern_defaults_metrics.js | 19 | ||||
-rw-r--r-- | jstests/noPassthrough/server_write_concern_metrics.js | 23 | ||||
-rw-r--r-- | jstests/replsets/get_default_write_concern_majority.js | 9 | ||||
-rw-r--r-- | jstests/replsets/reconfig_fails_no_cwwc_set.js | 55 | ||||
-rw-r--r-- | jstests/sharding/cannot_unset_cluster_wide_write_concern_once_set.js | 6 | ||||
-rw-r--r-- | jstests/sharding/read_write_concern_defaults_commands_api.js | 107 | ||||
-rw-r--r-- | src/mongo/db/read_write_concern_defaults.cpp | 20 | ||||
-rw-r--r-- | src/mongo/db/read_write_concern_defaults_test.cpp | 279 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_server_parameters.idl | 8 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/write_concern.cpp | 13 | ||||
-rw-r--r-- | src/mongo/s/commands/strategy.cpp | 12 |
14 files changed, 138 insertions, 436 deletions
diff --git a/jstests/libs/read_write_concern_defaults_propagation_common.js b/jstests/libs/read_write_concern_defaults_propagation_common.js index b992593e9fc..8bf732466b0 100644 --- a/jstests/libs/read_write_concern_defaults_propagation_common.js +++ b/jstests/libs/read_write_concern_defaults_propagation_common.js @@ -1,8 +1,7 @@ var ReadWriteConcernDefaultsPropagation = (function() { "use strict"; - load("jstests/libs/write_concern_util.js"); // For isDefaultWriteConcernMajorityFlagEnabled. - load('jstests/replsets/rslib.js'); // For isDefaultReadConcernLocalFlagEnabled. + load('jstests/replsets/rslib.js'); // For isDefaultReadConcernLocalFlagEnabled. const kDefaultReadConcernField = "defaultReadConcern"; const kDefaultWriteConcernField = "defaultWriteConcern"; @@ -140,8 +139,7 @@ var ReadWriteConcernDefaultsPropagation = (function() { // Note localUpdateWallClockTime is generated by the in-memory cache, so it will be // present even if there are no defaults. const unexpectedFields = kDefaultRWCFields.concat(kExtraSetFields).filter(field => { - return (!isDefaultWriteConcernMajorityFlagEnabled(checkConn) || - field !== kDefaultWriteConcernField) && + return (field !== kDefaultWriteConcernField) && (!isDefaultReadConcernLocalFlagEnabled(checkConn) || field !== kDefaultReadConcernField); }); diff --git a/jstests/libs/write_concern_util.js b/jstests/libs/write_concern_util.js index 80c6593507a..fff2517c754 100644 --- a/jstests/libs/write_concern_util.js +++ b/jstests/libs/write_concern_util.js @@ -154,17 +154,4 @@ function runWriteConcernRetryabilityTest(priConn, secConn, cmd, kNodes, dbName, checkWriteConcernTimedOut(testDB2.runCommand(cmd)); restartServerReplication(secConn); -} - -// Check if featureFlagDefaultWriteConcernMajority is enabled. -function isDefaultWriteConcernMajorityFlagEnabled(conn) { - let res = conn.adminCommand({getParameter: 1, featureFlagDefaultWriteConcernMajority: 1}); - if (!res.ok) { - // Running with old version which doesn't have the flag. - if (res.errmsg == "no option found to get") - return false; - assert(false); - } - - return res.featureFlagDefaultWriteConcernMajority.value; }
\ No newline at end of file diff --git a/jstests/noPassthrough/read_write_concern_defaults_metrics.js b/jstests/noPassthrough/read_write_concern_defaults_metrics.js index 7346b2af47a..5be8b7a98a4 100644 --- a/jstests/noPassthrough/read_write_concern_defaults_metrics.js +++ b/jstests/noPassthrough/read_write_concern_defaults_metrics.js @@ -8,8 +8,7 @@ "use strict"; load("jstests/libs/ftdc.js"); -load("jstests/libs/write_concern_util.js"); // For isDefaultWriteConcernMajorityFlagEnabled. -load('jstests/replsets/rslib.js'); // For isDefaultReadConcernLocalFlagEnabled. +load('jstests/replsets/rslib.js'); // For isDefaultReadConcernLocalFlagEnabled. // Verifies the transaction server status response has the fields that we expect. function verifyServerStatus(conn, @@ -42,18 +41,14 @@ function verifyServerStatus(conn, assert.eq(undefined, defaultsRes.defaultReadConcern, tojson(defaultsRes)); } - if (isDefaultWriteConcernMajorityFlagEnabled(conn)) { - assert.hasFields(defaultsRes, ["defaultWriteConcernSource"]); - if (!expectedWC) { - assert.eq("implicit", defaultsRes.defaultWriteConcernSource, tojson(defaultsRes)); - if (isImplicitDefaultWCMajority) { - expectedWC = {w: "majority", wtimeout: 0}; - } - } else { - assert.eq("global", defaultsRes.defaultWriteConcernSource, tojson(defaultsRes)); + assert.hasFields(defaultsRes, ["defaultWriteConcernSource"]); + if (!expectedWC) { + assert.eq("implicit", defaultsRes.defaultWriteConcernSource, tojson(defaultsRes)); + if (isImplicitDefaultWCMajority) { + expectedWC = {w: "majority", wtimeout: 0}; } } else { - assert.eq(undefined, defaultsRes.defaultWriteConcernSource); + assert.eq("global", defaultsRes.defaultWriteConcernSource, tojson(defaultsRes)); } if (expectedWC) { diff --git a/jstests/noPassthrough/server_write_concern_metrics.js b/jstests/noPassthrough/server_write_concern_metrics.js index 82b2f150762..61b18ff1b1f 100644 --- a/jstests/noPassthrough/server_write_concern_metrics.js +++ b/jstests/noPassthrough/server_write_concern_metrics.js @@ -7,8 +7,6 @@ (function() { "use strict"; -load("jstests/libs/write_concern_util.js"); // For isDefaultWriteConcernMajorityFlagEnabled. - // Verifies that the server status response has the fields that we expect. function verifyServerStatusFields(serverStatusResponse) { assert(serverStatusResponse.hasOwnProperty("opWriteConcernCounters"), @@ -111,7 +109,6 @@ function resetCollection(setupCommand) { function testWriteConcernMetrics(cmd, opName, inc, isPSASet, setupCommand) { initializeReplicaSet(isPSASet); - const isDefaultWCMajorityFlagEnabled = isDefaultWriteConcernMajorityFlagEnabled(primary); // Run command with no writeConcern and no CWWC set. resetCollection(setupCommand); @@ -119,17 +116,15 @@ function testWriteConcernMetrics(cmd, opName, inc, isPSASet, setupCommand) { verifyServerStatusFields(serverStatus); assert.commandWorked(testDB.runCommand(cmd)); let newStatus = assert.commandWorked(testDB.adminCommand({serverStatus: 1})); - verifyServerStatusChange( - serverStatus.opWriteConcernCounters, - newStatus.opWriteConcernCounters, - [ - opName + - (isDefaultWCMajorityFlagEnabled ? (isPSASet ? ".noneInfo.implicitDefault.wnum.1" - : ".noneInfo.implicitDefault.wmajority") - : ".noneInfo.implicitDefault.wnum.1"), - opName + ".none" - ], - inc); + verifyServerStatusChange(serverStatus.opWriteConcernCounters, + newStatus.opWriteConcernCounters, + [ + opName + + (isPSASet ? ".noneInfo.implicitDefault.wnum.1" + : ".noneInfo.implicitDefault.wmajority"), + opName + ".none" + ], + inc); // Run command with no writeConcern with CWWC set to majority. resetCollection(setupCommand); diff --git a/jstests/replsets/get_default_write_concern_majority.js b/jstests/replsets/get_default_write_concern_majority.js index 619b4d9ccb8..925c8f980aa 100644 --- a/jstests/replsets/get_default_write_concern_majority.js +++ b/jstests/replsets/get_default_write_concern_majority.js @@ -6,7 +6,6 @@ */ (function() { 'use strict'; -load("jstests/libs/write_concern_util.js"); // For isDefaultWriteConcernMajorityFlagEnabled. jsTestLog("Test PSS configuration will set defaultWC to majority."); let replTest = new ReplSetTest({name: 'default_wc_majority', nodes: 3}); @@ -15,12 +14,8 @@ replTest.initiate(); let primary = replTest.getPrimary(); let res = assert.commandWorked(primary.adminCommand({getDefaultRWConcern: 1})); -if (isDefaultWriteConcernMajorityFlagEnabled(primary)) { - assert(res.hasOwnProperty("defaultWriteConcern")); - assert.eq({w: "majority", wtimeout: 0}, res.defaultWriteConcern, tojson(res)); -} else { - assert(!res.hasOwnProperty("defaultWriteConcern")); -} +assert(res.hasOwnProperty("defaultWriteConcern")); +assert.eq({w: "majority", wtimeout: 0}, res.defaultWriteConcern, tojson(res)); replTest.stopSet(); diff --git a/jstests/replsets/reconfig_fails_no_cwwc_set.js b/jstests/replsets/reconfig_fails_no_cwwc_set.js index 6d0f2d71156..976392e62ec 100644 --- a/jstests/replsets/reconfig_fails_no_cwwc_set.js +++ b/jstests/replsets/reconfig_fails_no_cwwc_set.js @@ -6,22 +6,15 @@ (function() { 'use strict'; -load("jstests/libs/write_concern_util.js"); // For 'isDefaultWriteConcernMajorityFlagEnabled()'. - const rst = new ReplSetTest({nodes: 2}); rst.startSet(); rst.initiate(); const primary = rst.getPrimary(); -const featureFlagEnabled = isDefaultWriteConcernMajorityFlagEnabled(primary); let cwwc = primary.adminCommand({getDefaultRWConcern: 1}); -if (featureFlagEnabled) { - assert(cwwc.hasOwnProperty("defaultWriteConcern")); - assert.eq({w: "majority", wtimeout: 0}, cwwc.defaultWriteConcern, tojson(cwwc)); -} else { - assert(!cwwc.hasOwnProperty("defaultWriteConcern")); -} +assert(cwwc.hasOwnProperty("defaultWriteConcern")); +assert.eq({w: "majority", wtimeout: 0}, cwwc.defaultWriteConcern, tojson(cwwc)); jsTestLog("Starting arbiter"); const arbiter = rst.add(); @@ -31,30 +24,26 @@ config.version++; const reconfigErrorMsg = "Reconfig attempted to install a config that would change the implicit default write concern"; -if (featureFlagEnabled) { - // Adding the arbiter would change the implicit default write concern from {w: majority} to - // {w:1}, so we fail the reconfig. - let res = assert.commandFailed(primary.adminCommand({replSetReconfig: config})); - assert.eq(res.code, ErrorCodes.NewReplicaSetConfigurationIncompatible); - assert(res.errmsg.includes(reconfigErrorMsg)); - - // A force reconfig should also fail. - res = assert.commandFailed(primary.adminCommand({replSetReconfig: config, force: true})); - assert.eq(res.code, ErrorCodes.NewReplicaSetConfigurationIncompatible); - assert(res.errmsg.includes(reconfigErrorMsg)); - - assert.commandWorked(primary.adminCommand( - {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); - - // After setting the cluster-wide write concern, the same reconfig command should succeed. - assert.commandWorked(primary.adminCommand({replSetReconfig: config})); - - cwwc = primary.adminCommand({getDefaultRWConcern: 1}); - assert(cwwc.hasOwnProperty("defaultWriteConcern")); - assert.eq({w: 1, wtimeout: 0}, cwwc.defaultWriteConcern, tojson(cwwc)); -} else { - assert.commandWorked(primary.adminCommand({replSetReconfig: config})); -} +// Adding the arbiter would change the implicit default write concern from {w: majority} to +// {w:1}, so we fail the reconfig. +let res = assert.commandFailed(primary.adminCommand({replSetReconfig: config})); +assert.eq(res.code, ErrorCodes.NewReplicaSetConfigurationIncompatible); +assert(res.errmsg.includes(reconfigErrorMsg)); + +// A force reconfig should also fail. +res = assert.commandFailed(primary.adminCommand({replSetReconfig: config, force: true})); +assert.eq(res.code, ErrorCodes.NewReplicaSetConfigurationIncompatible); +assert(res.errmsg.includes(reconfigErrorMsg)); + +assert.commandWorked(primary.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + +// After setting the cluster-wide write concern, the same reconfig command should succeed. +assert.commandWorked(primary.adminCommand({replSetReconfig: config})); + +cwwc = primary.adminCommand({getDefaultRWConcern: 1}); +assert(cwwc.hasOwnProperty("defaultWriteConcern")); +assert.eq({w: 1, wtimeout: 0}, cwwc.defaultWriteConcern, tojson(cwwc)); rst.stopSet(); })(); diff --git a/jstests/sharding/cannot_unset_cluster_wide_write_concern_once_set.js b/jstests/sharding/cannot_unset_cluster_wide_write_concern_once_set.js index 336c1a44a69..3f5f12db913 100644 --- a/jstests/sharding/cannot_unset_cluster_wide_write_concern_once_set.js +++ b/jstests/sharding/cannot_unset_cluster_wide_write_concern_once_set.js @@ -5,14 +5,8 @@ */ (function() { "use strict"; -load("jstests/libs/write_concern_util.js"); // For isDefaultWriteConcernMajorityFlagEnabled. function runTest(conn) { - if (!isDefaultWriteConcernMajorityFlagEnabled(conn)) { - jsTestLog("Skipping test because the default WC majority feature flag is disabled"); - return; - } - let expectedDefaultWC = {w: "majority", wtimeout: 0}; let res = conn.adminCommand({getDefaultRWConcern: 1}); assert(res.hasOwnProperty("defaultWriteConcern")); diff --git a/jstests/sharding/read_write_concern_defaults_commands_api.js b/jstests/sharding/read_write_concern_defaults_commands_api.js index f73bfea8652..5a44e1527e1 100644 --- a/jstests/sharding/read_write_concern_defaults_commands_api.js +++ b/jstests/sharding/read_write_concern_defaults_commands_api.js @@ -5,8 +5,7 @@ (function() { "use strict"; -load("jstests/libs/write_concern_util.js"); // For isDefaultWriteConcernMajorityFlagEnabled. -load('jstests/replsets/rslib.js'); // For isDefaultReadConcernLocalFlagEnabled. +load('jstests/replsets/rslib.js'); // For isDefaultReadConcernLocalFlagEnabled. // Asserts a set/get default RWC command response or persisted document contains the expected // fields. Assumes a default read or write concern has been set previously and the response was not @@ -14,7 +13,6 @@ load('jstests/replsets/rslib.js'); // For isDefaultReadConcernLocalFla function verifyFields(res, {expectRC, expectWC, isPersistedDocument}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority) { // These fields are always set once a read or write concern has been set at least once. let expectedFields = ["updateOpTime", "updateWallClockTime", "localUpdateWallClockTime"]; @@ -38,7 +36,7 @@ function verifyFields(res, unexpectedFields.push("defaultWriteConcern"); } - if (isDefaultWCMajorityFlagEnabled && !isPersistedDocument) { + if (!isPersistedDocument) { expectedFields.push("defaultWriteConcernSource"); } else { unexpectedFields.push("defaultWriteConcernSource"); @@ -56,7 +54,7 @@ function verifyFields(res, assert(!res.hasOwnProperty(field), `response unexpectedly had field '${field}', res: ${tojson(res)}`); }); - if (isDefaultWCMajorityFlagEnabled && !isPersistedDocument) { + if (!isPersistedDocument) { if (expectWC) { assert.eq(res.defaultWriteConcernSource, "global", tojson(res)); } else { @@ -94,15 +92,9 @@ function verifyDefaultRWCommandsInvalidInput(conn) { ErrorCodes.BadValue); // Empty write concern is not allowed if write concern has already been set. - const featureEnabled = assert - .commandWorked(conn.adminCommand( - {getParameter: 1, featureFlagDefaultWriteConcernMajority: 1})) - .featureFlagDefaultWriteConcernMajority.value; - if (featureEnabled) { - assert.commandFailedWithCode( - conn.adminCommand({setDefaultRWConcern: 1, defaultWriteConcern: {}}), - ErrorCodes.IllegalOperation); - } + assert.commandFailedWithCode( + conn.adminCommand({setDefaultRWConcern: 1, defaultWriteConcern: {}}), + ErrorCodes.IllegalOperation); // Invalid read concern. assert.commandFailedWithCode(conn.adminCommand({setDefaultRWConcern: 1, defaultReadConcern: 1}), @@ -140,10 +132,7 @@ function verifyDefaultRWCommandsInvalidInput(conn) { } // Verifies the default responses for the default RWC commands and the default persisted state. -function verifyDefaultState(conn, - isDefaultRCLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, - isImplicitDefaultWCMajority) { +function verifyDefaultState(conn, isDefaultRCLocalFlagEnabled, isImplicitDefaultWCMajority) { const res = assert.commandWorked(conn.adminCommand({getDefaultRWConcern: 1})); const inMemoryRes = assert.commandWorked(conn.adminCommand({getDefaultRWConcern: 1, inMemory: true})); @@ -153,10 +142,8 @@ function verifyDefaultState(conn, if (isImplicitDefaultWCMajority) { expectedFields.push("defaultWriteConcern"); } - if (isDefaultWCMajorityFlagEnabled) { - expectedFields.push("defaultWriteConcernSource"); - } + expectedFields.push("defaultWriteConcernSource"); if (isDefaultRCLocalFlagEnabled) { expectedFields.push("defaultReadConcern"); expectedFields.push("defaultReadConcernSource"); @@ -170,19 +157,14 @@ function verifyDefaultState(conn, }); assert.eq(inMemoryRes.inMemory, true, tojson(inMemoryRes)); - if (isDefaultWCMajorityFlagEnabled) { - assert.eq(res.defaultWriteConcernSource, "implicit", tojson(res)); - assert.eq(inMemoryRes.defaultWriteConcernSource, "implicit", tojson(inMemoryRes)); - } + assert.eq(res.defaultWriteConcernSource, "implicit", tojson(res)); + assert.eq(inMemoryRes.defaultWriteConcernSource, "implicit", tojson(inMemoryRes)); // No other fields should be returned if neither a default read nor write concern has been set. const unexpectedFields = ["updateOpTime", "updateWallClockTime"]; if (!isImplicitDefaultWCMajority) { unexpectedFields.push("defaultWriteConcern"); } - if (!isDefaultWCMajorityFlagEnabled) { - unexpectedFields.push("defaultWriteConcernSource"); - } if (!isDefaultRCLocalFlagEnabled) { unexpectedFields.push("defaultReadConcern"); @@ -201,10 +183,8 @@ function verifyDefaultState(conn, assert.eq(null, getPersistedRWCDocument(conn)); } -function verifyDefaultRWCommandsValidInputOnSuccess(conn, - isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, - isImplicitDefaultWCMajority) { +function verifyDefaultRWCommandsValidInputOnSuccess( + conn, isDefaultReadConcernLocalFlagEnabled, isImplicitDefaultWCMajority) { // // Test getDefaultRWConcern when neither read nor write concern are set. // @@ -230,19 +210,16 @@ function verifyDefaultRWCommandsValidInputOnSuccess(conn, {setDefaultRWConcern: 1, defaultReadConcern: {level: "local"}})), {expectRC: true, expectWC: false}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); verifyFields(getPersistedRWCDocument(conn), {expectRC: true, expectWC: false, isPersistedDocument: true}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); // Test getDefaultRWConcern when only read concern is set. verifyFields(assert.commandWorked(conn.adminCommand({getDefaultRWConcern: 1})), {expectRC: true, expectWC: false}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); // Test unsetting read concern. @@ -250,17 +227,14 @@ function verifyDefaultRWCommandsValidInputOnSuccess(conn, assert.commandWorked(conn.adminCommand({setDefaultRWConcern: 1, defaultReadConcern: {}})), {expectRC: false, expectWC: false}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); verifyFields(getPersistedRWCDocument(conn), {expectRC: false, expectWC: false, isPersistedDocument: true}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); verifyFields(assert.commandWorked(conn.adminCommand({getDefaultRWConcern: 1})), {expectRC: false, expectWC: false}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); // @@ -272,12 +246,10 @@ function verifyDefaultRWCommandsValidInputOnSuccess(conn, assert.commandWorked(conn.adminCommand({setDefaultRWConcern: 1, defaultWriteConcern: {}})), {expectRC: false, expectWC: false}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); verifyFields(getPersistedRWCDocument(conn), {expectRC: false, expectWC: false, isPersistedDocument: true}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); // Test setRWConcern when only write concern is set. @@ -291,19 +263,16 @@ function verifyDefaultRWCommandsValidInputOnSuccess(conn, conn.adminCommand({setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}})), {expectRC: false, expectWC: true}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); verifyFields(getPersistedRWCDocument(conn), {expectRC: false, expectWC: true, isPersistedDocument: true}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); // Test getRWConcern when only write concern is set. verifyFields(assert.commandWorked(conn.adminCommand({getDefaultRWConcern: 1})), {expectRC: false, expectWC: true}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); // @@ -316,19 +285,16 @@ function verifyDefaultRWCommandsValidInputOnSuccess(conn, })), {expectRC: true, expectWC: true}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); verifyFields(getPersistedRWCDocument(conn), {expectRC: true, expectWC: true, isPersistedDocument: true}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); // Test getRWConcern when both read and write concern are set. verifyFields(assert.commandWorked(conn.adminCommand({getDefaultRWConcern: 1})), {expectRC: true, expectWC: true}, isDefaultReadConcernLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, isImplicitDefaultWCMajority); } @@ -365,16 +331,10 @@ jsTestLog("Testing standalone replica set with implicit default write concern ma const primary = rst.getPrimary(); const isDefaultRCLocalFlagEnabled = isDefaultReadConcernLocalFlagEnabled(primary); - const isDefaultWCMajorityFlagEnabled = isDefaultWriteConcernMajorityFlagEnabled(primary); - const isImplicitDefaultWCMajority = isDefaultWCMajorityFlagEnabled; - verifyDefaultState(primary, - isDefaultRCLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, - isImplicitDefaultWCMajority); - verifyDefaultRWCommandsValidInputOnSuccess(primary, - isDefaultRCLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, - isImplicitDefaultWCMajority); + verifyDefaultState( + primary, isDefaultRCLocalFlagEnabled, true /* isImplicitDefaultWCMajority */); + verifyDefaultRWCommandsValidInputOnSuccess( + primary, isDefaultRCLocalFlagEnabled, true /* isImplicitDefaultWCMajority */); verifyDefaultRWCommandsInvalidInput(primary); // Secondary can run getDefaultRWConcern, but not setDefaultRWConcern. @@ -397,15 +357,10 @@ jsTestLog("Testing standalone replica set with implicit default write concern {w const primary = rst.getPrimary(); const isDefaultRCLocalFlagEnabled = isDefaultReadConcernLocalFlagEnabled(primary); - const isDefaultWCMajorityFlagEnabled = isDefaultWriteConcernMajorityFlagEnabled(primary); - verifyDefaultState(primary, - isDefaultRCLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, - false /* isImplicitDefaultWCMajority */); - verifyDefaultRWCommandsValidInputOnSuccess(primary, - isDefaultRCLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, - false /* isImplicitDefaultWCMajority */); + verifyDefaultState( + primary, isDefaultRCLocalFlagEnabled, false /* isImplicitDefaultWCMajority */); + verifyDefaultRWCommandsValidInputOnSuccess( + primary, isDefaultRCLocalFlagEnabled, false /* isImplicitDefaultWCMajority */); verifyDefaultRWCommandsInvalidInput(primary); // Secondary can run getDefaultRWConcern, but not setDefaultRWConcern. @@ -424,16 +379,9 @@ jsTestLog("Testing sharded cluster with implicit default write concern majority. // Mongos succeeds. let isDefaultRCLocalFlagEnabled = isDefaultReadConcernLocalFlagEnabled(st.s); - let isDefaultWCMajorityFlagEnabled = isDefaultWriteConcernMajorityFlagEnabled(st.s); - let isImplicitDefaultWCMajority = isDefaultWCMajorityFlagEnabled; - verifyDefaultState(st.s, - isDefaultRCLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, - isImplicitDefaultWCMajority); - verifyDefaultRWCommandsValidInputOnSuccess(st.s, - isDefaultRCLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, - isImplicitDefaultWCMajority); + verifyDefaultState(st.s, isDefaultRCLocalFlagEnabled, true /* isImplicitDefaultWCMajority */); + verifyDefaultRWCommandsValidInputOnSuccess( + st.s, isDefaultRCLocalFlagEnabled, true /* isImplicitDefaultWCMajority */); verifyDefaultRWCommandsInvalidInput(st.s); // Shard node fails. @@ -450,17 +398,12 @@ jsTestLog("Testing sharded cluster with implicit default write concern majority. st = new ShardingTest({shards: 1, rs: {nodes: 2}}); // Config server primary succeeds. isDefaultRCLocalFlagEnabled = isDefaultReadConcernLocalFlagEnabled(st.configRS.getPrimary()); - isDefaultWCMajorityFlagEnabled = - isDefaultWriteConcernMajorityFlagEnabled(st.configRS.getPrimary()); - isImplicitDefaultWCMajority = isDefaultWCMajorityFlagEnabled; verifyDefaultState(st.configRS.getPrimary(), isDefaultRCLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, - isImplicitDefaultWCMajority); + true /* isImplicitDefaultWCMajority */); verifyDefaultRWCommandsValidInputOnSuccess(st.configRS.getPrimary(), isDefaultRCLocalFlagEnabled, - isDefaultWCMajorityFlagEnabled, - isImplicitDefaultWCMajority); + true /* isImplicitDefaultWCMajority */); verifyDefaultRWCommandsInvalidInput(st.configRS.getPrimary()); // Config server secondary can run getDefaultRWConcern, but not setDefaultRWConcern. diff --git a/src/mongo/db/read_write_concern_defaults.cpp b/src/mongo/db/read_write_concern_defaults.cpp index 50a643e89e2..e73f8b04afd 100644 --- a/src/mongo/db/read_write_concern_defaults.cpp +++ b/src/mongo/db/read_write_concern_defaults.cpp @@ -138,9 +138,7 @@ RWConcernDefault ReadWriteConcernDefaults::generateNewCWRWCToBeSavedOnDisk( // setDefaultRWConcern command was empty (i.e. {defaultWriteConcern: {}}) // If current->getDefaultWriteConcern exists, that means the global default write concern has // already been set. - if (repl::feature_flags::gDefaultWCMajority.isEnabled( - serverGlobalParams.featureCompatibility) && - wc && wc->usedDefaultConstructedWC && current) { + if (wc && wc->usedDefaultConstructedWC && current) { uassert(ErrorCodes::IllegalOperation, str::stream() << "The global default write concern cannot be unset once it is set.", !current->getDefaultWriteConcern()); @@ -244,19 +242,13 @@ ReadWriteConcernDefaults::RWConcernDefaultAndTime ReadWriteConcernDefaults::getD } } - // The implicit default write concern will be w:1 if the feature compatibility version is not - // yet initialized. Similarly, if the config hasn't yet been loaded on the node, the default - // will be w:1, since we have no way of calculating the implicit default. This means that after - // we have loaded our config, nodes could change their implicit write concern default. This is - // safe since we shouldn't be accepting writes that need a write concern before we have loaded - // our config. - const bool isDefaultWCMajorityFeatureFlagEnabled = - serverGlobalParams.featureCompatibility.isVersionInitialized() && - repl::feature_flags::gDefaultWCMajority.isEnabled(serverGlobalParams.featureCompatibility); - + // If the config hasn't yet been loaded on the node, the default will be w:1, since we have no + // way of calculating the implicit default. This means that after we have loaded our config, + // nodes could change their implicit write concern default. This is safe since we shouldn't be + // accepting writes that need a write concern before we have loaded our config. // This prevents overriding the default write concern and its source on mongos if it has // already been set through the config server. - if (isDefaultWCMajorityFeatureFlagEnabled && !cached.getDefaultWriteConcernSource()) { + if (!cached.getDefaultWriteConcernSource()) { const bool isCWWCSet = cached.getDefaultWriteConcern() && !cached.getDefaultWriteConcern().get().usedDefaultConstructedWC; if (isCWWCSet) { diff --git a/src/mongo/db/read_write_concern_defaults_test.cpp b/src/mongo/db/read_write_concern_defaults_test.cpp index bcfa28ad0d2..a57c977ddeb 100644 --- a/src/mongo/db/read_write_concern_defaults_test.cpp +++ b/src/mongo/db/read_write_concern_defaults_test.cpp @@ -60,10 +60,6 @@ protected: ReadWriteConcernDefaultsLookupMock _lookupMock; - bool _isDefaultWCMajorityEnabled{ - serverGlobalParams.featureCompatibility.isVersionInitialized() && - repl::feature_flags::gDefaultWCMajority.isEnabled(serverGlobalParams.featureCompatibility)}; - bool _isDefaultRCLocalEnabled{ serverGlobalParams.featureCompatibility.isVersionInitialized() && repl::feature_flags::gDefaultRCLocal.isEnabled(serverGlobalParams.featureCompatibility)}; @@ -94,16 +90,10 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithAbsentCWRWCWithImplicitWC ASSERT(!defaults.getUpdateOpTime()); ASSERT(!defaults.getUpdateWallClockTime()); ASSERT_EQ(Date_t(), defaults.localUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithAbsentCWRWCWithImplicitWCMajority) { - if (!_isDefaultWCMajorityEnabled) { - return; - } - createDefaults(true /* isImplicitWCMajority */); // By not calling _lookupMock.setLookupCallReturnValue(), tests _defaults.lookup() returning @@ -152,16 +142,10 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithCWRWCNeverSetWithImplicit ASSERT(!defaults.getUpdateOpTime()); ASSERT(!defaults.getUpdateWallClockTime()); ASSERT_GT(defaults.localUpdateWallClockTime(), Date_t()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithCWRWCNeverSetWithImplicitWCMajority) { - if (!_isDefaultWCMajorityEnabled) { - return; - } - createDefaults(true /* isImplicitWCMajority */); // _defaults.lookup() returning default constructed RWConcern not boost::none. @@ -212,16 +196,10 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithUnsetCWRWCWithImplicitWCW ASSERT_EQ(Timestamp(1, 2), *defaults.getUpdateOpTime()); ASSERT_EQ(1234, defaults.getUpdateWallClockTime()->toMillisSinceEpoch()); ASSERT_GT(defaults.localUpdateWallClockTime(), Date_t()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithUnsetCWRWCWithImplicitWCMajority) { - if (!_isDefaultWCMajorityEnabled) { - return; - } - createDefaults(true /* isImplicitWCMajority */); RWConcernDefault newDefaults; @@ -270,10 +248,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithCWRWCNotSetThenSetWithImp ASSERT(!oldDefaults.getUpdateOpTime()); ASSERT(!oldDefaults.getUpdateWallClockTime()); ASSERT_GT(oldDefaults.localUpdateWallClockTime(), Date_t()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(oldDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(oldDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); RWConcernDefault newDefaults; newDefaults.setDefaultReadConcern( @@ -288,9 +263,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithCWRWCNotSetThenSetWithImp _lookupMock.setLookupCallReturnValue(std::move(newDefaults)); ReadWriteConcernDefaults::get(getServiceContext()).invalidate(); - if (_isDefaultWCMajorityEnabled) { - ASSERT(isCWWCSet()); - } + ASSERT(isCWWCSet()); auto defaults = getDefault(); ASSERT(defaults.getDefaultReadConcern()->getLevel() == repl::ReadConcernLevel::kLocalReadConcern); @@ -304,17 +277,11 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithCWRWCNotSetThenSetWithImp ASSERT_EQ(Timestamp(1, 2), *defaults.getUpdateOpTime()); ASSERT_EQ(1234, defaults.getUpdateWallClockTime()->toMillisSinceEpoch()); ASSERT_GT(defaults.localUpdateWallClockTime(), Date_t()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource()); - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); - } + ASSERT(defaults.getDefaultWriteConcernSource()); + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithCWRWCNotSetThenSetWithImplicitWCMajority) { - if (!_isDefaultWCMajorityEnabled) { - return; - } - createDefaults(true /* isImplicitWCMajority */); // _defaults.lookup() returning default constructed RWConcern not boost::none. @@ -383,10 +350,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithSetCWRWCWithImplicitWCW1) newDefaults.setUpdateOpTime(Timestamp(1, 2)); newDefaults.setUpdateWallClockTime(Date_t::fromMillisSinceEpoch(1234)); _lookupMock.setLookupCallReturnValue(std::move(newDefaults)); - - if (_isDefaultWCMajorityEnabled) { - ASSERT(isCWWCSet()); - } + ASSERT(isCWWCSet()); auto defaults = getDefault(); ASSERT(defaults.getDefaultReadConcern()->getLevel() == repl::ReadConcernLevel::kLocalReadConcern); @@ -400,16 +364,10 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithSetCWRWCWithImplicitWCW1) ASSERT_EQ(Timestamp(1, 2), *defaults.getUpdateOpTime()); ASSERT_EQ(1234, defaults.getUpdateWallClockTime()->toMillisSinceEpoch()); ASSERT_GT(defaults.localUpdateWallClockTime(), Date_t()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithSetCWRWCWithImplicitWCMajority) { - if (!_isDefaultWCMajorityEnabled) { - return; - } - createDefaults(true /* isImplicitWCMajority */); RWConcernDefault newDefaults; @@ -441,10 +399,6 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithSetCWRWCWithImplicitWCMaj } TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWriteConcernSourceImplicitWithUsedDefaultWC) { - if (!_isDefaultWCMajorityEnabled) { - return; - } - createDefaults(true /* isImplicitWCMajority */); RWConcernDefault newDefaults; @@ -500,9 +454,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithSetAndUnSetCWRCWithImplic ASSERT_EQ(Timestamp(1, 2), *defaults.getUpdateOpTime()); ASSERT_EQ(1234, defaults.getUpdateWallClockTime()->toMillisSinceEpoch()); ASSERT_GT(defaults.localUpdateWallClockTime(), Date_t()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); // unsetting default read concern. RWConcernDefault newDefaults2; @@ -529,16 +481,10 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithSetAndUnSetCWRCWithImplic ASSERT_EQ(Timestamp(1, 3), *defaults.getUpdateOpTime()); ASSERT_EQ(1234, defaults.getUpdateWallClockTime()->toMillisSinceEpoch()); ASSERT_GT(defaults.localUpdateWallClockTime(), Date_t()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithSetAndUnSetCWRCWithImplicitWCMajority) { - if (!_isDefaultWCMajorityEnabled) { - return; - } - createDefaults(true /* isImplicitWCMajority */); // Setting only default read concern. @@ -624,9 +570,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithoutInvalidateDoesNotCallL ASSERT_EQ(Timestamp(1, 2), *defaults.getUpdateOpTime()); ASSERT_EQ(1234, defaults.getUpdateWallClockTime()->toMillisSinceEpoch()); ASSERT_GT(defaults.localUpdateWallClockTime(), Date_t()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); RWConcernDefault newDefaults2; newDefaults2.setDefaultReadConcern( @@ -638,9 +582,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithoutInvalidateDoesNotCallL newDefaults2.setDefaultWriteConcern(wc); newDefaults2.setUpdateOpTime(Timestamp(3, 4)); newDefaults2.setUpdateWallClockTime(Date_t::fromMillisSinceEpoch(5678)); - if (_isDefaultWCMajorityEnabled) { - newDefaults2.setDefaultWriteConcernSource(DefaultWriteConcernSourceEnum::kGlobal); - } + newDefaults2.setDefaultWriteConcernSource(DefaultWriteConcernSourceEnum::kGlobal); _lookupMock.setLookupCallReturnValue(std::move(newDefaults2)); ASSERT(!isCWWCSet()); @@ -659,10 +601,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithoutInvalidateDoesNotCallL ASSERT_EQ(Timestamp(1, 2), *defaults2.getUpdateOpTime()); ASSERT_EQ(1234, defaults2.getUpdateWallClockTime()->toMillisSinceEpoch()); ASSERT_GT(defaults2.localUpdateWallClockTime(), Date_t()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults2.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults2.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } TEST_F(ReadWriteConcernDefaultsTest, TestInvalidate) { @@ -689,9 +628,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestInvalidate) { ASSERT_EQ(Timestamp(1, 2), *defaults.getUpdateOpTime()); ASSERT_EQ(1234, defaults.getUpdateWallClockTime()->toMillisSinceEpoch()); ASSERT_GT(defaults.localUpdateWallClockTime(), Date_t()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); RWConcernDefault newDefaults2; newDefaults2.setDefaultReadConcern( @@ -706,9 +643,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestInvalidate) { _lookupMock.setLookupCallReturnValue(std::move(newDefaults2)); ReadWriteConcernDefaults::get(getServiceContext()).invalidate(); - if (_isDefaultWCMajorityEnabled) { - ASSERT(isCWWCSet()); - } + ASSERT(isCWWCSet()); auto defaults2 = getDefault(); ASSERT(defaults2.getDefaultReadConcern()->getLevel() == repl::ReadConcernLevel::kAvailableReadConcern); @@ -720,9 +655,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestInvalidate) { ASSERT_EQ(Timestamp(3, 4), *defaults2.getUpdateOpTime()); ASSERT_EQ(5678, defaults2.getUpdateWallClockTime()->toMillisSinceEpoch()); ASSERT_GT(defaults2.localUpdateWallClockTime(), Date_t()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults2.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); - } + ASSERT(defaults2.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } TEST_F(ReadWriteConcernDefaultsTest, TestRefreshDefaultsWithEmptyCacheAndAbsentDefaults) { @@ -746,9 +679,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestRefreshDefaultsWithEmptyCacheAndAbsentD ASSERT(!defaults.getUpdateOpTime()); ASSERT(!defaults.getUpdateWallClockTime()); ASSERT_EQ(Date_t(), defaults.localUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } TEST_F(ReadWriteConcernDefaultsTest, TestRefreshDefaultsWithEmptyCacheAndSetDefaults) { @@ -766,9 +697,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestRefreshDefaultsWithEmptyCacheAndSetDefa ASSERT_EQ(Timestamp(1, 2), *defaults.getUpdateOpTime()); ASSERT_EQ(1234, defaults.getUpdateWallClockTime()->toMillisSinceEpoch()); ASSERT_GT(defaults.localUpdateWallClockTime(), Date_t()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } TEST_F(ReadWriteConcernDefaultsTest, TestRefreshDefaultsWithHigherEpoch) { @@ -783,9 +712,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestRefreshDefaultsWithHigherEpoch) { auto defaults = getDefault(); ASSERT_EQ(Timestamp(1, 2), *defaults.getUpdateOpTime()); ASSERT_EQ(1234, defaults.getUpdateWallClockTime()->toMillisSinceEpoch()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); RWConcernDefault newDefaults2; newDefaults2.setUpdateOpTime(Timestamp(3, 4)); @@ -798,9 +725,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestRefreshDefaultsWithHigherEpoch) { auto defaults2 = getDefault(); ASSERT_EQ(Timestamp(3, 4), *defaults2.getUpdateOpTime()); ASSERT_EQ(5678, defaults2.getUpdateWallClockTime()->toMillisSinceEpoch()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } TEST_F(ReadWriteConcernDefaultsTest, TestRefreshDefaultsWithLowerEpoch) { @@ -814,9 +739,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestRefreshDefaultsWithLowerEpoch) { auto defaults = getDefault(); ASSERT(defaults.getUpdateOpTime()); ASSERT(defaults.getUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); RWConcernDefault newDefaults2; newDefaults2.setUpdateOpTime(Timestamp(5, 6)); @@ -828,9 +751,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestRefreshDefaultsWithLowerEpoch) { auto defaults2 = getDefault(); ASSERT_EQ(Timestamp(10, 20), *defaults2.getUpdateOpTime()); ASSERT_EQ(1234, defaults2.getUpdateWallClockTime()->toMillisSinceEpoch()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } /** @@ -880,10 +801,6 @@ protected: return ReadWriteConcernDefaults::get(getServiceContext()); }()}; - bool _isDefaultWCMajorityEnabled{ - serverGlobalParams.featureCompatibility.isVersionInitialized() && - repl::feature_flags::gDefaultWCMajority.isEnabled(serverGlobalParams.featureCompatibility)}; - bool _isDefaultRCLocalEnabled{ serverGlobalParams.featureCompatibility.isVersionInitialized() && repl::feature_flags::gDefaultRCLocal.isEnabled(serverGlobalParams.featureCompatibility)}; @@ -975,11 +892,8 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - // Default write concern source is calculated through 'getDefault'. - ASSERT(newDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is calculated through 'getDefault'. + ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, @@ -1004,11 +918,8 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - // Default write concern source is calculated through 'getDefault'. - ASSERT(newDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is calculated through 'getDefault'. + ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, @@ -1026,11 +937,8 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, _lookupMock.setLookupCallReturnValue(std::move(defaults)); _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); - if (_isDefaultWCMajorityEnabled) { - // Default write concern source is calculated through 'getDefault'. - ASSERT(newDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kImplicit); - } + // Default write concern source is calculated through 'getDefault'. + ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, @@ -1054,11 +962,8 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - // Default write concern source is calculated through 'getDefault'. - ASSERT(newDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is calculated through 'getDefault'. + ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, @@ -1076,11 +981,8 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, _lookupMock.setLookupCallReturnValue(std::move(oldDefaults)); _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); - if (_isDefaultWCMajorityEnabled) { - // Default write concern source is calculated through 'getDefault'. - ASSERT(newDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kImplicit); - } + // Default write concern source is calculated through 'getDefault'. + ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); VectorClockMutable::get(getServiceContext())->tickClusterTime(1); getMockClockSource()->advance(Milliseconds(1)); @@ -1100,11 +1002,8 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, newDefaults = _rwcd.getDefault(operationContext()); ASSERT(newDefaults.getDefaultWriteConcern()); ASSERT_EQ(5, newDefaults.getDefaultWriteConcern()->wNumNodes); - if (_isDefaultWCMajorityEnabled) { - // Default write concern source is calculated through 'getDefault'. - ASSERT(newDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is calculated through 'getDefault'. + ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, @@ -1128,11 +1027,8 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - // Default write concern source is calculated through 'getDefault'. - ASSERT(newDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is calculated through 'getDefault'. + ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); // Test that the implicit default read concern is still used after read concern is unset. if (_isDefaultRCLocalEnabled) { @@ -1150,29 +1046,11 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, TestGenerateNewCWRWCToBeSavedOnDiskInvalidUnsetWriteConcern) { - auto oldDefaults = setupOldDefaults(); - if (repl::feature_flags::gDefaultWCMajority.isEnabled( - serverGlobalParams.featureCompatibility)) { - ASSERT_THROWS_CODE(_rwcd.generateNewCWRWCToBeSavedOnDisk( - operationContext(), boost::none, WriteConcernOptions()), - AssertionException, - ErrorCodes::IllegalOperation); - } else { - auto defaults = _rwcd.generateNewCWRWCToBeSavedOnDisk( - operationContext(), boost::none, WriteConcernOptions()); - ASSERT(defaults.getDefaultReadConcern()); - ASSERT(oldDefaults.getDefaultReadConcern()->getLevel() == - defaults.getDefaultReadConcern()->getLevel()); - ASSERT(!defaults.getDefaultReadConcernSource()); - ASSERT(!defaults.getDefaultWriteConcern()); - ASSERT_LT(*oldDefaults.getUpdateOpTime(), *defaults.getUpdateOpTime()); - ASSERT_LT(*oldDefaults.getUpdateWallClockTime(), *defaults.getUpdateWallClockTime()); - - _lookupMock.setLookupCallReturnValue(std::move(defaults)); - _rwcd.refreshIfNecessary(operationContext()); - auto newDefaults = _rwcd.getDefault(operationContext()); - ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); - } + setupOldDefaults(); + ASSERT_THROWS_CODE(_rwcd.generateNewCWRWCToBeSavedOnDisk( + operationContext(), boost::none, WriteConcernOptions()), + AssertionException, + ErrorCodes::IllegalOperation); } TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, @@ -1187,50 +1065,17 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, _lookupMock.setLookupCallReturnValue(std::move(defaults)); _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); - if (_isDefaultWCMajorityEnabled) { - // Default write concern source is calculated through 'getDefault'. - ASSERT(newDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kImplicit); - } + // Default write concern source is calculated through 'getDefault'. + ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, TestGenerateNewCWRWCToBeSavedOnDiskInvalidUnsetReadWriteConcern) { - auto oldDefaults = setupOldDefaults(); - if (repl::feature_flags::gDefaultWCMajority.isEnabled( - serverGlobalParams.featureCompatibility)) { - ASSERT_THROWS_CODE(_rwcd.generateNewCWRWCToBeSavedOnDisk( - operationContext(), repl::ReadConcernArgs(), WriteConcernOptions()), - AssertionException, - ErrorCodes::IllegalOperation); - } else { - auto defaults = _rwcd.generateNewCWRWCToBeSavedOnDisk( - operationContext(), repl::ReadConcernArgs(), WriteConcernOptions()); - // Assert that the on disk version does not have a read/write concern set. - ASSERT(!defaults.getDefaultReadConcern()); - ASSERT(!defaults.getDefaultReadConcernSource()); - - ASSERT(!defaults.getDefaultWriteConcern()); - ASSERT_LT(*oldDefaults.getUpdateOpTime(), *defaults.getUpdateOpTime()); - ASSERT_LT(*oldDefaults.getUpdateWallClockTime(), *defaults.getUpdateWallClockTime()); - - _lookupMock.setLookupCallReturnValue(std::move(defaults)); - _rwcd.refreshIfNecessary(operationContext()); - auto newDefaults = _rwcd.getDefault(operationContext()); - ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); - - if (_isDefaultRCLocalEnabled) { - ASSERT(newDefaults.getDefaultReadConcern()); - ASSERT(newDefaults.getDefaultReadConcern()->getLevel() == - repl::ReadConcernLevel::kLocalReadConcern); - ASSERT(newDefaults.getDefaultReadConcernSource()); - ASSERT(newDefaults.getDefaultReadConcernSource() == - DefaultReadConcernSourceEnum::kImplicit); - } else { - ASSERT(!newDefaults.getDefaultReadConcern()); - ASSERT(!newDefaults.getDefaultReadConcernSource()); - } - } + setupOldDefaults(); + ASSERT_THROWS_CODE(_rwcd.generateNewCWRWCToBeSavedOnDisk( + operationContext(), repl::ReadConcernArgs(), WriteConcernOptions()), + AssertionException, + ErrorCodes::IllegalOperation); } TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, @@ -1255,11 +1100,8 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - // Default write concern source is calculated through 'getDefault'. - ASSERT(newDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is calculated through 'getDefault'. + ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, @@ -1284,11 +1126,8 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - // Default write concern source is calculated through 'getDefault'. - ASSERT(newDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is calculated through 'getDefault'. + ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, TestRefreshDefaultsWithDeletedDefaults) { @@ -1300,10 +1139,8 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, TestRefreshDefaultsWithDelet auto origCachedDefaults = _rwcd.getDefault(operationContext()); ASSERT_EQ(Timestamp(10, 20), *origCachedDefaults.getUpdateOpTime()); ASSERT_EQ(Date_t::fromMillisSinceEpoch(1234), *origCachedDefaults.getUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(origCachedDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(origCachedDefaults.getDefaultWriteConcernSource() == + DefaultWriteConcernSourceEnum::kImplicit); VectorClockMutable::get(getServiceContext())->tickClusterTime(1); getMockClockSource()->advance(Milliseconds(1)); @@ -1318,10 +1155,8 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, TestRefreshDefaultsWithDelet ASSERT(!newCachedDefaults.getUpdateWallClockTime()); ASSERT_LT(origCachedDefaults.localUpdateWallClockTime(), newCachedDefaults.localUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(newCachedDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kImplicit); - } + ASSERT(newCachedDefaults.getDefaultWriteConcernSource() == + DefaultWriteConcernSourceEnum::kImplicit); } } // namespace diff --git a/src/mongo/db/repl/repl_server_parameters.idl b/src/mongo/db/repl/repl_server_parameters.idl index cbd2fdc1136..de92709ad49 100644 --- a/src/mongo/db/repl/repl_server_parameters.idl +++ b/src/mongo/db/repl/repl_server_parameters.idl @@ -551,14 +551,6 @@ feature_flags: default: true version: 4.9 - featureFlagDefaultWriteConcernMajority: - description: >- - When enabled, default write concern might be set to majority following the default write - concern formula if there is no cluster wide write concern (CWWC). - cpp_varname: feature_flags::gDefaultWCMajority - default: true - version: 5.0 - featureFlagRetryableFindAndModify: description: >- When enabled, storeFindAndModifyImagesInOplog=false will change the location of any diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index f6a296e5fa9..f6c475aa472 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -3515,9 +3515,7 @@ Status ReplicationCoordinatorImpl::_doReplSetReconfig(OperationContext* opCtx, // reconfig command. This includes force reconfigs. // The user should set a cluster-wide write concern and attempt the reconfig command again. if (serverGlobalParams.clusterRole != ClusterRole::ShardServer) { - if (repl::feature_flags::gDefaultWCMajority.isEnabled( - serverGlobalParams.featureCompatibility) && - !repl::enableDefaultWriteConcernUpdatesForInitiate.load() && currIDWC != newIDWC && + if (!repl::enableDefaultWriteConcernUpdatesForInitiate.load() && currIDWC != newIDWC && !ReadWriteConcernDefaults::get(opCtx).isCWWCSet(opCtx)) { return Status( ErrorCodes::NewReplicaSetConfigurationIncompatible, diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp index 713c95a5c32..2f929993bfd 100644 --- a/src/mongo/db/write_concern.cpp +++ b/src/mongo/db/write_concern.cpp @@ -116,15 +116,10 @@ StatusWith<WriteConcernOptions> extractWriteConcern(OperationContext* opCtx, ReadWriteConcernDefaults::get(opCtx->getServiceContext()).getDefault(opCtx); auto wcDefault = rwcDefaults.getDefaultWriteConcern(); if (wcDefault) { - if (repl::feature_flags::gDefaultWCMajority.isEnabled( - serverGlobalParams.featureCompatibility)) { - const auto defaultWriteConcernSource = - rwcDefaults.getDefaultWriteConcernSource(); - customDefaultWasApplied = defaultWriteConcernSource && - defaultWriteConcernSource == DefaultWriteConcernSourceEnum::kGlobal; - } else { - customDefaultWasApplied = true; - } + const auto defaultWriteConcernSource = + rwcDefaults.getDefaultWriteConcernSource(); + customDefaultWasApplied = defaultWriteConcernSource && + defaultWriteConcernSource == DefaultWriteConcernSourceEnum::kGlobal; LOGV2_DEBUG(22548, 2, diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp index 1013fc99471..d71fc9e6abc 100644 --- a/src/mongo/s/commands/strategy.cpp +++ b/src/mongo/s/commands/strategy.cpp @@ -676,15 +676,9 @@ Status ParseAndRunCommand::RunInvocation::_setup() { ReadWriteConcernDefaults::get(opCtx->getServiceContext()).getDefault(opCtx); if (const auto wcDefault = rwcDefaults.getDefaultWriteConcern()) { _parc->_wc = *wcDefault; - if (repl::feature_flags::gDefaultWCMajority.isEnabled( - serverGlobalParams.featureCompatibility)) { - const auto defaultWriteConcernSource = - rwcDefaults.getDefaultWriteConcernSource(); - customDefaultWriteConcernWasApplied = defaultWriteConcernSource && - defaultWriteConcernSource == DefaultWriteConcernSourceEnum::kGlobal; - } else { - customDefaultWriteConcernWasApplied = true; - } + const auto defaultWriteConcernSource = rwcDefaults.getDefaultWriteConcernSource(); + customDefaultWriteConcernWasApplied = defaultWriteConcernSource && + defaultWriteConcernSource == DefaultWriteConcernSourceEnum::kGlobal; LOGV2_DEBUG(22766, 2, "Applying default writeConcern on {command} of {writeConcern}", |