diff options
author | Aaron <aaron@10gen.com> | 2009-04-06 16:33:44 -0400 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2009-04-06 16:33:44 -0400 |
commit | 0875581b5e67530e6d6e567968906d2553dcb4aa (patch) | |
tree | 45bbd907abe3e17b1a0c41cc8c839298e4018019 /s/shard.cpp | |
parent | 0af6ebeea2e641001ebf855ddf23f89bbb92c63d (diff) | |
parent | fc5b28e636cb276a5340cc1694ebaea892d8f1e7 (diff) | |
download | mongo-0875581b5e67530e6d6e567968906d2553dcb4aa.tar.gz |
Diffstat (limited to 's/shard.cpp')
-rw-r--r-- | s/shard.cpp | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/s/shard.cpp b/s/shard.cpp index 99e64ed3d1a..ffbac9509ca 100644 --- a/s/shard.cpp +++ b/s/shard.cpp @@ -126,14 +126,8 @@ namespace mongo { log() << "moving shard ns: " << _ns << " moving shard: " << toString() << " " << _server << " -> " << to << endl; string from = _server; - - lockNamespaceOnServer( from , _ns ); + ServerShardVersion oldVersion = _manager->getVersion( from ); - // copyCollection - ScopedDbConnection toconn( to ); - BSONObj cloneRes; - - BSONObj filter; { BSONObjBuilder b; @@ -141,17 +135,20 @@ namespace mongo { filter = b.obj(); } - bool worked = toconn->runCommand( _manager->_config->getName().c_str() , - BSON( "cloneCollection" << _ns << - "from" << from << - "query" << filter - ) , - cloneRes - ); + ScopedDbConnection fromconn( from ); + + BSONObj startRes; + bool worked = fromconn->runCommand( "admin" , + BSON( "moveshard.start" << _ns << + "from" << from << + "to" << to << + "filter" << filter + ) , + startRes + ); - toconn.done(); if ( ! worked ){ - errmsg = (string)"cloneCollection failed: " + cloneRes.toString(); + errmsg = (string)"moveshard.start failed: " + startRes.toString(); return false; } @@ -165,16 +162,29 @@ namespace mongo { _manager->save(); - // delete old data - ScopedDbConnection fromconn( from ); - fromconn->remove( _ns.c_str() , filter ); - string removeerror = fromconn->getLastError(); - fromconn.done(); - if ( removeerror.size() ){ - errmsg = (string)"error removing old data:" + removeerror; + BSONObj finishRes; + { + + ServerShardVersion newVersion = _manager->getVersion( from ); + uassert( "version has to be higher" , newVersion > oldVersion ); + + BSONObjBuilder b; + b << "moveshard.finish" << _ns; + b << "to" << to; + b.appendTimestamp( "newVersion" , newVersion ); + b.append( startRes["finishToken"] ); + + worked = fromconn->runCommand( "admin" , + b.done() , + finishRes ); + } + + if ( ! worked ){ + errmsg = (string)"moveshard.finish failed: " + finishRes.toString(); return false; } + fromconn.done(); return true; } |