[SERVER-20017] isMaster command has a primary which does not have ismaster set to true Created: 18/Aug/15  Updated: 03/Mar/16  Resolved: 19/Aug/15

Status: Closed
Project: Core Server
Component/s: Replication, Sharding
Affects Version/s: 3.1.7
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jonathan Abrahams Assignee: Eric Milkie
Resolution: Done Votes: 1
Labels: 32qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File nonMasterPrimary.js    
Issue Links:
Related
Operating System: ALL
Steps To Reproduce:

#!/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

Participants:

 Description   

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
}



 Comments   
Comment by Eric Milkie [ 19/Aug/15 ]

While the node is in drain mode, isMaster will return false, but the state will appear as PRIMARY.

Comment by Jonathan Abrahams [ 19/Aug/15 ]

Adjusted title, since apparently it does not require a configsvr to occur.

Comment by Kevin Pulo [ 18/Aug/15 ]

I've attached a non-configsvr:true based jstest that demonstrates this. I found it easy to hit with 3 members in 3.0.0 and above, but this behaviour (of primary == me, but secondary == true and ismaster == false) didn't happen in 2.6.10, which always hits the "too slow" code path as soon as the primary is elected.

Comment by Jonathan Abrahams [ 18/Aug/15 ]

Cannot reproduce if a non-configsvr replica set.

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