Permalink
Browse files

cleaning split

  • Loading branch information...
1 parent 745cfbf commit 160d0b72013ec72ae0e00a95d6b21c5f5a014bb1 @erh erh committed Mar 30, 2009
Showing with 61 additions and 12 deletions.
  1. +6 −1 jstests/_runner_sharding.js
  2. +48 −9 s/commands.cpp
  3. +5 −1 s/shard.cpp
  4. +2 −1 s/shard.h
@@ -3,6 +3,8 @@
//
var files = listFiles("jstests/sharding");
+var num = 0;
+
files.forEach(
function(x) {
@@ -13,7 +15,10 @@ files.forEach(
return;
}
-
+ if ( num++ > 0 ){
+ sleep( 1000 ); // let things fully come down
+ }
+
print(" *******************************************");
print(" Test : " + x.name + " ...");
try {
View
@@ -260,24 +260,27 @@ namespace mongo {
}
} shardCmd;
-
- class SplitCollection : public GridAdminCmd {
+
+ class SplitCollectionHelper : public GridAdminCmd {
public:
- SplitCollection() : GridAdminCmd( "split" ){}
+ SplitCollectionHelper( const char * name ) : GridAdminCmd( name ){}
virtual void help( stringstream& help ) const {
help
<< " example: { shard : 'alleyinsider.blog.posts' , find : { ts : 1 } } - split the shard that contains give key \n"
<< " example: { shard : 'alleyinsider.blog.posts' , middle : { ts : 1 } } - split the shard that contains the key with this as the middle \n"
<< " NOTE: this does not move move the chunks, it merely creates a logical seperation \n"
;
}
+
+ virtual bool _split( BSONObjBuilder& result , string&errmsg , const string& ns , ShardManager * manager , Shard& old , BSONObj middle ) = 0;
+
bool run(const char *cmdns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
string ns = cmdObj["split"].valuestrsafe();
if ( ns.size() == 0 ){
errmsg = "no ns";
return false;
}
-
+
DBConfig * config = grid.getDBConfig( ns );
if ( ! config->sharded( ns ) ){
errmsg = "ns not sharded. have to shard before can split";
@@ -299,7 +302,43 @@ namespace mongo {
ShardManager * info = config->getShardManager( ns );
Shard& old = info->findShard( find );
- log() << "splitting: " << ns << " on: " << find << endl;
+
+ return _split( result , errmsg , ns , info , old , cmdObj.getObjectField( "middle" ) );
+ }
+
+ };
+
+ class SplitValueCommand : public SplitCollectionHelper {
+ public:
+ SplitValueCommand() : SplitCollectionHelper( "splitvalue" ){}
+ virtual bool _split( BSONObjBuilder& result , string& errmsg , const string& ns , ShardManager * manager , Shard& old , BSONObj middle ){
+
+ result << "shardinfo" << old.toString();
+
+ result.appendBool( "auto" , middle.isEmpty() );
+
+ if ( middle.isEmpty() ){
+
+ old.split();
+ }
+ else {
+ result.append( "middle" , middle );
+ }
+
+ result << "ok" << 1;
+ return true;
+ }
+
+
+ } splitValueCmd;
+
+
+ class SplitCollection : public SplitCollectionHelper {
+ public:
+ SplitCollection() : SplitCollectionHelper( "split" ){}
+ virtual bool _split( BSONObjBuilder& result , string& errmsg , const string& ns , ShardManager * manager , Shard& old , BSONObj middle ){
+
+ log() << "splitting: " << ns << " shard: " << old << endl;
unsigned long long nextTS = grid.getNextOpTime();
ScopedDbConnection conn( old.getServer() );
@@ -311,12 +350,12 @@ namespace mongo {
}
conn.done();
- if ( middle )
- old.split( cmdObj.getObjectField( "middle" ) );
- else
+ if ( middle.isEmpty() )
old.split();
+ else
+ old.split( middle );
- info->save();
+ manager->save();
result << "ok" << 1;
return true;
View
@@ -42,8 +42,12 @@ namespace mongo {
_manager->getShardKey().compare( obj , getMax() ) < 0;
}
+ BSONObj Shard::pickSplitPoint(){
+ return _manager->getShardKey().middle( getMin() , getMax() );
+ }
+
Shard * Shard::split(){
- return split( _manager->getShardKey().middle( getMin() , getMax() ) );
+ return split( pickSplitPoint() );
}
Shard * Shard::split( const BSONObj& m ){
View
@@ -64,13 +64,14 @@ namespace mongo {
operator string() const { return toString(); }
bool operator==(const Shard& s);
-
+
bool operator!=(const Shard& s){
return ! ( *this == s );
}
void getFilter( BSONObjBuilder& b );
+ BSONObj pickSplitPoint();
Shard * split();
Shard * split( const BSONObj& middle );

0 comments on commit 160d0b7

Please sign in to comment.