diff options
author | wenqinYe <wenqin908@gmail.com> | 2022-11-01 15:52:15 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-01 16:25:14 +0000 |
commit | 52622f9c3cc14aee28efcec2376fc06edb20ebdb (patch) | |
tree | 5a21e71cea5379807d572d6a9bc6ef905e02b387 /jstests/noPassthrough | |
parent | f9ce2b3836f6662587e27739948fdf0b839fca91 (diff) | |
download | mongo-52622f9c3cc14aee28efcec2376fc06edb20ebdb.tar.gz |
SERVER-70745 explain command for cluster delete results in error when on shardsvr mongod
Diffstat (limited to 'jstests/noPassthrough')
-rw-r--r-- | jstests/noPassthrough/cluster_explain_commands_not_supported.js | 87 | ||||
-rw-r--r-- | jstests/noPassthrough/cluster_explain_commands_require_cluster_node.js | 37 |
2 files changed, 87 insertions, 37 deletions
diff --git a/jstests/noPassthrough/cluster_explain_commands_not_supported.js b/jstests/noPassthrough/cluster_explain_commands_not_supported.js new file mode 100644 index 00000000000..3aa315382e3 --- /dev/null +++ b/jstests/noPassthrough/cluster_explain_commands_not_supported.js @@ -0,0 +1,87 @@ +/** + * Verify the explaining "cluster" versions of commands is not supported on any mongod + * + * @tags: [ + * requires_replication, + * requires_sharding, + * ] + */ +(function() { +"use strict"; + +const kDbName = "cluster_explain_commands"; +const kCollName = "bar"; + +const clusterCommandsCases = [ + {cmd: {explain: {clusterAggregate: kCollName, pipeline: [{$match: {}}], cursor: {}}}}, + {cmd: {explain: {clusterCount: "x"}}}, + {cmd: {explain: {clusterFind: kCollName}}}, + {cmd: {explain: {clusterInsert: kCollName, documents: [{x: 1}]}}}, + {cmd: {explain: {clusterUpdate: kCollName, updates: [{q: {doesNotExist: 1}, u: {x: 1}}]}}}, + {cmd: {explain: {clusterDelete: `${kCollName}`, deletes: [{q: {}, limit: 1}]}}} +]; + +function runTestCaseExpectFail(conn, testCase, code) { + assert.commandFailedWithCode( + conn.getDB(kDbName).runCommand(testCase.cmd), code, tojson(testCase.cmd)); +} + +// +// Cluster explain commands not supported on standalone mongods +// +{ + const standalone = MongoRunner.runMongod({}); + assert(standalone); + + for (let testCase of clusterCommandsCases) { + runTestCaseExpectFail(standalone, testCase, ErrorCodes.CommandNotSupported); + } + + MongoRunner.stopMongod(standalone); +} + +// +// Cluster explain commands not supported on replica set mongods +// +{ + const rst = new ReplSetTest({nodes: 1}); + rst.startSet(); + rst.initiate(); + + for (let testCase of clusterCommandsCases) { + runTestCaseExpectFail(rst.getPrimary(), testCase, ErrorCodes.CommandNotSupported); + } + + rst.stopSet(); +} + +{ + const st = new ShardingTest({mongos: 1, shards: 1, config: 1}); + + // + // Cluster explain commands do not exist on mongos. + // + + for (let testCase of clusterCommandsCases) { + runTestCaseExpectFail(st.s, testCase, ErrorCodes.CommandNotFound); + } + + // + // Cluster explain commands are not supported on a config server node. + // + + for (let testCase of clusterCommandsCases) { + runTestCaseExpectFail(st.configRS.getPrimary(), testCase, ErrorCodes.CommandNotSupported); + } + + // + // Cluster explain commands are not supported sharding enabled shardsvr. + // + + for (let testCase of clusterCommandsCases) { + runTestCaseExpectFail(st.rs0.getPrimary(), testCase, ErrorCodes.CommandNotSupported); + } + + st.stop(); +} +}()); diff --git a/jstests/noPassthrough/cluster_explain_commands_require_cluster_node.js b/jstests/noPassthrough/cluster_explain_commands_require_cluster_node.js deleted file mode 100644 index 5e009345d80..00000000000 --- a/jstests/noPassthrough/cluster_explain_commands_require_cluster_node.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Verify the explaining "cluster" versions of commands is rejected on a non shardsvr mongod. - * - * @tags: [ - * requires_replication, - * ] - */ -(function() { -"use strict"; - -const kDbName = "cluster_explain_commands"; -const kCollName = "bar"; -const rst = new ReplSetTest({nodes: 1}); -rst.startSet(); -rst.initiate(); - -const clusterCommandsCases = [ - {cmd: {explain: {clusterAggregate: kCollName, pipeline: [{$match: {}}], cursor: {}}}}, - {cmd: {explain: {clusterCount: "x"}}}, - {cmd: {explain: {clusterDelete: kCollName, deletes: [{q: {}, limit: 1}]}}}, - {cmd: {explain: {clusterFind: kCollName}}}, - {cmd: {explain: {clusterInsert: kCollName, documents: [{x: 1}]}}}, - {cmd: {explain: {clusterUpdate: kCollName, updates: [{q: {doesNotExist: 1}, u: {x: 1}}]}}}, - {cmd: {explain: {clusterDelete: `${kCollName}`, deletes: [{q: {}, limit: 1}]}}} -]; - -function runTestCaseExpectFail(conn, testCase, code) { - assert.commandFailedWithCode( - conn.getDB(kDbName).runCommand(testCase.cmd), code, tojson(testCase.cmd)); -} - -for (let testCase of clusterCommandsCases) { - runTestCaseExpectFail(rst.getPrimary(), testCase, ErrorCodes.ShardingStateNotInitialized); -} - -rst.stopSet(); -}()); |