Files
mongo/jstests/sharding/split_against_shard_with_invalid_split_points.js
2019-07-27 11:02:23 -04:00

42 lines
1.4 KiB
JavaScript

// Tests that executing splitChunk directly against a shard, with an invalid split point will not
// corrupt the chunks metadata
(function() {
'use strict';
var st = new ShardingTest({shards: 1});
var testDB = st.s.getDB('TestSplitDB');
assert.commandWorked(testDB.adminCommand({enableSharding: 'TestSplitDB'}));
st.ensurePrimaryShard('TestSplitDB', st.shard0.shardName);
assert.commandWorked(testDB.adminCommand({shardCollection: 'TestSplitDB.Coll', key: {x: 1}}));
assert.commandWorked(testDB.adminCommand({split: 'TestSplitDB.Coll', middle: {x: 0}}));
var chunksBefore = st.s.getDB('config').chunks.find().toArray();
// Try to do a split with invalid parameters through mongod
var callSplit = function(db, minKey, maxKey, splitPoints) {
var res = assert.commandWorked(st.s.adminCommand({getShardVersion: 'TestSplitDB.Coll'}));
return db.runCommand({
splitChunk: 'TestSplitDB.Coll',
from: st.shard0.shardName,
min: minKey,
max: maxKey,
keyPattern: {x: 1},
splitKeys: splitPoints,
epoch: res.versionEpoch,
});
};
assert.commandFailedWithCode(
callSplit(st.rs0.getPrimary().getDB('admin'), {x: MinKey}, {x: 0}, [{x: 2}]),
ErrorCodes.InvalidOptions);
var chunksAfter = st.s.getDB('config').chunks.find().toArray();
assert.eq(chunksBefore,
chunksAfter,
'Split chunks failed, but the chunks were updated in the config database');
st.stop();
})();