summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-04-03 14:24:20 -0400
committerAaron <aaron@10gen.com>2009-04-03 14:24:20 -0400
commit3fbb785b96333b8ba9a6371cda4dc339859a54d4 (patch)
treeffba1151108f02a43449281ef269d5092776f582
parent28a140ee8cf327cc69b3e9427cd4c2bb1527c5ad (diff)
parent5d81abc69044aa62241524fa3e7ee3c9aed2fbb1 (diff)
downloadmongo-3fbb785b96333b8ba9a6371cda4dc339859a54d4.tar.gz
Merge branch 'master' of git@github.com:mongodb/mongo
-rw-r--r--s/commands.cpp48
-rw-r--r--s/shard.cpp54
-rw-r--r--s/shard.h2
3 files changed, 57 insertions, 47 deletions
diff --git a/s/commands.cpp b/s/commands.cpp
index 80c64272372..3b58628606d 100644
--- a/s/commands.cpp
+++ b/s/commands.cpp
@@ -408,54 +408,8 @@ namespace mongo {
return false;
}
- log() << "ns: " << ns << " moving shard: " << s << " to: " << to << endl;
-
- // copyCollection
- ScopedDbConnection toconn( to );
- BSONObj cloneRes;
-
-
- BSONObj filter;
- {
- BSONObjBuilder b;
- s.getFilter( b );
- filter = b.obj();
- }
-
- bool worked = toconn->runCommand( config->getName().c_str() ,
- BSON( "cloneCollection" << ns <<
- "from" << from <<
- "query" << filter
- ) ,
- cloneRes
- );
-
- toconn.done();
- if ( ! worked ){
- errmsg = (string)"cloneCollection failed: " + cloneRes.toString();
+ if ( ! s.moveAndCommit( to , errmsg ) )
return false;
- }
-
- // update config db
- s.setServer( to );
-
- // need to increment version # for old server
- Shard * randomShardOnOldServer = info->findShardOnServer( from );
- if ( randomShardOnOldServer )
- randomShardOnOldServer->_markModified();
-
- info->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;
- return false;
- }
-
result << "ok" << 1;
return true;
diff --git a/s/shard.cpp b/s/shard.cpp
index 0ea0e906ca5..27c44f3727c 100644
--- a/s/shard.cpp
+++ b/s/shard.cpp
@@ -120,6 +120,60 @@ namespace mongo {
return s;
}
+
+ bool Shard::moveAndCommit( const string& to , string& errmsg ){
+ log() << "moving shard ns: " << _ns << " moving shard: " << toString() << " " << _server << " -> " << to << endl;
+
+ string from = _server;
+
+ // copyCollection
+ ScopedDbConnection toconn( to );
+ BSONObj cloneRes;
+
+
+ BSONObj filter;
+ {
+ BSONObjBuilder b;
+ getFilter( b );
+ filter = b.obj();
+ }
+
+ bool worked = toconn->runCommand( _manager->_config->getName().c_str() ,
+ BSON( "cloneCollection" << _ns <<
+ "from" << from <<
+ "query" << filter
+ ) ,
+ cloneRes
+ );
+
+ toconn.done();
+ if ( ! worked ){
+ errmsg = (string)"cloneCollection failed: " + cloneRes.toString();
+ return false;
+ }
+
+ // update config db
+ setServer( to );
+
+ // need to increment version # for old server
+ Shard * randomShardOnOldServer = _manager->findShardOnServer( from );
+ if ( randomShardOnOldServer )
+ randomShardOnOldServer->_markModified();
+
+ _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;
+ return false;
+ }
+
+ return true;
+ }
bool Shard::operator==( const Shard& s ){
return
diff --git a/s/shard.h b/s/shard.h
index 8aaca9b5c29..1c6aca70f4d 100644
--- a/s/shard.h
+++ b/s/shard.h
@@ -74,6 +74,8 @@ namespace mongo {
BSONObj pickSplitPoint();
Shard * split();
Shard * split( const BSONObj& middle );
+
+ bool moveAndCommit( const string& to , string& errmsg );
virtual const char * getNS(){ return "config.shard"; }
virtual void serialize(BSONObjBuilder& to);