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

mongos fails to start if CSRS primary is not ismaster

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.9
    • Affects Version/s: 3.1.7
    • Component/s: Sharding
    • Fully Compatible
    • ALL
    • Hide
      #!/bin/bash
      dbRoot=/tmp
      mongo=$(which mongo)
      mongod=$(which mongod)
      mongos=$(which mongos)
      cfgPort=29017
      mongosPort=30000
      hostname=$(hostname)
      replset="configServers"
      mongoCmds=""
      members="[ "
      configServers=
      storageEngine="wiredTiger"
      
      waitForPrimary="assert.soon(function() { return rs.isMaster().primary })"
      
      # Start mongods
      for i in $(seq 0 2)
      do
          port=$((cfgPort+i))
          dbpath="$dbRoot/config$i"
          rm -fr $dbpath
          mkdir -p $dbpath
          logpath="mongod-config$i.log"
          rm ${logpath}*
      
          # Save each mongod configsvr
          cfgSrvr[$i]="$mongod \
              --storageEngine $storageEngine \
              --smallfiles \
              --configsvr \
              --port $port \
              --dbpath $dbpath \
              --replSet $replset \
              --logpath $logpath \
              --fork"    
      
          # Start each mongod configsvr
          ${cfgSrvr[$i]}
          members="$members {_id: $i, host: '$hostname:$port'},"
          if [ ! -z "$configServers" ]; then
              configServers="$configServers,$hostname:$port"
          else
              configServers="$hostname:$port"
          fi
      done
      members="$members ]"
      
      # Initiate the replica set as configsvr (CSRS)
      mongoCmds="var cfg={_id: '$replset', configsvr: true, members: $members};
          print('initializing with', tojson(cfg));
          print('rs.initiate', tojson(rs.initiate(cfg)));
          $waitForPrimary;
          printjson(rs.status());"
      echo "$mongoCmds" | $mongo --port $cfgPort
      
      # Start the mongos
      mongosCmd="$mongos \
          --port $mongosPort \
          --configdb configServers/$configServers \
          --fork \
          --logpath mongos.log"
      
      $mongosCmd
      
      
      Show
      #!/bin/bash dbRoot=/tmp mongo=$(which mongo) mongod=$(which mongod) mongos=$(which mongos) cfgPort=29017 mongosPort=30000 hostname=$(hostname) replset= "configServers" mongoCmds="" members= "[ " configServers= storageEngine= "wiredTiger" waitForPrimary= " assert .soon(function() { return rs.isMaster().primary })" # Start mongods for i in $(seq 0 2) do port=$((cfgPort+i)) dbpath= "$dbRoot/config$i" rm -fr $dbpath mkdir -p $dbpath logpath= "mongod-config$i.log" rm ${logpath}* # Save each mongod configsvr cfgSrvr[$i]="$mongod \ --storageEngine $storageEngine \ --smallfiles \ --configsvr \ --port $port \ --dbpath $dbpath \ --replSet $replset \ --logpath $logpath \ --fork" # Start each mongod configsvr ${cfgSrvr[$i]} members= "$members {_id: $i, host: '$hostname:$port' }," if [ ! -z "$configServers" ]; then configServers= "$configServers,$hostname:$port" else configServers= "$hostname:$port" fi done members= "$members ]" # Initiate the replica set as configsvr (CSRS) mongoCmds=" var cfg={_id: '$replset' , configsvr: true , members: $members}; print( 'initializing with' , tojson(cfg)); print( 'rs.initiate' , tojson(rs.initiate(cfg))); $waitForPrimary; printjson(rs.status());" echo "$mongoCmds" | $mongo --port $cfgPort # Start the mongos mongosCmd="$mongos \ --port $mongosPort \ --configdb configServers/$configServers \ --fork \ --logpath mongos.log" $mongosCmd
    • Sharding 8 08/28/15, Sharding 9 (09/18/15), Sharding A (10/09/15)

      mongos fails to start if the primary node does not have ismaster set to true (see SERVER-20017). The CSRS is in a startup state and mongos should retry before failing immediately:

      {
      	"hosts" : [
      		"rhel64.mongotest.com:29017",
      		"rhel64.mongotest.com:29018",
      		"rhel64.mongotest.com:29019"
      	],
      	"setName" : "configServers",
      	"setVersion" : 1,
      	"ismaster" : false,
      	"secondary" : true,
      	"primary" : "rhel64.mongotest.com:29017",
      	"me" : "rhel64.mongotest.com:29017",
      	"electionId" : ObjectId("55d38ce30000000000000000"),
      	"configsvr" : 1,
      	"maxBsonObjectSize" : 16777216,
      	"maxMessageSizeBytes" : 48000000,
      	"maxWriteBatchSize" : 1000,
      	"localTime" : ISODate("2015-08-18T19:52:03.160Z"),
      	"maxWireVersion" : 4,
      	"minWireVersion" : 0,
      	"ok" : 1
      }
      
      2015-08-18T19:52:03.764+0000 I NETWORK  [mongosMain] starting new replica set monitor for replica set configServers with seeds
      2015-08-18T19:52:03.764+0000 I NETWORK  [mongosMain] rhel64.mongotest.com:29017
      2015-08-18T19:52:03.764+0000 I NETWORK  [mongosMain] ,
      2015-08-18T19:52:03.764+0000 I NETWORK  [mongosMain] rhel64.mongotest.com:29018
      2015-08-18T19:52:03.764+0000 I NETWORK  [mongosMain] ,
      2015-08-18T19:52:03.764+0000 I NETWORK  [mongosMain] rhel64.mongotest.com:29019
      2015-08-18T19:52:03.764+0000 I NETWORK  [ReplicaSetMonitorWatcher] starting
      2015-08-18T19:52:03.810+0000 W NETWORK  [mongosMain] No primary detected for set configServers
      2015-08-18T19:52:03.810+0000 E SHARDING [mongosMain] Error initializing sharding system: NotMaster No master found for set configServers
      

        1. test.js
          0.4 kB

            Assignee:
            spencer@mongodb.com Spencer Brody (Inactive)
            Reporter:
            jonathan.abrahams Jonathan Abrahams
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: