Skip to content

Commit

Permalink
SERVER-2212 mongos maxTimeMS support for moveChunk
Browse files Browse the repository at this point in the history
  • Loading branch information
jrassi committed Oct 31, 2013
1 parent 195c99e commit 323abac
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
25 changes: 25 additions & 0 deletions jstests/sharding/max_time_ms_sharded.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,29 @@ assert.doesNotThrow(function() { cursor.itcount(); },
[],
"did not expect getmore ops to hit the time limit");

configureMaxTimeNeverTimeOut("off");

//
// Test that mongos correctly forwards max time to shards for sharded commands. Uses
// maxTimeAlwaysTimeOut to ensure mongod throws if it receives a max time.
//

// Positive test for "moveChunk".
configureMaxTimeAlwaysTimeOut("alwaysOn");
assert.commandFailed(admin.runCommand({moveChunk: coll.getFullName(),
find: {_id: 0},
to: "shard0000",
maxTimeMS: 1000*60*60*24}),
"expected moveChunk to fail in mongod due to maxTimeAlwaysTimeOut fail point");

// Negative test for "moveChunk".
configureMaxTimeAlwaysTimeOut("off");
assert.commandWorked(admin.runCommand({moveChunk: coll.getFullName(),
find: {_id: 0},
to: "shard0000",
maxTimeMS: 1000*60*60*24}),
"expected moveChunk to not hit time limit in mongod");

// TODO Test additional commmands.

st.stop();
1 change: 1 addition & 0 deletions src/mongo/s/balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ namespace mongo {
Chunk::MaxChunkSize,
secondaryThrottle,
waitForDelete,
0, /* maxTimeMS */
res)) {
movedCount++;
continue;
Expand Down
6 changes: 5 additions & 1 deletion src/mongo/s/chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "mongo/client/connpool.h"
#include "mongo/client/dbclientcursor.h"
#include "mongo/db/query/lite_parsed_query.h"
#include "mongo/db/queryutil.h"
#include "mongo/platform/random.h"
#include "mongo/s/chunk_diff.h"
Expand Down Expand Up @@ -317,6 +318,7 @@ namespace mongo {
long long chunkSize /* bytes */,
bool secondaryThrottle,
bool waitForDelete,
int maxTimeMS,
BSONObj& res) const
{
uassert( 10167 , "can't move shard to its current location!" , getShard() != to );
Expand All @@ -341,7 +343,8 @@ namespace mongo {
"shardId" << genID() <<
"configdb" << configServer.modelServer() <<
"secondaryThrottle" << secondaryThrottle <<
"waitForDelete" << waitForDelete
"waitForDelete" << waitForDelete <<
LiteParsedQuery::cmdOptionMaxTimeMS << maxTimeMS
) ,
res);
fromconn.done();
Expand Down Expand Up @@ -443,6 +446,7 @@ namespace mongo {
MaxChunkSize ,
false , /* secondaryThrottle - small chunk, no need */
false, /* waitForDelete - small chunk, no need */
0, /* maxTimeMS - don't time out */
res ) );

// update our config
Expand Down
2 changes: 2 additions & 0 deletions src/mongo/s/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@ namespace mongo {
* @param chunSize maximum number of bytes beyond which the migrate should no go trhough
* @param secondaryThrottle whether during migrate all writes should block for repl
* @param waitForDelete whether chunk move should wait for cleanup or return immediately
* @param maxTimeMS max time for the migrate request
* @param res the object containing details about the migrate execution
* @return true if move was successful
*/
bool moveAndCommit(const Shard& to,
long long chunkSize,
bool secondaryThrottle,
bool waitForDelete,
int maxTimeMS,
BSONObj& res) const;

/**
Expand Down
11 changes: 10 additions & 1 deletion src/mongo/s/commands_admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "mongo/db/field_parser.h"
#include "mongo/db/hasher.h"
#include "mongo/db/index_names.h"
#include "mongo/db/query/lite_parsed_query.h"
#include "mongo/db/stats/counters.h"
#include "mongo/db/wire_version.h"
#include "mongo/s/chunk.h"
Expand Down Expand Up @@ -736,7 +737,7 @@ namespace mongo {

BSONObj moveResult;
if (!chunk->moveAndCommit(to, Chunk::MaxChunkSize,
false, true, moveResult)) {
false, true, 0, moveResult)) {
warning().stream()
<< "Couldn't move chunk " << chunk << " to shard " << to
<< " while sharding collection " << ns << ". Reason: "
Expand Down Expand Up @@ -1055,11 +1056,19 @@ namespace mongo {

MONGO_TLOG(0) << "CMD: movechunk: " << cmdObj << endl;

StatusWith<int> maxTimeMS = LiteParsedQuery::parseMaxTimeMSCommand(cmdObj);

if (!maxTimeMS.isOK()) {
errmsg = maxTimeMS.getStatus().reason();
return false;
}

BSONObj res;
if (!c->moveAndCommit(to,
maxChunkSizeBytes,
cmdObj["_secondaryThrottle"].trueValue(),
cmdObj["_waitForDelete"].trueValue(),
maxTimeMS.getValue(),
res)) {
errmsg = "move failed";
result.append( "cause" , res );
Expand Down

0 comments on commit 323abac

Please sign in to comment.