Last active
December 19, 2015 00:39
-
-
Save renctan/5870664 to your computer and use it in GitHub Desktop.
Slightly modified test from SERVER-10015 (originally written by Greg)
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
// | |
// Tests whether the balancer continues with inconsistent chunks | |
// | |
var options = {separateConfig : true, sync : true}; | |
var st = new ShardingTest({shards : 2, mongos : 1, other : options}); | |
st.stopBalancer(); | |
var mongos = st.s; | |
var shards = mongos.getDB("config").shards.find().toArray(); | |
var lastConfig = st.config2; | |
var coll = mongos.getCollection("foo.bar"); | |
jsTest.log("Creating sharded connection..."); | |
assert(mongos.adminCommand({enableSharding : coll.getDB() + ""}).ok); | |
printjson(mongos.adminCommand({movePrimary : coll.getDB() + "", to : shards[0]._id})); | |
assert(mongos.adminCommand({shardCollection : coll + "", key : {_id : 1}}).ok); | |
jsTest.log("Splitting first chunks."); | |
for ( var i = 0; i < 20; i++) { | |
assert(mongos.adminCommand({split : coll + "", middle : {_id : i}}).ok); | |
} | |
var origChunks = mongos.getDB("config").chunks.find().toArray(); | |
printjson(mongos.getDB("config").chunks.find().toArray()); | |
printjson(lastConfig.getDB("config").chunks.find().toArray()); | |
jsTest.log("Moving chunk and rolling back only last config server."); | |
assert(mongos.adminCommand({moveChunk : coll + "", find : {_id : 0}, to : shards[1]._id}).ok); | |
lastConfig.getDB("config").chunks.remove(); | |
for ( var i = 0; i < origChunks.length; i++) { | |
lastConfig.getDB("config").chunks.insert(origChunks[i]); | |
} | |
assert.eq(null, lastConfig.getDB("config").getLastError()); | |
var moveChunksBefore = mongos.getDB("config").changelog.find({ what: 'moveChunk.start' }).count(); | |
// Wait for config checker to detect inconsistency. | |
sleep( 120 * 1000 ); | |
// Wait 30 seconds for the balancer to move chunks, if it is going to | |
st.startBalancer(); | |
sleep( 30 * 1000 ); | |
var moveChunksAfter = mongos.getDB("config").changelog.find({ what: 'moveChunk.start' }).count(); | |
// We should at most have tried to move one chunk with inconsistent data and realized the problem | |
// TODO: Better to not move at all, but potentially hard to check. | |
assert.eq(moveChunksBefore, moveChunksAfter); | |
st.stop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment