Last active
December 24, 2015 16:29
-
-
Save derickson/6828712 to your computer and use it in GitHub Desktop.
YCSB splittin code for mongodb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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