0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-24 00:17:37 +01:00
mongodb/jstests/sharding/merge_chunks_test_with_md_ops.js
Matt Broadstone 771dabd098 SERVER-81339 Convert ReplSetTest and ShardingTest to modules (#26332)
GitOrigin-RevId: 744aa110a53786b23c62ff53f87a1418b5991e8d
2024-08-20 22:00:49 +00:00

52 lines
1.7 KiB
JavaScript

// Tests that merging chunks does not prevent cluster from doing other metadata ops
import {ShardingTest} from "jstests/libs/shardingtest.js";
var st = new ShardingTest({shards: 2});
var mongos = st.s0;
var admin = mongos.getDB("admin");
const kDbName = "foo";
assert.commandWorked(
admin.runCommand({enableSharding: kDbName + "", primaryShard: st.shard0.shardName}));
var coll = mongos.getCollection(kDbName + ".bar");
assert.commandWorked(admin.runCommand({shardCollection: coll + "", key: {_id: 1}}));
st.printShardingStatus();
// Split and merge the first chunk repeatedly
jsTest.log("Splitting and merging repeatedly...");
for (var i = 0; i < 5; i++) {
assert.commandWorked(admin.runCommand({split: coll + "", middle: {_id: i}}));
assert.commandWorked(
admin.runCommand({mergeChunks: coll + "", bounds: [{_id: MinKey}, {_id: MaxKey}]}));
printjson(mongos.getDB("config").chunks.find().toArray());
}
// Move the first chunk to the other shard
jsTest.log("Moving to another shard...");
assert.commandWorked(
admin.runCommand({moveChunk: coll + "", find: {_id: 0}, to: st.shard1.shardName}));
// Split and merge the chunk repeatedly
jsTest.log("Splitting and merging repeatedly (again)...");
for (var i = 0; i < 5; i++) {
assert.commandWorked(admin.runCommand({split: coll + "", middle: {_id: i}}));
assert.commandWorked(
admin.runCommand({mergeChunks: coll + "", bounds: [{_id: MinKey}, {_id: MaxKey}]}));
printjson(mongos.getDB("config").chunks.find().toArray());
}
// Move the chunk back to the original shard
jsTest.log("Moving to original shard...");
assert.commandWorked(
admin.runCommand({moveChunk: coll + "", find: {_id: 0}, to: st.shard0.shardName}));
st.printShardingStatus();
st.stop();