Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-10908

Sanity check for adding config server as shard server never runs

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.5.3
    • 2.5.2
    • Sharding
    • ALL
    • Hide

      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();

      Show
      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();

    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.

      Attachments

        Activity

          People

            randolph@mongodb.com Randolph Tan
            phillip.quiza Phillip Quiza
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: