diff options
Diffstat (limited to 'jstests')
36 files changed, 174 insertions, 10 deletions
diff --git a/jstests/concurrency/fsm_workloads/multi_statement_transaction_atomicity_isolation.js b/jstests/concurrency/fsm_workloads/multi_statement_transaction_atomicity_isolation.js index 8be593b1a77..a1cd85daac2 100644 --- a/jstests/concurrency/fsm_workloads/multi_statement_transaction_atomicity_isolation.js +++ b/jstests/concurrency/fsm_workloads/multi_statement_transaction_atomicity_isolation.js @@ -191,6 +191,14 @@ var $config = (function() { const states = (function() { return { init: function init(db, collName) { + // The default WC is majority and this workload may not be able to satisfy majority + // writes. + assert.commandWorked(db.adminCommand({ + setDefaultRWConcern: 1, + defaultWriteConcern: {w: 1}, + writeConcern: {w: "majority"} + })); + this.iteration = 0; // Set causalConsistency = true to ensure that in the checkConsistency state // function, we will be able to read our own writes that were committed as a diff --git a/jstests/concurrency/fsm_workloads/multi_statement_transaction_simple.js b/jstests/concurrency/fsm_workloads/multi_statement_transaction_simple.js index adf4feba8b0..bfe4162201b 100644 --- a/jstests/concurrency/fsm_workloads/multi_statement_transaction_simple.js +++ b/jstests/concurrency/fsm_workloads/multi_statement_transaction_simple.js @@ -28,6 +28,12 @@ var $config = (function() { } function init(db, collName) { + // The default WC is majority and this test can't satisfy majority writes. + assert.commandWorked(db.adminCommand({ + setDefaultRWConcern: 1, + defaultWriteConcern: {w: 1}, + writeConcern: {w: "majority"} + })); this.session = db.getMongo().startSession({causalConsistency: true}); } diff --git a/jstests/concurrency/fsm_workloads/snapshot_read_kill_operations.js b/jstests/concurrency/fsm_workloads/snapshot_read_kill_operations.js index ee33ab8978a..3a8b8a8e822 100644 --- a/jstests/concurrency/fsm_workloads/snapshot_read_kill_operations.js +++ b/jstests/concurrency/fsm_workloads/snapshot_read_kill_operations.js @@ -15,6 +15,12 @@ var $config = (function() { const states = { init: function init(db, collName) { let session = db.getMongo().startSession({causalConsistency: true}); + // The default WC is majority and this test can't satisfy majority writes. + assert.commandWorked(db.adminCommand({ + setDefaultRWConcern: 1, + defaultWriteConcern: {w: 1}, + writeConcern: {w: "majority"} + })); // Store the session ID in the database so any unterminated transactions can be aborted // at teardown. insertSessionDoc(db, collName, this.tid, session.getSessionId().id); diff --git a/jstests/core/txns/new_transaction_waits_for_previous_txn_table_updates.js b/jstests/core/txns/new_transaction_waits_for_previous_txn_table_updates.js index 8e221936502..fa6e611e5b6 100644 --- a/jstests/core/txns/new_transaction_waits_for_previous_txn_table_updates.js +++ b/jstests/core/txns/new_transaction_waits_for_previous_txn_table_updates.js @@ -102,6 +102,9 @@ const collName = jsTestName(); const testDB = db.getSiblingDB(dbName); testDB.runCommand({drop: collName}); +// The default WC is majority and this test can't satisfy majority writes. +assert.commandWorked(testDB.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); assert.commandWorked(testDB.runCommand({create: collName, writeConcern: {w: "majority"}})); const session = testDB.getMongo().startSession(); diff --git a/jstests/core/txns/speculative_snapshot_includes_all_writes.js b/jstests/core/txns/speculative_snapshot_includes_all_writes.js index b4dc62c948a..99ea7beb183 100644 --- a/jstests/core/txns/speculative_snapshot_includes_all_writes.js +++ b/jstests/core/txns/speculative_snapshot_includes_all_writes.js @@ -43,6 +43,9 @@ let checkReads = (session, collExpected, coll2Expected) => { // Clear ramlog so checkLog can't find log messages from previous times this fail point was // enabled. assert.commandWorked(testDB.adminCommand({clearLog: 'global'})); +// The default WC is majority and this test can't satisfy majority writes. +assert.commandWorked(testDB.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); jsTest.log("Prepopulate the collections."); assert.commandWorked(testColl.insert([{_id: 0}], {writeConcern: {w: "majority"}})); diff --git a/jstests/core/txns/timestamped_reads_wait_for_prepare_oplog_visibility.js b/jstests/core/txns/timestamped_reads_wait_for_prepare_oplog_visibility.js index 9071a65e669..6138e4b54df 100644 --- a/jstests/core/txns/timestamped_reads_wait_for_prepare_oplog_visibility.js +++ b/jstests/core/txns/timestamped_reads_wait_for_prepare_oplog_visibility.js @@ -69,6 +69,9 @@ const readThreadFunc = function(readFunc, _collName, hangTimesEntered, logTimesE function runTest(prefix, readFunc) { // Reset the log history between tests. assert.commandWorked(db.adminCommand({clearLog: 'global'})); + // The default WC is majority and this test can't satisfy majority writes. + assert.commandWorked(db.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); jsTestLog('Testing oplog visibility for ' + prefix); const collName = baseCollName + '_' + prefix; diff --git a/jstests/libs/write_concern_util.js b/jstests/libs/write_concern_util.js index b1118a095c1..eb0ed480774 100644 --- a/jstests/libs/write_concern_util.js +++ b/jstests/libs/write_concern_util.js @@ -39,13 +39,21 @@ function stopServerReplication(conn, retryIntervalMS) { } // Stops replication at all replicaset secondaries. -function stopReplicationOnSecondaries(rs) { +function stopReplicationOnSecondaries(rs, changeReplicaSetDefaultWCToLocal = true) { + if (changeReplicaSetDefaultWCToLocal == true) { + // The default WC is majority and this test can't satisfy majority writes. + assert.commandWorked(rs.getPrimary().adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + } stopServerReplication(rs.getSecondaries()); } // Stops replication at all shard secondaries. function stopReplicationOnSecondariesOfAllShards(st) { - st._rsObjects.forEach(stopReplicationOnSecondaries); + // The default WC is majority and this test can't satisfy majority writes. + assert.commandWorked(st.s.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + st._rsObjects.forEach(rs => stopReplicationOnSecondaries(rs, false)); } // Restarts replication on the given server(s). @@ -112,6 +120,11 @@ function runWriteConcernRetryabilityTest(priConn, secConn, cmd, kNodes, dbName, dbName = dbName || "test"; jsTestLog(`Testing ${tojson(cmd)} on ${dbName}.`); + // The default WC is majority and stopServerReplication will prevent the replica set from + // fulfilling any majority writes + assert.commandWorked(priConn.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + // Send a dummy write to this connection so it will have the Client object initialized. const secondPriConn = new Mongo(priConn.host); const testDB2 = secondPriConn.getDB(dbName); diff --git a/jstests/multiVersion/genericSetFCVUsage/feature_compatibility_version_lagging_secondary.js b/jstests/multiVersion/genericSetFCVUsage/feature_compatibility_version_lagging_secondary.js index ac7a632e2c9..48285f2f4fe 100644 --- a/jstests/multiVersion/genericSetFCVUsage/feature_compatibility_version_lagging_secondary.js +++ b/jstests/multiVersion/genericSetFCVUsage/feature_compatibility_version_lagging_secondary.js @@ -21,6 +21,11 @@ function runTest(downgradeVersion) { let primary = rst.getPrimary(); let latestSecondary = rst.getSecondary(); + // The default WC is majority and stopServerReplication will prevent satisfying any majority + // writes. + assert.commandWorked(primary.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + // Set the featureCompatibilityVersion to the downgrade version so that a downgrade node can // join the set. assert.commandWorked( diff --git a/jstests/multiVersion/genericSetFCVUsage/set_feature_compatibility_version.js b/jstests/multiVersion/genericSetFCVUsage/set_feature_compatibility_version.js index c2b98d86c62..a96a607f953 100644 --- a/jstests/multiVersion/genericSetFCVUsage/set_feature_compatibility_version.js +++ b/jstests/multiVersion/genericSetFCVUsage/set_feature_compatibility_version.js @@ -305,6 +305,10 @@ function runReplicaSetTest(downgradeVersion) { let primary = rst.getPrimary(); primaryAdminDB = primary.getDB("admin"); assert.commandWorked(primary.adminCommand({setFeatureCompatibilityVersion: downgradeFCV})); + // The default WC is majority and stopServerReplication will prevent satisfying any majority + // writes. + assert.commandWorked(primary.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); let secondary = rst.getSecondary(); diff --git a/jstests/noPassthrough/diff_using_sessions_test.js b/jstests/noPassthrough/diff_using_sessions_test.js index be1f27b1e1c..8af480bdd80 100644 --- a/jstests/noPassthrough/diff_using_sessions_test.js +++ b/jstests/noPassthrough/diff_using_sessions_test.js @@ -19,6 +19,11 @@ const collName = "mycoll"; const primaryDB = rst.getPrimary().startSession().getDatabase(dbName); const secondaryDB = rst.getSecondary().startSession().getDatabase(dbName); +// The default WC is majority and rsSyncApplyStop failpoint will prevent satisfying any majority +// writes. +assert.commandWorked(rst.getPrimary().adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + assert.commandWorked(primaryDB[collName].insert( Array.from({length: 100}, (_, i) => ({_id: i, num: i * 2})), {writeConcern: {w: 2}})); diff --git a/jstests/noPassthrough/do_not_rebuild_indexes_before_repair.js b/jstests/noPassthrough/do_not_rebuild_indexes_before_repair.js index 9badd23287f..597c2ea2362 100644 --- a/jstests/noPassthrough/do_not_rebuild_indexes_before_repair.js +++ b/jstests/noPassthrough/do_not_rebuild_indexes_before_repair.js @@ -33,6 +33,11 @@ if (!rst.getPrimary().adminCommand("serverStatus").storageEngine.supportsSnapsho let primary = rst.getPrimary(); let testDB = primary.getDB(dbName); let coll = testDB.getCollection(collName); +// The default WC is majority and disableSnapshotting failpoint will prevent satisfying any majority +// writes. +assert.commandWorked(primary.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + assert.commandWorked(testDB.runCommand({ createIndexes: collName, indexes: [ diff --git a/jstests/noPassthrough/index_build_restart_secondary.js b/jstests/noPassthrough/index_build_restart_secondary.js index 47dfb3ed092..b51eb2c5437 100644 --- a/jstests/noPassthrough/index_build_restart_secondary.js +++ b/jstests/noPassthrough/index_build_restart_secondary.js @@ -32,6 +32,9 @@ replTest.initiate(); const primary = replTest.getPrimary(); const secondary = replTest.getSecondary(); +// The default WC is majority and this test can't satisfy majority writes. +assert.commandWorked(primary.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); const primaryDB = primary.getDB('test'); const secondaryDB = secondary.getDB('test'); diff --git a/jstests/noPassthrough/minvalid2.js b/jstests/noPassthrough/minvalid2.js index e201ec16767..76dd0650184 100644 --- a/jstests/noPassthrough/minvalid2.js +++ b/jstests/noPassthrough/minvalid2.js @@ -43,6 +43,9 @@ var primary = replTest.getPrimary(); var primaryId = replTest.getNodeId(primary); var secondary = secondaries[0]; var secondaryId = replTest.getNodeId(secondary); +// The default WC is majority and this test can't satisfy majority writes. +assert.commandWorked(primary.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); // Wait for primary to detect that the arbiter is up so that it won't step down when we later take // the secondary offline. diff --git a/jstests/noPassthrough/out_merge_on_secondary_write_concern.js b/jstests/noPassthrough/out_merge_on_secondary_write_concern.js index de68517decf..1229d898a7f 100644 --- a/jstests/noPassthrough/out_merge_on_secondary_write_concern.js +++ b/jstests/noPassthrough/out_merge_on_secondary_write_concern.js @@ -21,6 +21,10 @@ const primary = replTest.getPrimary(); const secondary = replTest.getSecondary(); const primaryDB = primary.getDB("test"); const secondaryDB = secondary.getDB("test"); +// The default WC is majority and stopServerReplication will prevent satisfying any majority writes. +assert.commandWorked(primary.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + assert.commandWorked(primaryDB.setProfilingLevel(2)); secondaryDB.getMongo().setReadPref("secondary"); diff --git a/jstests/noPassthrough/readConcern_atClusterTime_snapshot_selection.js b/jstests/noPassthrough/readConcern_atClusterTime_snapshot_selection.js index 68902a7bfa0..a81e4c81812 100644 --- a/jstests/noPassthrough/readConcern_atClusterTime_snapshot_selection.js +++ b/jstests/noPassthrough/readConcern_atClusterTime_snapshot_selection.js @@ -18,6 +18,11 @@ const rst = new ReplSetTest({nodes: 3, settings: {chainingAllowed: false}}); rst.startSet(); rst.initiate(); +// The default WC is majority and stopServerReplication will prevent satisfying any majority writes. +assert.commandWorked(rst.getPrimary().adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); +rst.awaitReplication(); + const primarySession = rst.getPrimary().getDB(dbName).getMongo().startSession({causalConsistency: false}); const primaryDB = primarySession.getDatabase(dbName); diff --git a/jstests/noPassthrough/rebuild_multiple_indexes_at_startup.js b/jstests/noPassthrough/rebuild_multiple_indexes_at_startup.js index 58e8b93a74b..fb5e7131024 100644 --- a/jstests/noPassthrough/rebuild_multiple_indexes_at_startup.js +++ b/jstests/noPassthrough/rebuild_multiple_indexes_at_startup.js @@ -25,6 +25,11 @@ if (!rst.getPrimary().adminCommand("serverStatus").storageEngine.supportsSnapsho return; } +// The default WC is majority and disableSnapshotting failpoint will prevent satisfying any majority +// writes. +assert.commandWorked(rst.getPrimary().adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + let testDB = rst.getPrimary().getDB("indexRebuild"); let collName = "coll"; let coll = testDB.getCollection(collName); diff --git a/jstests/noPassthrough/recovery_wt_cache_full.js b/jstests/noPassthrough/recovery_wt_cache_full.js index 5bf4b46b040..19656c93416 100644 --- a/jstests/noPassthrough/recovery_wt_cache_full.js +++ b/jstests/noPassthrough/recovery_wt_cache_full.js @@ -41,6 +41,11 @@ const primary = rst.getPrimary(); const mydb = primary.getDB('test'); const coll = mydb.getCollection('t'); +// The default WC is majority and disableSnapshotting failpoint will prevent satisfying any majority +// writes. +assert.commandWorked(primary.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + const numDocs = 2; const minDocSizeMB = 10; diff --git a/jstests/noPassthrough/standalone_replication_recovery.js b/jstests/noPassthrough/standalone_replication_recovery.js index 0fdd31e5ba2..f0de7b23710 100644 --- a/jstests/noPassthrough/standalone_replication_recovery.js +++ b/jstests/noPassthrough/standalone_replication_recovery.js @@ -50,6 +50,10 @@ let secondary = nodes[1]; rst.initiate( {_id: name, members: [{_id: 0, host: node.host}, {_id: 2, host: secondary.host, priority: 0}]}); +// The default WC is majority and stopServerReplication will prevent satisfying any majority writes. +assert.commandWorked(rst.getPrimary().adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + // Create the collection with w:majority and then perform a clean restart to ensure that // the collection is in a stable checkpoint. assert.commandWorked(node.getDB(dbName).runCommand( diff --git a/jstests/noPassthrough/timestamp_index_builds.js b/jstests/noPassthrough/timestamp_index_builds.js index f7995108f34..61299bbaf4e 100644 --- a/jstests/noPassthrough/timestamp_index_builds.js +++ b/jstests/noPassthrough/timestamp_index_builds.js @@ -40,6 +40,11 @@ if (!rst.getPrimary().adminCommand("serverStatus").storageEngine.supportsSnapsho return; } +// The default WC is majority and disableSnapshotting failpoint will prevent satisfying any majority +// writes. +assert.commandWorked(rst.getPrimary().adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + function getColl(conn) { return conn.getDB("timestampingIndexBuild")["coll"]; } diff --git a/jstests/noPassthrough/wt_cache_full.js b/jstests/noPassthrough/wt_cache_full.js index e27c71f2fef..a71837783ad 100644 --- a/jstests/noPassthrough/wt_cache_full.js +++ b/jstests/noPassthrough/wt_cache_full.js @@ -32,6 +32,11 @@ const primary = rst.getPrimary(); const mydb = primary.getDB('test'); const coll = mydb.getCollection('t'); +// The default WC is majority and rsSyncApplyStop failpoint will prevent satisfying any majority +// writes. +assert.commandWorked(primary.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + const numDocs = 2; const minDocSizeMB = 10; diff --git a/jstests/noPassthrough/wt_delayed_secondary_read_concern_majority.js b/jstests/noPassthrough/wt_delayed_secondary_read_concern_majority.js index 7985c3b5d8d..807a46bbeea 100644 --- a/jstests/noPassthrough/wt_delayed_secondary_read_concern_majority.js +++ b/jstests/noPassthrough/wt_delayed_secondary_read_concern_majority.js @@ -64,6 +64,10 @@ if (storageEngine !== "wiredTiger") { }); var primary = rst.getPrimary(); // Waits for PRIMARY state. + // The default WC is majority and we want the delayed secondary to fall behind in replication. + assert.commandWorked(primary.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: 1}})); + // Reconfigure primary with a small cache size so less data needs to be // inserted to make the cache full while trying to trigger a stall. assert.commandWorked(primary.adminCommand( diff --git a/jstests/noPassthroughWithMongod/ttl_repl_secondary_disabled.js b/jstests/noPassthroughWithMongod/ttl_repl_secondary_disabled.js index 160933c4ed8..60184fe1ee8 100644 --- a/jstests/noPassthroughWithMongod/ttl_repl_secondary_disabled.js +++ b/jstests/noPassthroughWithMongod/ttl_repl_secondary_disabled.js @@ -41,8 +41,10 @@ rt.awaitReplication(); assert.commandWorked(secondary1col.getDB().adminCommand({setParameter: 1, logLevel: 1})); // insert old doc (10 minutes old) directly on secondary using godinsert +// The default WC is majority and godinsert command on a secondary is incompatible with wc:majority. assert.commandWorked(secondary1col.runCommand( - "godinsert", {obj: {_id: new Date(), x: new Date((new Date()).getTime() - 600000)}})); + "godinsert", + {obj: {_id: new Date(), x: new Date((new Date()).getTime() - 600000)}, writeConcern: {w: 1}})); assert.eq(1, secondary1col.count(), "missing inserted doc"); sleep(70 * 1000); // wait for 70seconds diff --git a/jstests/replsets/operation_time_read_and_write_concern.js b/jstests/replsets/operation_time_read_and_write_concern.js index 89e813faeb3..f1ce000511d 100644 --- a/jstests/replsets/operation_time_read_and_write_concern.js +++ b/jstests/replsets/operation_time_read_and_write_concern.js @@ -18,6 +18,11 @@ var replTest = new ReplSetTest( replTest.startSet(); replTest.initiate(); +// The default WC is majority and stopServerReplication will prevent satisfying any majority writes. +assert.commandWorked(replTest.getPrimary().adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); +replTest.awaitReplication(); + var res; var testDB = replTest.getPrimary().getDB(name); var collectionName = "foo"; @@ -32,7 +37,7 @@ res = assert.commandWorked(testDB.runCommand( {insert: collectionName, documents: [majorityDoc], writeConcern: {w: "majority"}})); var majorityWriteOperationTime = res.operationTime; -stopReplicationOnSecondaries(replTest); +stopReplicationOnSecondaries(replTest, false /* changeReplicaSetDefaultWCToLocal */); res = assert.commandWorked( testDB.runCommand({insert: collectionName, documents: [localDoc], writeConcern: {w: 1}})); @@ -102,7 +107,7 @@ res = assert.commandWorked(testDB.runCommand( {insert: collectionName, documents: [successfulDoc], writeConcern: {w: "majority"}})); var majorityWriteOperationTime = res.operationTime; -stopReplicationOnSecondaries(replTest); +stopReplicationOnSecondaries(replTest, false /* changeReplicaSetDefaultWCToLocal */); res = testDB.runCommand({ insert: collectionName, diff --git a/jstests/replsets/replset5.js b/jstests/replsets/replset5.js index b4a9ddd7aaf..8faf0739224 100644 --- a/jstests/replsets/replset5.js +++ b/jstests/replsets/replset5.js @@ -23,7 +23,7 @@ replTest.awaitSecondaryNodes(); var testDB = "foo"; // Initial replication -// TODO SERVER-55703: Remove manual write concern once we start using the new implicit default write +// TODO SERVER-56633: Remove manual write concern once we start using the new implicit default write // concern. primary.getDB("barDB").bar.save({a: 1}, {writeConcern: {w: 3, wtimeout: ReplSetTest.kDefaultTimeoutMS}}); @@ -39,7 +39,7 @@ for (var n = 0; n < docNum; n++) { // If you want to test failure, just add values for w and wtimeout (e.g. w=1) // to the following command. This will override the default set above and // prevent replication from happening in time for the count tests below. -// TODO SERVER-55703: Remove manual write concern once we start using the new implicit default write +// TODO SERVER-56633: Remove manual write concern once we start using the new implicit default write // concern. var result = bulk.execute({w: 3, wtimeout: ReplSetTest.kDefaultTimeoutMS}); var wcError = result.getWriteConcernError(); diff --git a/jstests/sharding/change_stream_update_lookup_read_concern.js b/jstests/sharding/change_stream_update_lookup_read_concern.js index 7cb8f5c667e..2b46b5084a6 100644 --- a/jstests/sharding/change_stream_update_lookup_read_concern.js +++ b/jstests/sharding/change_stream_update_lookup_read_concern.js @@ -53,6 +53,10 @@ rst.awaitSecondaryNodes(); const st = new ShardingTest({manualAddShard: true}); assert.commandWorked(st.s.adminCommand({addShard: replSetName + "/" + rst.getPrimary().host})); +// The default WC is majority and stopServerReplication will prevent satisfying any majority writes. +assert.commandWorked(st.s.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + const mongosDB = st.s0.getDB(jsTestName()); const mongosColl = mongosDB[jsTestName()]; diff --git a/jstests/sharding/commands_that_write_accept_wc_configRS.js b/jstests/sharding/commands_that_write_accept_wc_configRS.js index 1dae32155fd..7b147aea257 100644 --- a/jstests/sharding/commands_that_write_accept_wc_configRS.js +++ b/jstests/sharding/commands_that_write_accept_wc_configRS.js @@ -202,7 +202,7 @@ function testValidWriteConcern(wc, cmd) { // Stop replication at all config server secondaries and all shard secondaries. stopReplicationOnSecondariesOfAllShards(st); st.configRS.awaitReplication(); - stopReplicationOnSecondaries(st.configRS); + stopReplicationOnSecondaries(st.configRS, false /* changeReplicaSetDefaultWCToLocal */); // Command should fail after two config servers are not replicating. req.writeConcern.wtimeout = 3000; diff --git a/jstests/sharding/migration_waits_for_majority_commit.js b/jstests/sharding/migration_waits_for_majority_commit.js index cc124aac46b..b0247eb4a41 100644 --- a/jstests/sharding/migration_waits_for_majority_commit.js +++ b/jstests/sharding/migration_waits_for_majority_commit.js @@ -20,6 +20,9 @@ st.ensurePrimaryShard("test", st.shard0.shardName); assert.commandWorked(st.s.adminCommand({enableSharding: "test"})); assert.commandWorked(st.s.adminCommand({shardCollection: "test.foo", key: {_id: 1}})); assert.commandWorked(st.s.adminCommand({split: "test.foo", middle: {_id: 0}})); +// The default WC is majority and stopServerReplication will prevent satisfying any majority writes. +assert.commandWorked(st.s.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); // The document is in the majority committed snapshot. assert.eq(1, testDB.foo.find().readConcern("majority").itcount()); diff --git a/jstests/sharding/read_committed_lookup.js b/jstests/sharding/read_committed_lookup.js index 95b5c2b25d8..20688df6f7c 100644 --- a/jstests/sharding/read_committed_lookup.js +++ b/jstests/sharding/read_committed_lookup.js @@ -40,6 +40,10 @@ let st = new ShardingTest({ manualAddShard: true, }); assert.commandWorked(st.s.adminCommand({addShard: rst.getURL()})); +// The default WC is majority and this test can't satisfy majority writes. +assert.commandWorked(st.s.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + testReadCommittedLookup(st.s.getDB("test"), shardSecondary, rst); // Confirm read committed works on a cluster with: diff --git a/jstests/sharding/safe_secondary_reads_drop_recreate.js b/jstests/sharding/safe_secondary_reads_drop_recreate.js index 4cd28a158d4..bc9e51c5915 100644 --- a/jstests/sharding/safe_secondary_reads_drop_recreate.js +++ b/jstests/sharding/safe_secondary_reads_drop_recreate.js @@ -516,6 +516,9 @@ let staleMongos = st.s1; let res = st.s.adminCommand({listCommands: 1}); assert.commandWorked(res); +// The default WC is majority and this test can't satisfy majority writes. +assert.commandWorked(staleMongos.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); let commands = Object.keys(res.commands); for (let command of commands) { diff --git a/jstests/sharding/shard_identity_rollback.js b/jstests/sharding/shard_identity_rollback.js index 39738521d6e..ba2d43e5acc 100644 --- a/jstests/sharding/shard_identity_rollback.js +++ b/jstests/sharding/shard_identity_rollback.js @@ -18,6 +18,10 @@ var replTest = new ReplSetTest({nodes: 3}); var nodes = replTest.startSet({shardsvr: ''}); replTest.initiate(); +// The default WC is majority and stopServerReplication will prevent satisfying any majority writes. +assert.commandWorked(st.s.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + var priConn = replTest.getPrimary(); var secondaries = replTest.getSecondaries(); var configConnStr = st.configRS.getURL(); diff --git a/jstests/sharding/sharding_rs2.js b/jstests/sharding/sharding_rs2.js index 4c8f70c569d..76b3f7e8f0e 100644 --- a/jstests/sharding/sharding_rs2.js +++ b/jstests/sharding/sharding_rs2.js @@ -38,6 +38,10 @@ var db = s.getDB("test"); var t = db.foo; assert.commandWorked(s.s0.adminCommand({enablesharding: "test"})); +// The default WC is majority and fsyncLock will prevent satisfying any majority writes. +assert.commandWorked(s.s.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + s.ensurePrimaryShard('test', s.shard0.shardName); // ------------------------------------------------------------------------------------------- diff --git a/jstests/sharding/shards_and_config_return_last_committed_optime.js b/jstests/sharding/shards_and_config_return_last_committed_optime.js index 03fa837bbbe..ab9315699fe 100644 --- a/jstests/sharding/shards_and_config_return_last_committed_optime.js +++ b/jstests/sharding/shards_and_config_return_last_committed_optime.js @@ -92,6 +92,9 @@ function assertReturnsLastCommittedOpTime(testDB, collName, connType) { const st = new ShardingTest({shards: 1, rs: {nodes: 2}, config: 2}); assert.commandWorked(st.s.adminCommand({enableSharding: "test"})); assert.commandWorked(st.s.adminCommand({shardCollection: "test.foo", key: {x: 1}})); +// The default WC is majority and stopServerReplication will prevent satisfying any majority writes. +assert.commandWorked(st.s.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); // Sharded collection. assertDoesNotReturnLastCommittedOpTime( diff --git a/jstests/sharding/txn_commit_optimizations_for_read_only_shards.js b/jstests/sharding/txn_commit_optimizations_for_read_only_shards.js index a9b8005058b..b5928ce7eba 100644 --- a/jstests/sharding/txn_commit_optimizations_for_read_only_shards.js +++ b/jstests/sharding/txn_commit_optimizations_for_read_only_shards.js @@ -239,6 +239,13 @@ const failureModes = { }, participantCannotMajorityCommitWritesClientSendsWriteConcernMajority: { beforeStatements: () => { + // The default WC is majority and stopServerReplication will prevent satisfying any + // majority writes. + assert.commandWorked(st.s.adminCommand({ + setDefaultRWConcern: 1, + defaultWriteConcern: {w: 1}, + writeConcern: {w: "majority"} + })); // Participant cannot majority commit writes. stopServerReplication(st.rs0.getSecondaries()); @@ -262,6 +269,12 @@ const failureModes = { }, participantCannotMajorityCommitWritesClientSendsWriteConcern1: { beforeStatements: () => { + // stopServerReplication will prevent fulfil any majority writes. + assert.commandWorked(st.s.adminCommand({ + setDefaultRWConcern: 1, + defaultWriteConcern: {w: 1}, + writeConcern: {w: "majority"} + })); // Participant cannot majority commit writes. stopServerReplication(st.rs0.getSecondaries()); diff --git a/jstests/sharding/txn_recover_decision_using_recovery_router.js b/jstests/sharding/txn_recover_decision_using_recovery_router.js index 721634224d4..8a320444b82 100644 --- a/jstests/sharding/txn_recover_decision_using_recovery_router.js +++ b/jstests/sharding/txn_recover_decision_using_recovery_router.js @@ -188,6 +188,10 @@ const waitForCommitTransactionToComplete = function(coordinatorRs, lsid, txnNumb let st = new ShardingTest({shards: 2, rs: {nodes: 2}, mongos: 2, other: {mongosOptions: {verbose: 3}}}); +// The default WC is majority and this test can't satisfy majority writes. +assert.commandWorked(st.s.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + enableCoordinateCommitReturnImmediatelyAfterPersistingDecision(st); assert.commandWorked(st.s0.adminCommand({enableSharding: 'test'})); st.ensurePrimaryShard('test', st.shard0.name); @@ -278,7 +282,8 @@ assert.commandFailedWithCode(sendCommitViaOriginalMongos(lsid, txnNumber, recove const recoveryShardReplSetTest = st.rs1; -stopReplicationOnSecondaries(recoveryShardReplSetTest); +stopReplicationOnSecondaries(recoveryShardReplSetTest, + false /* changeReplicaSetDefaultWCToLocal */); // Do a write on the recovery node to bump the recovery node's system last OpTime. recoveryShardReplSetTest.getPrimary().getDB("dummy").getCollection("dummy").insert({dummy: 1}); @@ -308,7 +313,8 @@ assert.commandWorked(sendCommitViaOriginalMongos(lsid, txnNumber, recoveryToken) const recoveryShardReplSetTest = st.rs1; -stopReplicationOnSecondaries(recoveryShardReplSetTest); +stopReplicationOnSecondaries(recoveryShardReplSetTest, + false /* changeReplicaSetDefaultWCToLocal */); // Do a write on the recovery node to bump the recovery node's system last OpTime. recoveryShardReplSetTest.getPrimary().getDB("dummy").getCollection("dummy").insert({dummy: 1}); diff --git a/jstests/sharding/txn_two_phase_commit_wait_for_majority_commit_after_stepup.js b/jstests/sharding/txn_two_phase_commit_wait_for_majority_commit_after_stepup.js index a4b0735abc1..607389418b9 100644 --- a/jstests/sharding/txn_two_phase_commit_wait_for_majority_commit_after_stepup.js +++ b/jstests/sharding/txn_two_phase_commit_wait_for_majority_commit_after_stepup.js @@ -54,6 +54,11 @@ const setUp = function() { // shard1: [0, 10) // shard2: [10, +inf) assert.commandWorked(st.s.adminCommand({enableSharding: dbName})); + // The default WC is majority and stopServerReplication will prevent satisfying any majority + // writes. + assert.commandWorked(st.s.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + assert.commandWorked(st.s.adminCommand({movePrimary: dbName, to: participant0.shardName})); assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {_id: 1}})); assert.commandWorked(st.s.adminCommand({split: ns, middle: {_id: 0}})); diff --git a/jstests/sharding/txn_two_phase_commit_write_concern.js b/jstests/sharding/txn_two_phase_commit_write_concern.js index f42851c5dae..4d9eef7f4a0 100644 --- a/jstests/sharding/txn_two_phase_commit_write_concern.js +++ b/jstests/sharding/txn_two_phase_commit_write_concern.js @@ -38,6 +38,10 @@ const lsid = { let txnNumber = 0; assert.commandWorked(st.s.adminCommand({enableSharding: kDbName})); +// The default WC is majority and stopServerReplication will prevent satisfying any majority writes. +assert.commandWorked(st.s.adminCommand( + {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}})); + st.ensurePrimaryShard(kDbName, st.shard0.shardName); assert.commandWorked(st.s.adminCommand({shardCollection: kNs, key: {x: 1}})); |