There is no primary, how to make secondary as primary by force

2,093 views
Skip to first unread message

Avise Sudhakar Rao

unread,
Feb 8, 2013, 3:38:53 PM2/8/13
to mongod...@googlegroups.com
I needd your quick help
please respond
I have one serve in down
and another server in secondary state
but there is no primary
how can I make secondary as Primary forcely
?
please help
 

Scott Hernandez

unread,
Feb 8, 2013, 3:41:40 PM2/8/13
to mongod...@googlegroups.com
You can do a reconfigure with a higher vote count so that you have a
majority of votes with the members which are still up. In general you
should never have an even number, so having 3 data members + 1 arbiter
is a bad idea.

http://docs.mongodb.org/manual/tutorial/reconfigure-replica-set-with-unavailable-members/
http://docs.mongodb.org/manual/reference/method/rs.reconfig/
> --
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
>
> ---
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mongodb-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Avise Sudhakar Rao

unread,
Feb 8, 2013, 3:50:46 PM2/8/13
to mongod...@googlegroups.com
currently it is in monit:STARTUP2 mode
how can I set

Avise Sudhakar Rao

unread,
Feb 8, 2013, 3:54:11 PM2/8/13
to mongod...@googlegroups.com
monit:STARTUP2> cfg = rs.conf()
{
        "_id" : "monit",
        "version" : 21,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "172.25.122.181:27017"
                },
                {
                        "_id" : 2,
                        "host" : "172.25.122.20:27017",
                        "arbiterOnly" : true
                },
                {
                        "_id" : 3,
                        "host" : "172.25.122.182:27017"
                },
                {
                        "_id" : 4,
                        "host" : "172.25.122.186:27017"
                }
        ]
}
monit:STARTUP2> cfg.members[0].priority = 0.5
0.5
monit:STARTUP2> cfg.members[2].priority = 0.5
0.5
monit:STARTUP2> cfg.members[3].priority = 1
1
monit:STARTUP2> cfg.members[4].priority = 1
Fri Feb  8 20:52:57 TypeError: cfg.members[4] has no properties (shell):1
monit:STARTUP2> rs.reconfig(cfg,{force:true})
{
        "errmsg" : "exception: need most members up to reconfigure, not ok : 172.25.122.186:27017",
        "code" : 13144,
        "ok" : 0
}


I'm getting above error, please to make 172.25.122.182 as primary

Asya Kamsky

unread,
Feb 8, 2013, 4:12:46 PM2/8/13
to mongod...@googlegroups.com
Dear Sudhakar:

In order to have a node act as Primary it has to get votes from majority of the cluster.
Because you have four members on the replica set, majority is 3.  If you reduce the replica set configuration to three then it will only take two votes to be a primary.

You say you want to make 172.25.122.182 as Primary - can you log into that server with "mongo --host 171.25.122.186" ?

Earlier you posted:
monit:RECOVERING> db.printSlaveReplicationInfo()
source:   172.25.122.181:27017
         syncedTo: Fri Feb 08 2013 12:14:55 GMT+0000 (UTC)
                 = 16998 secs ago (4.72hrs)
source:   172.25.122.20:27017
         no replication info, yet.  State: ARBITER
source:   172.25.122.186:27017
         syncedTo: Fri Feb 08 2013 13:49:48 GMT+0000 (UTC)
                 = 11305 secs ago (3.14hrs)
monit:RECOVERING> 

Since 172.25.122.182 is the machine you want to make primary, connect to it via mongo shell and do 'rs.reconfigure' command there.

If you remove the stalest replica from the configuration, the arbiter and 172.25.186.182 will be able to vote it back into primary status,
hopefully then your other secondary can catch up.  

Create a config which looks like this:
newconfig = {

        "_id" : "monit",
        "version" : 21,
        "members" : [
                {
                        "_id" : 2,
                        "host" : "172.25.122.20:27017",
                        "arbiterOnly" : true
                },
                {
                        "_id" : 3,
                        "host" : "172.25.122.182:27017"
                },
                {
                        "_id" : 4,
                        "host" : "172.25.122.186:27017"
                }
        ]
}

run rs.reconfig(newconfig, {force:true}) ON 172.25.122.186:27017

Once you've restored basic functionality, I would recommend investing time into setting up a more robust cluster, with larger oplogs
and always an odd number of members.

Asya

Avise Sudhakar Rao

unread,
Feb 8, 2013, 4:21:19 PM2/8/13
to mongod...@googlegroups.com
Actually there is no data on 172.25.122.186
and if I start .186 then it will become primary and I will lost the data on .182 which is having production data

How I can run on .182 instead of .186?

Please help

Asya Kamsky

unread,
Feb 8, 2013, 4:27:49 PM2/8/13
to mongod...@googlegroups.com
I'm sorry, I must have mis-pasted.

Change your config object to be the same but run the rs.reconfig(newconfig) command when connected to 172.25.122.182:27017
You can add higher priority to it in the config as well like this:

newconfig = {
        "_id" : "monit",
        "version" : 21,
        "members" : [
                {
                        "_id" : 2,
                        "host" : "172.25.122.20:27017",
                        "arbiterOnly" : true
                },
                {
                        "_id" : 3,
                        "host" : "172.25.122.182:27017",
                       "priority": 2

                },
                {
                        "_id" : 4,
                        "host" : "172.25.122.186:27017"
                }
        ]
}


On Friday, February 8, 2013 1:21:19 PM UTC-8, Sudhakar wrote:
Actually there is no data on 172.25.122.186
and if I start .186 then it will become primary and I will lost the data on .182 which is having production data

How I can run on .182 instead of .186?

Please help
On Sat, Feb 9, 2013 at 2:42 AM, Asya Kamsky <as...@10gen.com> wrote:
Dear Sudhakar:

In order to have a node act as Primary it has to get votes from majority of the cluster.
Because you have four members on the replica set, majority is 3.  If you reduce the replica set configuration to three then it will only take two votes to be a primary.

You say you want to make 172.25.122.182 as Primary - can you log into that server with "mongo --host 171.25.122.182" ?
run rs.reconfig(newconfig, {force:true}) ON 172.25.122.182:27017

Avise Sudhakar Rao

unread,
Feb 8, 2013, 4:40:41 PM2/8/13
to mongod...@googlegroups.com
monit:SECONDARY> rs.status()
{
        "set" : "monit",
        "date" : ISODate("2013-02-08T21:39:41Z"),
        "myState" : 2,
        "members" : [
                {
                        "_id" : 2,
                        "name" : "172.25.122.20:27017",
                        "health" : 1,
                        "state" : 7,
                        "stateStr" : "ARBITER",
                        "uptime" : 72,
                        "lastHeartbeat" : ISODate("2013-02-08T21:39:41Z"),
                        "pingMs" : 1
                },
                {
                        "_id" : 3,
                        "name" : "172.25.122.182:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 72,
                        "optime" : Timestamp(1360354594000, 148),
                        "optimeDate" : ISODate("2013-02-08T20:16:34Z"),
                        "self" : true
                },
                {
                        "_id" : 4,
                        "name" : "172.25.122.186:27017",
                        "health" : 0,
                        "state" : 8,
                        "stateStr" : "(not reachable/healthy)",
                        "uptime" : 0,
                        "optime" : Timestamp(0, 0),
                        "optimeDate" : ISODate("1970-01-01T00:00:00Z"),
                        "lastHeartbeat" : ISODate("1970-01-01T00:00:00Z"),
                        "pingMs" : 0,
                        "errmsg" : "socket exception [CONNECT_ERROR] for 172.25.122.186:27017"
                }
        ],
        "ok" : 1
}
monit:SECONDARY>

Executed but still shwoing Secondary and not coming up to Primary

Asya Kamsky

unread,
Feb 8, 2013, 5:09:06 PM2/8/13
to mongod...@googlegroups.com
It would normally not be instant - what do the logs say?

Avise Sudhakar Rao

unread,
Feb 8, 2013, 5:43:23 PM2/8/13
to mongod...@googlegroups.com
It was still in Secondary, so I thought as i don't have any other opportunity, created new replicatSet with the name monit2
and after creating new replicatSet 172.25.122.182 is Primary but 172.25.122.186 is becoming to Recovery state and not coming up to Secondary state and the lag on the secondary is keep on increasing.

How can I change oplogsize on primary without restarting Primary? I think if I increase oplogsize of the Primary then this problem will be resolved.

Please help.

Asya Kamsky

unread,
Feb 8, 2013, 5:59:11 PM2/8/13
to mongod...@googlegroups.com
Yes, it was still in secondary and until you run the rs.reconfig() it will stay in secondary.

When you reconfigure it will be able to become Primary as long as the other nodes can connect to it over the network (if you don't have network connectivity between that node and other nodes, you won't be able to get the replica set back up).

Asya

Avise Sudhakar Rao

unread,
Feb 8, 2013, 6:09:38 PM2/8/13
to mongod...@googlegroups.com
How to increase oplogsize of primary without stopping it?

monit2:PRIMARY> db.oplog.rs.find().count()
768253
monit2:PRIMARY>

As slave  is not coming up to secondary and it's remaining in recovery state only.

Thanks,
Sudhakar

Asya Kamsky

unread,
Feb 8, 2013, 6:25:13 PM2/8/13
to mongod...@googlegroups.com
You cannot increase the size of the oplog without stopping the primary.

However, the fastest way to sync a secondary is to snapshot (make a copy) the entire data directory from the primary and drop it into the secondary's data file (when the secondary is stopped).  Then restart the secondary.   It will finish syncing from the oplog of the primary without needing to do a full sync.   Assuming you are running with journaling this does not require stopping the primary while you snapshot the disk.

Asya

Avise Sudhakar Rao

unread,
Feb 9, 2013, 3:21:00 AM2/9/13
to mongod...@googlegroups.com
If I'm doing this process taking of primary snapshot and placing on slave mongo server when I stop slave mongo server which is in  Recovery State, Primary mongo state getting changed to Secondary and there is no Primary mongo state.
And after copying all the data in the slave mongo db and making the mongo up then this slave mongo state is coming to Recovery and Secondary is automatically getting changed to Primary.

But no way Recovery state is changing to Secondary.

Please suggest how to resolve this.

Thanks,
Sudhakar

Reply all
Reply to author
Forward
0 new messages