summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjannaerin <golden.janna@gmail.com>2019-01-14 13:54:36 -0500
committerjannaerin <golden.janna@gmail.com>2019-01-14 17:57:06 -0500
commitaaec89134a7ce96573f06d48307a244cb1da6733 (patch)
treeb452116ab8e9ad41014c9a16556bd7a5931c8161
parent29efd5d05db9caab8c8812a83b6692e2e29b5f39 (diff)
downloadmongo-aaec89134a7ce96573f06d48307a244cb1da6733.tar.gz
SERVER-38734 Config collections other than config.system.sessions should not be allowed to be sharded
-rw-r--r--buildscripts/resmokeconfig/suites/sharding_auth.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/sharding_auth_audit.yml2
-rw-r--r--buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml3
-rw-r--r--jstests/sharding/shard_config_db_collections.js127
-rw-r--r--src/mongo/db/s/config/configsvr_shard_collection_command.cpp2
5 files changed, 6 insertions, 130 deletions
diff --git a/buildscripts/resmokeconfig/suites/sharding_auth.yml b/buildscripts/resmokeconfig/suites/sharding_auth.yml
index 0404938d735..59c7a2b23a5 100644
--- a/buildscripts/resmokeconfig/suites/sharding_auth.yml
+++ b/buildscripts/resmokeconfig/suites/sharding_auth.yml
@@ -16,8 +16,6 @@ selector:
- jstests/sharding/kill_sessions.js
# Skip these additional tests when running with auth enabled.
- jstests/sharding/parallel.js
- # Skip these tests that run with enableTestCommands off.
- - jstests/sharding/shard_config_db_collections.js
# Skip the testcases that do not have auth bypass when running ops in parallel.
- jstests/sharding/cleanup_orphaned_cmd_during_movechunk.js # SERVER-21713
- jstests/sharding/cleanup_orphaned_cmd_during_movechunk_hashed.js # SERVER-21713
diff --git a/buildscripts/resmokeconfig/suites/sharding_auth_audit.yml b/buildscripts/resmokeconfig/suites/sharding_auth_audit.yml
index 8329ba32ce1..2dc7f335c54 100644
--- a/buildscripts/resmokeconfig/suites/sharding_auth_audit.yml
+++ b/buildscripts/resmokeconfig/suites/sharding_auth_audit.yml
@@ -16,8 +16,6 @@ selector:
- jstests/sharding/kill_sessions.js
# Skip these additional tests when running with auth enabled.
- jstests/sharding/parallel.js
- # Skip these tests that run with enableTestCommands off.
- - jstests/sharding/shard_config_db_collections.js
# Skip the testcases that do not have auth bypass when running ops in parallel.
- jstests/sharding/cleanup_orphaned_cmd_during_movechunk.js # SERVER-21713
- jstests/sharding/cleanup_orphaned_cmd_during_movechunk_hashed.js # SERVER-21713
diff --git a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml
index ba64310425d..de2b7f8eec6 100644
--- a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml
+++ b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml
@@ -54,6 +54,7 @@ selector:
- jstests/sharding/out_write_concern.js
- jstests/sharding/restart_transactions.js
- jstests/sharding/shard7.js
+ - jstests/sharding/shard_config_db_collections.js
# TODO: SERVER-38541 remove from blacklist
- jstests/sharding/shard_collection_existing_zones.js
- jstests/sharding/single_shard_transaction_with_arbiter.js
@@ -85,7 +86,7 @@ selector:
- jstests/sharding/shard_existing_coll_chunk_count.js
- jstests/sharding/wildcard_index_banned_for_shard_key.js
- jstests/sharding/unsharded_lookup_in_txn.js
-# Enable if SERVER-20865 is backported or 4.2 becomes last-stable
+ # Enable if SERVER-20865 is backported or 4.2 becomes last-stable
- jstests/sharding/sharding_statistics_server_status.js
# Enable if SERVER-36966 is backported or 4.2 becomes last-stable
- jstests/sharding/mr_output_sharded_validation.js
diff --git a/jstests/sharding/shard_config_db_collections.js b/jstests/sharding/shard_config_db_collections.js
index 3a2e3f0590e..73e711946c1 100644
--- a/jstests/sharding/shard_config_db_collections.js
+++ b/jstests/sharding/shard_config_db_collections.js
@@ -1,10 +1,6 @@
(function() {
'use strict';
- function assertNoChunksOnConfig() {
- assert.eq(0, config.chunks.count({"shard": "config"}));
- }
-
// Database-level tests
{
var st = new ShardingTest({shards: 2});
@@ -27,132 +23,15 @@
st.stop();
}
- // Collection-level tests
- {
- var st = new ShardingTest({shards: 2});
- var config = st.s.getDB('config');
- var admin = st.s.getDB('admin');
-
- // Test that we can shard an empty collection in the config db
- assert.commandWorked(admin.runCommand({shardCollection: 'config.sharded', key: {_id: 1}}));
- assertNoChunksOnConfig();
-
- // Test that we cannot shard a collection in 'config' that holds data
- assert.writeOK(config.withdata.insert({a: 1}));
- assert.commandFailed(admin.runCommand({shardCollection: 'config.withdata', key: {_id: 1}}));
-
- // Test that we cannot specify an initial number of chunks,
- // because our shard key is not hashed.
- assert.commandFailed(admin.runCommand(
- {shardCollection: 'config.numchunks', key: {_id: 1}, numInitialChunks: 10}));
- assertNoChunksOnConfig();
-
- // Test that we cannot re-shard the same collection
- assert.commandFailed(admin.runCommand({shardCollection: 'config.sharded', key: {a: 1}}));
- assertNoChunksOnConfig();
-
- // Test that we can drop a sharded collection in config
- assert.commandWorked(admin.runCommand({shardCollection: 'config.todrop', key: {_id: 1}}));
- config.todrop.insert({a: 1});
- assertNoChunksOnConfig();
- assert(config.todrop.drop());
- assert.eq(0, config.chunks.count({"ns": "config.todrop"}));
- assert.eq(0, config.todrop.count());
-
- // Test that we can drop a non-sharded collection in config
- config.newcoll.insert({a: 1});
- assert(config.newcoll.drop());
- assert.eq(0, config.newcoll.count());
- assertNoChunksOnConfig();
-
- st.stop();
- }
-
- // CRUD operations on sharded collections in config
- {
- var st = new ShardingTest({shards: 2});
- var config = st.s.getDB('config');
- var admin = st.s.getDB('admin');
-
- assert.commandWorked(admin.runCommand({shardCollection: 'config.sharded', key: {_id: 1}}));
- assertNoChunksOnConfig();
-
- // Insertion and retrieval
- assert.commandWorked(st.splitAt("config.sharded", {_id: 0}));
- assert.commandWorked(admin.runCommand(
- {moveChunk: "config.sharded", find: {_id: -10}, to: st.shard0.shardName}));
- assert.commandWorked(admin.runCommand(
- {moveChunk: "config.sharded", find: {_id: 10}, to: st.shard1.shardName}));
-
- assert.writeOK(config.sharded.insert({_id: -10}));
- assert.writeOK(config.sharded.insert({_id: 10}));
- assert.eq({_id: -10}, config.sharded.findOne({_id: -10}));
- assert.eq({_id: 10}, config.sharded.findOne({_id: 10}));
-
- var shard0000 = st._connections[0].getDB("config");
- var shard0001 = st._connections[1].getDB("config");
- assert.eq({_id: -10}, shard0000.sharded.findOne());
- assert.eq({_id: 10}, shard0001.sharded.findOne());
-
- assert.eq(2, config.sharded.count());
-
- for (var i = 0; i < 100; i++) {
- assert.writeOK(config.sharded.insert({a: i}));
- }
-
- // Updates
- assert.writeOK(config.sharded.update({_id: 10}, {$set: {a: 15}}));
- assert.writeOK(config.sharded.update({_id: 10}, {$set: {a: 20}}));
-
- // Deletes
- assert.writeOK(config.sharded.remove({_id: 10}));
- assert.writeOK(config.sharded.remove({a: {$gt: 50}}));
-
- // Make an index
- assert.commandWorked(config.sharded.createIndex({a: 1}));
-
- st.stop();
- }
-
- // Chunk-level operations
- {
- var st = new ShardingTest({shards: 2});
- var config = st.s.getDB('config');
- var admin = st.s.getDB('admin');
-
- assert.commandWorked(admin.runCommand({shardCollection: 'config.sharded', key: {_id: 1}}));
- assertNoChunksOnConfig();
-
- // Test that we can split chunks
- assert.commandWorked(st.splitAt("config.sharded", {_id: 10}));
- assert.commandWorked(st.splitAt("config.sharded", {_id: 100}));
- assert.commandWorked(st.splitAt("config.sharded", {_id: 1000}));
- assertNoChunksOnConfig();
-
- // Try to move a chunk to config shard, should fail
- assert.commandFailed(
- admin.runCommand({moveChunk: "config.sharded", find: {_id: 40}, to: "config"}));
- assertNoChunksOnConfig();
-
- // Test that we can move chunks between two non-config shards
- assert.commandWorked(admin.runCommand(
- {moveChunk: "config.sharded", find: {_id: 40}, to: st.shard1.shardName}));
- assert.commandWorked(admin.runCommand(
- {moveChunk: "config.sharded", find: {_id: 40}, to: st.shard0.shardName}));
- assertNoChunksOnConfig();
-
- st.stop();
- }
-
- // When test commands are not enabled, only system.sessions may be sharded.
+ // Test that only system.sessions may be sharded.
{
- jsTest.setOption('enableTestCommands', false);
-
var st = new ShardingTest({shards: 2});
var admin = st.s.getDB('admin');
assert.commandWorked(
admin.runCommand({shardCollection: "config.system.sessions", key: {_id: 1}}));
+ assert.eq(0, st.s.getDB('config').chunks.count({"shard": "config"}));
+
assert.commandFailed(
admin.runCommand({shardCollection: "config.anythingelse", key: {_id: 1}}));
diff --git a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp
index 783076baa50..433c655cb46 100644
--- a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp
+++ b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp
@@ -658,7 +658,7 @@ public:
// Only whitelisted collections in config may be sharded (unless we are in test mode)
uassert(ErrorCodes::IllegalOperation,
"only special collections in the config db may be sharded",
- nss == NamespaceString::kLogicalSessionsNamespace || getTestCommandsEnabled());
+ nss == NamespaceString::kLogicalSessionsNamespace);
auto configShard = uassertStatusOK(shardRegistry->getShard(opCtx, dbType.getPrimary()));
ScopedDbConnection configConn(configShard->getConnString());