diff options
-rw-r--r-- | etc/backports_required_for_multiversion_tests.yml | 4 | ||||
-rw-r--r-- | jstests/replsets/write_concern_write_to_local.js | 41 | ||||
-rw-r--r-- | src/mongo/db/service_entry_point_mongod.cpp | 7 |
3 files changed, 52 insertions, 0 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml index 7e04263a86d..22da64c4512 100644 --- a/etc/backports_required_for_multiversion_tests.yml +++ b/etc/backports_required_for_multiversion_tests.yml @@ -24,6 +24,8 @@ last-continuous: all: - ticket: SERVER-57262 test_file: jstests/replsets/catchup_takeover_with_higher_config.js + - ticket: SERVER-58898 + test_file: jstests/replsets/write_concern_write_to_local.js # Tests that should only be excluded from particular suites should be listed under that suite. suites: @@ -196,6 +198,8 @@ last-lts: test_file: jstests/sharding/txn_writes_during_movechunk.js - ticket: SERVER-57262 test_file: jstests/replsets/catchup_takeover_with_higher_config.js + - ticket: SERVER-58898 + test_file: jstests/replsets/write_concern_write_to_local.js # Tests that should only be excluded from particular suites should be listed under that suite. suites: diff --git a/jstests/replsets/write_concern_write_to_local.js b/jstests/replsets/write_concern_write_to_local.js new file mode 100644 index 00000000000..86450f696a4 --- /dev/null +++ b/jstests/replsets/write_concern_write_to_local.js @@ -0,0 +1,41 @@ +/* + * Tests that we are silently ignoring writeConcern when we write to local db. + */ + +(function() { +'use strict'; + +load("jstests/libs/write_concern_util.js"); // For stopReplicationOnSecondaries. + +const rst = new ReplSetTest( + {nodes: [{}, {rsConfig: {priority: 0}}], nodeOptions: {setParameter: {logLevel: 1}}}); +rst.startSet(); +rst.initiate(); +const primary = rst.getPrimary(); +const primaryDB = primary.getDB("local"); +const primaryColl = primaryDB["test"]; + +const secondary = rst.getSecondary(); +const secondaryDB = secondary.getDB("local"); +const secondaryColl = secondaryDB["test"]; + +jsTestLog("Write to local db on the secondary node should succeed."); +secondaryColl.insertOne({x: 1}); +secondaryColl.insertOne({x: 2}, {writeConcern: {w: 1}}); +secondaryColl.insertOne({x: 3}, {writeConcern: {w: 2}}); + +jsTestLog("Stop replication to prevent primary from satisfying majority write-concern."); +stopReplicationOnSecondaries(rst, false /* changeReplicaSetDefaultWCToLocal */); + +// Advance the primary opTime by doing local dummy write. +assert.commandWorked( + rst.getPrimary().getDB("dummy")["dummy"].insert({x: 'dummy'}, {writeConcern: {w: 1}})); + +jsTestLog("Write to local db on the primary node should succeed."); +primaryColl.insertOne({x: 4}); +primaryColl.insertOne({x: 5}, {writeConcern: {w: 1}}); +primaryColl.insertOne({x: 6}, {writeConcern: {w: 2}}); + +restartReplicationOnSecondaries(rst); +rst.stopSet(); +})(); diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp index 00fbaea5764..71be1d02ba4 100644 --- a/src/mongo/db/service_entry_point_mongod.cpp +++ b/src/mongo/db/service_entry_point_mongod.cpp @@ -114,6 +114,13 @@ public: const CommandInvocation* invocation, const repl::OpTime& lastOpBeforeRun, BSONObjBuilder& commandResponseBuilder) const override { + + // Prevent waiting for writeConcern if the command is changing an unreplicated namespace. + invariant(invocation); + if (!invocation->ns().isReplicated()) { + return; + } + auto lastOpAfterRun = repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp(); auto waitForWriteConcernAndAppendStatus = [&]() { |