summaryrefslogtreecommitdiff
path: root/jstests/sharding/analyze_shard_key_basic.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/sharding/analyze_shard_key_basic.js')
-rw-r--r--jstests/sharding/analyze_shard_key_basic.js53
1 files changed, 29 insertions, 24 deletions
diff --git a/jstests/sharding/analyze_shard_key_basic.js b/jstests/sharding/analyze_shard_key_basic.js
index 5f134efacc0..aa584bda0e9 100644
--- a/jstests/sharding/analyze_shard_key_basic.js
+++ b/jstests/sharding/analyze_shard_key_basic.js
@@ -35,11 +35,13 @@ function runTestNonExistingNs(conn, ns, key) {
const st = new ShardingTest({shards: 2, rs: {nodes: 2}});
const dbName = "testDb";
+ const shardedNs = dbName + ".shardedColl";
+ const unshardedNs = dbName + ".unshardedColl";
const nonExistingNs = dbName + ".nonExistingColl";
- const candidateKeyWithIndex = {candidateKey: 1};
- const candidateKeyWithoutIndex = {candidateKey: "hashed"}; // does not have a supporting index.
+ const candidateKey0 = {candidateKey0: 1};
+ const candidateKey1 = {candidateKey1: 1}; // does not have a supporting index.
- const shardedNs = dbName + ".shardedColl";
+ // Set up the sharded collection.
const currentKey = {currentKey: 1};
const currentKeySplitPoint = {currentKey: 0};
assert.commandWorked(st.s.adminCommand({enableSharding: dbName}));
@@ -48,44 +50,46 @@ function runTestNonExistingNs(conn, ns, key) {
assert.commandWorked(st.s.adminCommand({split: shardedNs, middle: currentKeySplitPoint}));
assert.commandWorked(st.s.adminCommand(
{moveChunk: shardedNs, find: currentKeySplitPoint, to: st.shard1.shardName}));
- assert.commandWorked(st.s.getCollection(shardedNs).createIndex(candidateKeyWithIndex));
+ assert.commandWorked(st.s.getCollection(shardedNs).createIndex(candidateKey0));
- const unshardedNs = dbName + ".unshardedColl";
- assert.commandWorked(st.s.getCollection(unshardedNs).createIndex(candidateKeyWithIndex));
+ // Set up the unsharded collection.
+ assert.commandWorked(st.s.getCollection(unshardedNs).createIndex(candidateKey0));
- // Verify that the command is supported on all shardsvr mongods (both primary and secondary).
- function runTestSupported(conn, isPrimaryShard) {
- // Can evaluate candidate shard keys for an existing unsharded collection.
- if (isPrimaryShard) {
- runTestExistingNs(conn, unshardedNs, candidateKeyWithIndex, candidateKeyWithoutIndex);
+ // Verify that the command is supported on mongos and all shardsvr mongods (both primary and
+ // secondary).
+ function runTestSupported(conn, isPrimaryShardOrMongos) {
+ // Can evaluate a candidate shard key for an unsharded collection.
+ if (isPrimaryShardOrMongos) {
+ runTestExistingNs(conn, unshardedNs, candidateKey0, candidateKey1);
} else {
- runTestNonExistingNs(conn, unshardedNs, candidateKeyWithIndex);
+ runTestNonExistingNs(conn, unshardedNs, candidateKey0);
}
// Can evaluate the current shard key for an existing sharded collection.
runTestExistingNs(conn, shardedNs, currentKey);
// Can evaluate candidate shard keys for an existing sharded collection.
- runTestExistingNs(conn, shardedNs, candidateKeyWithIndex, candidateKeyWithoutIndex);
+ runTestExistingNs(conn, shardedNs, candidateKey0, candidateKey1);
// Cannot evaluate a candidate shard key for a non-existing collection.
- runTestNonExistingNs(conn, nonExistingNs, candidateKeyWithIndex);
+ runTestNonExistingNs(conn, nonExistingNs, candidateKey0);
}
+ runTestSupported(st.s, true /* isPrimaryShardOrMongos */);
st.rs0.nodes.forEach(node => {
- runTestSupported(node, true /* isPrimaryShard */);
+ runTestSupported(node, true /* isPrimaryShardOrMongos */);
});
st.rs1.nodes.forEach(node => {
- runTestSupported(node, false /* isPrimaryShard */);
+ runTestSupported(node, false /* isPrimaryShardOrMongos */);
});
// Verify that the command is not supported on configsvr mongods.
function runTestNotSupported(conn) {
assert.commandFailedWithCode(
- conn.adminCommand({analyzeShardKey: unshardedNs, key: candidateKeyWithIndex}),
+ conn.adminCommand({analyzeShardKey: unshardedNs, key: candidateKey0}),
ErrorCodes.IllegalOperation);
assert.commandFailedWithCode(
conn.adminCommand({analyzeShardKey: shardedNs, key: currentKey}),
ErrorCodes.IllegalOperation);
assert.commandFailedWithCode(
- conn.adminCommand({analyzeShardKey: shardedNs, key: candidateKeyWithIndex}),
+ conn.adminCommand({analyzeShardKey: shardedNs, key: candidateKey0}),
ErrorCodes.IllegalOperation);
}
@@ -103,19 +107,20 @@ function runTestNonExistingNs(conn, ns, key) {
const primary = rst.getPrimary();
const dbName = "testDb";
+ const unshardedNs = dbName + ".unshardedColl";
const nonExistingNs = dbName + ".nonExistingColl";
- const candidateKey = {candidateKey: 1};
- const invalidCandidateKey = {candidateKey: "hashed"}; // does not have a supporting index.
+ const candidateKey0 = {candidateKey0: 1};
+ const candidateKey1 = {candidateKey1: 1}; // does not have a supporting index.
- const unshardedNs = dbName + ".unshardedColl";
- assert.commandWorked(primary.getCollection(unshardedNs).createIndex(candidateKey));
+ // Set up the unsharded collection.
+ assert.commandWorked(primary.getCollection(unshardedNs).createIndex(candidateKey0));
// Verify that the command is supported on all mongods (both primary and secondary).
function runTestSupported(conn) {
// Can evaluate a candidate shard key for an existing unsharded collection.
- runTestExistingNs(conn, unshardedNs, candidateKey, invalidCandidateKey);
+ runTestExistingNs(conn, unshardedNs, candidateKey0, candidateKey1);
// Cannot evaluate a candidate shard key for a non-existing collection.
- runTestNonExistingNs(conn, nonExistingNs, candidateKey);
+ runTestNonExistingNs(conn, nonExistingNs, candidateKey0);
}
rst.nodes.forEach(node => {
runTestSupported(node);