mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-24 00:17:37 +01:00
771dabd098
GitOrigin-RevId: 744aa110a53786b23c62ff53f87a1418b5991e8d
66 lines
2.4 KiB
JavaScript
66 lines
2.4 KiB
JavaScript
/**
|
|
* Tests the collectionUUID parameter of the collMod command when one collection is sharded and the
|
|
* other collection is unsharded.
|
|
*
|
|
* @tags: [
|
|
* requires_fcv_60,
|
|
* ]
|
|
*/
|
|
import {ShardingTest} from "jstests/libs/shardingtest.js";
|
|
|
|
const st = new ShardingTest({shards: 2});
|
|
const mongos = st.s;
|
|
|
|
const db = mongos.getDB(jsTestName());
|
|
assert.commandWorked(
|
|
mongos.adminCommand({enableSharding: db.getName(), primaryShard: st.shard0.name}));
|
|
|
|
const shardedColl = db.sharded;
|
|
const unshardedColl = db.unsharded;
|
|
|
|
assert.commandWorked(shardedColl.insert({_id: 0}));
|
|
assert.commandWorked(shardedColl.insert({_id: 1}));
|
|
assert.commandWorked(unshardedColl.insert({_id: 2}));
|
|
|
|
const uuid = function(coll) {
|
|
return assert.commandWorked(db.runCommand({listCollections: 1}))
|
|
.cursor.firstBatch.find(c => c.name === coll.getName())
|
|
.info.uuid;
|
|
};
|
|
|
|
assert.commandWorked(
|
|
mongos.adminCommand({shardCollection: shardedColl.getFullName(), key: {_id: 1}}));
|
|
|
|
// Move {_id: 0} to shard0 and {_id: 1} to shard1.
|
|
assert.commandWorked(st.splitAt(shardedColl.getFullName(), {_id: 1}));
|
|
assert.commandWorked(mongos.adminCommand(
|
|
{moveChunk: shardedColl.getFullName(), find: {_id: 0}, to: st.shard0.shardName}));
|
|
assert.commandWorked(mongos.adminCommand(
|
|
{moveChunk: shardedColl.getFullName(), find: {_id: 1}, to: st.shard1.shardName}));
|
|
|
|
// Run the command on the collection which is sharded, while specifying the UUID of the unsharded
|
|
// collection that exists only on shard0.
|
|
let res = assert.commandFailedWithCode(db.runCommand({
|
|
collMod: shardedColl.getName(),
|
|
collectionUUID: uuid(unshardedColl),
|
|
}),
|
|
ErrorCodes.CollectionUUIDMismatch);
|
|
assert.eq(res.db, db.getName());
|
|
assert.eq(res.collectionUUID, uuid(unshardedColl));
|
|
assert.eq(res.expectedCollection, shardedColl.getName());
|
|
assert.eq(res.actualCollection, unshardedColl.getName());
|
|
|
|
// Run the command on the collection which is unsharded and exists only on shard0, while specifying
|
|
// the UUID of the collection that is sharded.
|
|
res = assert.commandFailedWithCode(db.runCommand({
|
|
collMod: unshardedColl.getName(),
|
|
collectionUUID: uuid(shardedColl),
|
|
}),
|
|
ErrorCodes.CollectionUUIDMismatch);
|
|
assert.eq(res.db, db.getName());
|
|
assert.eq(res.collectionUUID, uuid(shardedColl));
|
|
assert.eq(res.expectedCollection, unshardedColl.getName());
|
|
assert.eq(res.actualCollection, shardedColl.getName());
|
|
|
|
st.stop();
|