Skip to content

Instantly share code, notes, and snippets.

@derickson
Last active December 24, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derickson/6828712 to your computer and use it in GitHub Desktop.
Save derickson/6828712 to your computer and use it in GitHub Desktop.
YCSB splittin code for mongodb
var ycsbUtil = {};
ycsbUtil.dropAndSplitYCSB = function (shardCount, chunksPerShard) {
db.getMongo().getDB( 'ycsb' ).dropDatabase();
db.adminCommand( { "enablesharding" : "ycsb" } ) ;
db.adminCommand( { "shardcollection" : "ycsb.usertable", "key" : { "_id" : 1 } } ) ;
var splitCount = shardCount * chunksPerShard;
var splitSize = Math.ceil( 10000 / splitCount; )
for(var i=1; i < splitCount; ++i){
var splitPoint = ('user' + ('00000' + (splitSize * i)).slice(-4) + '000000000000000' );
print( "Splitting at: "+ splitPoint);
var splitResult = sh.splitAt( "ycsb.usertable", {"_id": splitPoint });
while( !splitResult || !(splitResult.ok === 1)) {
print("issue while splitting, probably a metadata lock. Retrying in a few seconds");
sleep(3000);
print( "Retry Splitting at: "+ splitPoint);
splitResult = sh.splitAt( "ycsb.usertable", {"_id": splitPoint });
}
sleep(3000);
}
return sh.status(true);
};
ycsbUtil.dropAndSplitYCSB( 8, 2 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment