Skip to content

Instantly share code, notes, and snippets.

@derickson derickson/splitHelper.js
Last active Dec 24, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.