diff options
author | Spencer T Brody <spencer@mongodb.com> | 2015-10-06 14:21:20 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2015-10-13 23:35:59 -0400 |
commit | 694e8d341e35091f168ed65665f54fb99f4c3f25 (patch) | |
tree | f7167186bb3986dac112cae570362c105b818a01 | |
parent | 110e24cb3571778f4abb53e8f121b14f529307f6 (diff) | |
download | mongo-694e8d341e35091f168ed65665f54fb99f4c3f25.tar.gz |
SERVER-20780 Don't shut down the primary when there could be unreplicated writes in config_rs_no_primary.js
-rw-r--r-- | jstests/sharding/conf_server_write_concern.js | 3 | ||||
-rw-r--r-- | jstests/sharding/replset_config/config_rs_no_primary.js | 48 | ||||
-rw-r--r-- | src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp | 2 |
3 files changed, 36 insertions, 17 deletions
diff --git a/jstests/sharding/conf_server_write_concern.js b/jstests/sharding/conf_server_write_concern.js index 938b0b9a9dc..500061d4ca1 100644 --- a/jstests/sharding/conf_server_write_concern.js +++ b/jstests/sharding/conf_server_write_concern.js @@ -1,6 +1,5 @@ /** - * Test write concern with w parameter when writing directly to the config servers will - * not cause an error. + * Test write concern with w parameter when writing directly to the config servers works as expected */ function writeToConfigTest(){ jsTestLog("Testing data writes to config server with write concern"); diff --git a/jstests/sharding/replset_config/config_rs_no_primary.js b/jstests/sharding/replset_config/config_rs_no_primary.js index 2ff0f63f5a1..4a67f865249 100644 --- a/jstests/sharding/replset_config/config_rs_no_primary.js +++ b/jstests/sharding/replset_config/config_rs_no_primary.js @@ -1,30 +1,50 @@ // Tests operation of the cluster when the config servers have no primary and thus the cluster // metadata is in read-only mode. -var st = new ShardingTest({shards: 1}); +(function() { +"use strict"; + +var st = new ShardingTest({shards: 1, + other: {c0: {}, // Make sure 1st config server is primary + c1: {rsConfig: {priority: 0}}, + c2: {rsConfig: {priority: 0}}}}); + +assert.eq(st.config0, st.configRS.getPrimary()); // Create the "test" database while the cluster metadata is still writeable. st.s.getDB('test').foo.insert({a:1}); // Take down two of the config servers so the remaining one goes into SECONDARY state. -st.configRS.stop(0); st.configRS.stop(1); -assert.throws(function() {st.configRS.getMaster(5000);}); +st.configRS.stop(2); +assert.soon(function() { + return st.configRS.callIsMaster() == false; + }, "Timed out waiting for there to be no primary in config replset"); jsTestLog("Starting a new mongos when the config servers have no primary which should work"); var mongos2 = MongoRunner.runMongos({configdb: st.configRS.getURL()}); assert.neq(null, mongos2); -jsTestLog("Doing ops that don't require metadata writes and thus should succeed"); -assert.writeOK(mongos2.getDB('test').foo.insert({a:1})); -assert.eq(2, mongos2.getDB('test').foo.count()); +var testOps = function(mongos) { + jsTestLog("Doing ops that don't require metadata writes and thus should succeed against: " + + mongos); + var initialCount = mongos.getDB('test').foo.count(); + assert.writeOK(mongos.getDB('test').foo.insert({a:1})); + assert.eq(initialCount + 1, mongos.getDB('test').foo.count()); + + assert.throws(function() {mongos.getDB('config').shards.findOne();}); + mongos.setSlaveOk(true); + var shardDoc = mongos.getDB('config').shards.findOne(); + mongos.setSlaveOk(false); + assert.neq(null, shardDoc); -assert.throws(function() {st.s.getDB('config').shards.findOne();}); -st.s.setSlaveOk(true); -var shardDoc = st.s.getDB('config').shards.findOne(); -assert.neq(null, shardDoc); + jsTestLog("Doing ops that require metadata writes and thus should fail against: " + mongos) + assert.writeError(mongos.getDB("newDB").foo.insert({a:1})); + assert.commandFailed(mongos.getDB('admin').runCommand({shardCollection: "test.foo", + key: {a:1}})); +} -jsTestLog("Doing ops that require metadata writes and thus should fail") -assert.writeError(st.s.getDB("newDB").foo.insert({a:1})); -assert.commandFailed(st.s.getDB('admin').runCommand({shardCollection: "test.foo", key: {a:1}})); +testOps(mongos2); +testOps(st.s); -st.stop();
\ No newline at end of file +st.stop(); +}());
\ No newline at end of file diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp b/src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp index bb0c14fe7a0..1e843a17228 100644 --- a/src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp +++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp @@ -869,7 +869,7 @@ bool CatalogManagerReplicaSet::runUserManagementWriteCommand(OperationContext* t BSONObjBuilder* result) { BSONObj cmdToRun = cmdObj; { - // Make sure that the if the command has a write concern that it is w:1 or w:majority, and + // Make sure that if the command has a write concern that it is w:1 or w:majority, and // convert w:1 or no write concern to w:majority before sending. WriteConcernOptions writeConcern; const char* writeConcernFieldName = "writeConcern"; |