[SERVER-10908] Sanity check for adding config server as shard server never runs Created: 25/Sep/13  Updated: 11/Jul/16  Resolved: 04/Oct/13

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 2.5.2
Fix Version/s: 2.5.3

Type: Bug Priority: Major - P3
Reporter: Phillip Quiza Assignee: Randolph Tan
Resolution: Done Votes: 0
Labels: 26qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Operating System: ALL
Steps To Reproduce:

Run this bash script to start up a shard cluster with one config server. The last command adds a config server as a shard and succeeds.

#!/bin/bash
 
DATA_DIR=/data/db
TEST_PREFIX='addShard-'
MONGO_BIN_DIR=''
 
pushd $DATA_DIR
 
echo Deleting old directories
rm -rf "$TEST_PREFIX"shard* "$TEST_PREFIX"config* "$TEST_PREFIX"mongos* "$TEST_PREFIX"config_backup* "$TEST_PREFIX"dump*
 
echo Creating directories
mkdir "$TEST_PREFIX"shard0; touch "$TEST_PREFIX"shard0/log
mkdir "$TEST_PREFIX"shard1; touch "$TEST_PREFIX"shard1/log
mkdir "$TEST_PREFIX"config1; touch "$TEST_PREFIX"config1/log
mkdir "$TEST_PREFIX"config2; touch "$TEST_PREFIX"config2/log
mkdir "$TEST_PREFIX"mongos; touch "$TEST_PREFIX"mongos/mongos.log
mkdir "$TEST_PREFIX"config_backup; touch "$TEST_PREFIX"config_backup/log
 
echo Starting shards and config servers
"$MONGO_BIN_DIR"mongod --rest  --dbpath "$TEST_PREFIX"shard0 --logpath $DATA_DIR/"$TEST_PREFIX"shard0/log --port 4000 --fork --shardsvr
"$MONGO_BIN_DIR"mongod --rest  --dbpath "$TEST_PREFIX"shard1 --logpath $DATA_DIR/"$TEST_PREFIX"shard1/log --port 4001 --fork --shardsvr
"$MONGO_BIN_DIR"mongod --rest  --dbpath "$TEST_PREFIX"config1 --logpath $DATA_DIR/"$TEST_PREFIX"config1/log --port 4003 --fork --configsvr
"$MONGO_BIN_DIR"mongod --rest  --dbpath "$TEST_PREFIX"config2 --logpath $DATA_DIR/"$TEST_PREFIX"config2/log --port 4004 --fork --configsvr
 
echo Waiting for config server to start up
sleep 3 # let config server start up
 
echo Starting mongos
"$MONGO_BIN_DIR"mongos --port 4006 --configdb localhost:4003 --fork --logpath $DATA_DIR/"$TEST_PREFIX"mongos.log --chunkSize 1
 
echo Waiting for mongos to start up 
sleep 3 
 
echo Initiating shard
"$MONGO_BIN_DIR"mongo --port 4006 admin <<EOF
print("\nAdding shards");
db.runCommand( { addshard : 'localhost:4000', name: 'shard0' });
db.runCommand( { addshard : 'localhost:4001', name: 'shard1' });
print("\nAdding config server as shard. This should fail. ");
db.runCommand( { addShard : 'localhost:4004', name: 'shard2' });
EOF                                                            

Or you could run this jstest:

/**
 * Test to make sure you can't add a config server as shard 
 */
 
var st = new ShardingTest({ shards: [{ useHostName: true }], 
    other: {
        shardOptions: {
            smallfiles: "",
            noprealloc: ""
        }
    }
});
 
/* Create a new config server */
var configConf = {
    useHostname: "localhost",
    noJournalPrealloc: true,
    port: 29004,
    pathOpts: { testName: "test", config: 4 },
    dbpath: "$testName-config$config",
    configsvr: ""
};
 
var newConfig = MongoRunner.runMongod(configConf);
 
/* Print some things */
print("Printing initial config server command line options:");
printjson(st.config0.getDB("admin").runCommand({"getCmdLineOpts": 1}));
//res = st.s.adminCommand({addShard: st.config0.host });
print("Printing newConfig server command line options:");
printjson(newConfig.getDB("admin").runCommand({"getCmdLineOpts": 1}));
print("Printing current config servers");
printjson(st._configServers);
print("newConfig host:");
print(newConfig.host);
st.printShardingStatus();
 
/* Test adding a config server as shard */
res = st.s.adminCommand({addShard: newConfig.host });
assert.eq(res.ok, 0);
print("Printing config servers");
printjson(st._configServers);
st.printShardingStatus()
 
st.stop();

Participants:

 Description   

Config servers should not be allowed to be added as shard servers. In 2.5.3 config servers can be added as shards. This is a regression. v2.4.6 runs fine.



 Comments   
Comment by Randolph Tan [ 04/Oct/13 ]

reverted regression via https://github.com/mongodb/mongo/commit/6c68034f641f9f50e10ab68ac660242a53373ec1

Generated at Thu Feb 08 03:24:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.