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

isMaster command has a primary which does not have ismaster set to true

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.1.7
    • Component/s: Replication, Sharding
    • 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 })"
      waitForNode="assert.soon(function() { return rs.isMaster().primary && (rs.isMaster().ismaster || rs.isMaster().secondary) })"
      
      # 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)));
          printjson(rs.status());"
      echo "$mongoCmds" | $mongo --port $cfgPort
      
      # Make sure all configsvr nodes are ready
      for i in $(seq 0 2)
      do
          mongoCmds="$waitForNode; printjson(rs.isMaster());"
          echo "$mongoCmds" | $mongo --port $((cfgPort+i))
      done
      
      # 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 })" waitForNode= " assert .soon(function() { return rs.isMaster().primary && (rs.isMaster().ismaster || rs.isMaster().secondary) })" # 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))); printjson(rs.status());" echo "$mongoCmds" | $mongo --port $cfgPort # Make sure all configsvr nodes are ready for i in $(seq 0 2) do mongoCmds= "$waitForNode; printjson(rs.isMaster());" echo "$mongoCmds" | $mongo --port $((cfgPort+i)) done # Start the mongos mongosCmd="$mongos \ --port $mongosPort \ --configdb configServers/$configServers \ --fork \ --logpath mongos.log" $mongosCmd

      The isMaster command returns the "state" of the mongod.
      The "primary" is this node ("me"), but "secondary" is true and "ismaster" is false. Note this was from a configsvr replica set:

      {
      	"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
      }
      

        1. nonMasterPrimary.js
          2 kB
          Kevin Pulo

            Assignee:
            milkie@mongodb.com Eric Milkie
            Reporter:
            jonathan.abrahams Jonathan Abrahams
            Votes:
            1 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: