diff options
author | hari devaraj <hari.devaraj@10gen.com> | 2016-06-17 15:53:36 -0400 |
---|---|---|
committer | Siyuan Zhou <visualzhou@gmail.com> | 2017-01-18 21:29:02 -0500 |
commit | 12ae6869bef461d9604d667df726825bcaa35e32 (patch) | |
tree | 8f6a1168a26e28bbdac2469f3b61d442728cf1d4 | |
parent | 6f2efcb09ca00560471bce88ab725ee0cfb72403 (diff) | |
download | mongo-12ae6869bef461d9604d667df726825bcaa35e32.tar.gz |
SERVER-21432 Allowed slaveOk reads when node is in drain mode
(cherry picked from commit dd7e05dbde9f1e9554ad93cada8fb4d5dcbe11de)
-rw-r--r-- | jstests/replsets/drain.js | 11 | ||||
-rw-r--r-- | jstests/replsets/maintenance.js | 4 | ||||
-rw-r--r-- | src/mongo/db/dbcommands.cpp | 11 |
3 files changed, 17 insertions, 9 deletions
diff --git a/jstests/replsets/drain.js b/jstests/replsets/drain.js index 7f170c485d9..a81d45f1d10 100644 --- a/jstests/replsets/drain.js +++ b/jstests/replsets/drain.js @@ -43,7 +43,7 @@ } assert.writeOK(bulk.execute()); jsTestLog('Number of documents inserted into collection on primary: ' + numDocuments); - assert.eq(numDocuments, primary.getDB("foo").foo.find().itcount()); + assert.eq(numDocuments, primary.getDB("foo").foo.count()); assert.soon(function() { var serverStatus = secondary.getDB('foo').serverStatus(); @@ -75,12 +75,7 @@ "find failed with unexpected error code: " + tojson(res)); // Nor should it be readable with the slaveOk bit. secondary.slaveOk = true; - res = secondary.getDB("foo").runCommand({find: "foo"}); - assert.commandFailed(res); - assert.eq(ErrorCodes.NotMasterOrSecondary, - res.code, - "find failed with unexpected error code: " + tojson(res)); - secondary.slaveOk = false; + assert.commandWorked(secondary.getDB("foo").runCommand({find: "foo"})); assert.commandFailedWithCode( secondary.adminCommand({ @@ -110,5 +105,5 @@ // Check for at least two entries. There was one prior to freezing op application on the // secondary and we cannot guarantee all writes reached the secondary's op queue prior to // shutting down the original primary. - assert.gte(primary.getDB("foo").foo.find().itcount(), 2); + assert.gte(primary.getDB("foo").foo.count(), 2); })(); diff --git a/jstests/replsets/maintenance.js b/jstests/replsets/maintenance.js index 7e49e07e396..b1fe94efc0e 100644 --- a/jstests/replsets/maintenance.js +++ b/jstests/replsets/maintenance.js @@ -75,6 +75,10 @@ assert.soon(function() { return !im.secondary && !im.ismaster; }); +var recv = conns[1].getDB("admin").runCommand({find: "foo"}); +assert.commandFailed(recv); +assert.eq(recv.errmsg, "node is recovering"); + print("now getmore shouldn't work"); var ex = assert.throws(function() { lastDoc = null; diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index 31c453ecaa3..53b92f56bd3 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -1258,7 +1258,16 @@ void Command::execCommand(OperationContext* txn, replCoord->getReplicationMode() == repl::ReplicationCoordinator::modeReplSet && !replCoord->canAcceptWritesForDatabase(dbname) && !replCoord->getMemberState().secondary()) { - uasserted(ErrorCodes::NotMasterOrSecondary, "node is recovering"); + uassert(ErrorCodes::NotMasterOrSecondary, + "node is recovering", + !replCoord->getMemberState().recovering()); + uassert(ErrorCodes::NotMasterOrSecondary, + "node is not in primary or recovering state", + replCoord->getMemberState().primary()); + // Check ticket SERVER-21432, slaveOk commands are allowed in drain mode + uassert(ErrorCodes::NotMasterOrSecondary, + "node is in drain mode", + commandIsOverriddenToRunOnSecondary || commandCanRunOnSecondary); } } |