-
-
Save cheahuychou/d36b339b26b6777e4910f19d4f29b690 to your computer and use it in GitHub Desktop.
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 that chunks with UUID shard key created in 3.4 can be moved in later versions. | |
*/ | |
(function() { | |
"use strict"; | |
load('jstests/multiVersion/libs/multi_rs.js'); | |
load('jstests/multiVersion/libs/multi_cluster.js'); | |
load('jstests/sharding/autosplit_include.js'); | |
TestData.skipCheckingUUIDsConsistentAcrossCluster = true; | |
TestData.skipCheckingIndexesConsistentAcrossCluster = true; | |
TestData.skipCheckOrphans = true; | |
/* | |
* Prints out the chunks for the given namespace. | |
*/ | |
function checkChunks(ns) { | |
const chunks = st.s.getDB("config").chunks.find({ns: ns}).toArray(); | |
jsTest.log("All chunks " + tojson(chunks)); | |
} | |
/* | |
* Upgrades the entire cluster to the given binVersion and waits for config server and shards | |
* to become available and for the replica set monitors on the mongos and each shard to reflect | |
* the state of all shards. | |
*/ | |
function upgradeCluster(binVersion) { | |
st.stopBalancer(); | |
st.upgradeCluster( | |
binVersion, | |
{upgradeMongos: true, upgradeConfigs: true, upgradeShards: true, waitUntilStable: true}); | |
st.s.adminCommand({setFeatureCompatibilityVersion: binVersion}); | |
st.restartMongoses(); | |
} | |
/* | |
* Creates a sharded collection with the given collection name in the database kDbName with the | |
* shard key kShardKey. Inserts kNumDocs 1 KB docs with a UUID field into the collection, and waits | |
* for the balancer to split and distribute the initial chunks. | |
*/ | |
function setUpChunks(collName) { | |
const ns = kDbName + "." + collName; | |
jsTest.log(`Setting up sharded collection ${ns}`); | |
assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: kShardKey})); | |
checkChunks(ns); | |
jsTest.log(`Inserting docs for ${ns}`); | |
const doc1k = (new Array(1024)).join('x'); | |
for (let x = 0; x < kNumDocs; x++) { | |
assert.commandWorked(st.s.getDB(kDbName).runCommand({ | |
insert: collName, | |
documents: [{x: UUID(), v: doc1k}], | |
ordered: false, | |
writeConcern: {w: 1} | |
})); | |
} | |
jsTest.log(`Wait for autosplitter to split the chunk for ${ns}`); | |
waitForOngoingChunkSplits(st); | |
checkChunks(ns); | |
return ns; | |
} | |
jsTest.log("Start a 3.4 sharded cluster"); | |
const st = new ShardingTest({ | |
shards: 2, | |
mongos: 1, | |
config: {nodes: 1}, | |
other: { | |
chunkSize: 1, | |
enableAutoSplit: true, | |
mongosOptions: {binVersion: "3.4"}, | |
configOptions: {binVersion: "3.4"}, | |
shardOptions: {binVersion: "3.4"}, | |
rsOptions: {binVersion: "3.4"}, | |
rs: true, | |
} | |
}); | |
const kDbName = "foo"; | |
const kCollName = "bar"; | |
const kShardKey = { | |
x: 1 | |
}; | |
const kNumDocs = 1500; | |
assert.commandWorked(st.s.adminCommand({enableSharding: kDbName})); | |
st.ensurePrimaryShard(kDbName, st.shard0.shardName); | |
const collName34 = kCollName + "34"; | |
const ns = setUpChunks(collName34); | |
const chunkToMove = st.s.getDB("config").chunks.findOne( | |
{ns: ns, shard: st.shard0.shardName, min: {$ne: {x: MinKey}}}); | |
jsTest.log("3.4 chunk to move" + tojson(chunkToMove)); | |
// Example: | |
// { | |
// "_id" : "foo.bar34-x_BinData(4, EDA0569058014FF7963CCD1417AE9F01)", | |
// "lastmod" : Timestamp(1, 3), | |
// "lastmodEpoch" : ObjectId("5ea098b9eb65a3598e36a0b5"), | |
// "ns" : "foo.bar34", | |
// "min" : { | |
// "x" : UUID("eda05690-5801-4ff7-963c-cd1417ae9f01") | |
// }, | |
// "max" : { | |
// "x" : { "$maxKey" : 1 } | |
// }, | |
// "shard" : "move_chunk_UUID_shard_key-rs0" | |
// } | |
(() => { | |
jsTest.log("Upgrading cluster to 3.6"); | |
upgradeCluster("3.6"); | |
jsTest.log("Moving the 3.4 chunk after upgrading to 3.6"); | |
assert.commandFailedWithCode( | |
st.s.adminCommand({moveChunk: ns, find: chunkToMove.min, to: st.shard1.shardName}), | |
ErrorCodes.DuplicateKey); | |
// User Assertion: 11000:Chunk move was not successful due to E11000 duplicate key error | |
// collection: config.chunks index: ns_1_min_1 dup key: { : "foo.bar34", : { x: | |
// UUID("eda05690-5801-4ff7-963c-cd1417ae9f01") } } | |
// src/mongo/s/commands/cluster_move_chunk_cmd.cpp 193 | |
checkChunks(ns); | |
})(); | |
(() => { | |
jsTest.log("Upgrading cluster to 4.0"); | |
upgradeCluster("4.0"); | |
jsTest.log("Moving the 3.4 chunk after upgrading to 4.0"); | |
assert.commandFailedWithCode( | |
st.s.adminCommand({moveChunk: ns, find: chunkToMove.min, to: st.shard1.shardName}), | |
ErrorCodes.IncompatibleShardingMetadata); | |
// User Assertion: IncompatibleShardingMetadata: Chunk move was not successful :: caused by :: | |
// Tried to find the chunk for 'foo.bar34-x_UUID("eda05690-5801-4ff7-963c-cd1417ae9f01"), but | |
// found no chunks src/mongo/s/commands/cluster_move_chunk_cmd.cpp 198 | |
checkChunks(ns); | |
})(); | |
(() => { | |
jsTest.log("Upgrading cluster to 4.2"); | |
upgradeCluster("4.2"); | |
jsTest.log("Moving the 3.4 chunk after upgrading to 4.2"); | |
assert.commandFailedWithCode( | |
st.s.adminCommand({moveChunk: ns, find: chunkToMove.min, to: st.shard1.shardName}), | |
ErrorCodes.IncompatibleShardingMetadata); | |
// User Assertion: IncompatibleShardingMetadata: Chunk move was not successful :: caused by :: | |
// Tried to find the chunk for 'foo.bar34-x_UUID("eda05690-5801-4ff7-963c-cd1417ae9f01"), but | |
// found no chunks src/mongo/s/commands/cluster_move_chunk_cmd.cpp 195 | |
checkChunks(ns); | |
})(); | |
st.stop(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment