Search code examples
mongodbmeteorreplication

Meteor, MongoDB multiple oplog setup


I have Meteor project with replicated two mongoDB server It works pretty well but when I tested some DB error simulation, the mongoDB replication's primary election and multi-oplog setting work differently with my though.

Here's my Meteor and MongoDB settings.

- MongodB -
rs.conf()
{
        "_id" : "meteor",
        "version" : 6,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "hostname1:27017",
                        "priority" : 2.5
                },
                {
                        "_id" : 1,
                        "host" : "hostname2:27017",
                        "priority" : 1.5
                }
        ]
}

rs.status()
{
        "set" : "meteor",
        "date" : ISODate("2014-10-08T10:40:38Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 0,
                        "name" : "hostname1:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 462,
                        "optime" : Timestamp(1412764634, 2),
                        "optimeDate" : ISODate("2014-10-08T10:37:14Z"),
                        "electionTime" : Timestamp(1412764612, 1),
                        "electionDate" : ISODate("2014-10-08T10:36:52Z"),
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "hostname2:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 234,
                        "optime" : Timestamp(1412764634, 2),
                        "optimeDate" : ISODate("2014-10-08T10:37:14Z"),
                        "lastHeartbeat" : ISODate("2014-10-08T10:40:37Z"),
                        "lastHeartbeatRecv" : ISODate("2014-10-08T10:40:37Z"),
                        "pingMs" : 141,
                        "syncingTo" : "hostname2:27017"
                }
        ],
        "ok" : 1
}


- Meteor Environment - 
MONGO_OPLOG_URL=mongodb://hostname1:27017,hostname2:27017/local MONGO_URL=mongodb://hostname1:27017/sports meteor

I assumed that if I terminate DB hostname1, then hostname2 should be elected by Primary, so my Meteor server could redirect its OPLOG URL to it.

But when I terminated hostname1, hostname2 stayed as Secondary and Meteor couldn't find any oplog server.

And even when I terminated hostname2, hostname1 which was Primary was changed into Secondary so Meteor couldn't find any oplog server as well.

I think I missed something big one, but I can't figure it out.

Does anyone have some idea about this?

Thanks in advance.


Solution

  • Your MONGO_URL needs to include both members of the replica set. Meteor is built on the node driver for mongo and thus has to be aware of both members of the replica set in order for failover to occur gracefully.