#1 2019-01-10 13:18:53

DigDiver
Member
Registered: 2013-04-29
Posts: 137

MongoDB replicaset PrimarySteppedDown

Does anybody implement correct works with mongoDB replicaset?

The problem is that all insert/update TMongoCollection operations calls Database.Client.Connections[0] where index "0" is a primary server. When the primary server is down/reboots the primary server in replicaset will be changed. After that all insert/update operations will fail with the error:

..."connectionId":6,"err":"Not primary while writing to database.ServerStat","code":189,"codeName":"PrimarySteppedDown"...

As a solution, maybe we should run the command "ismaster" to resort Database.Client.Connections periodically or when error occurred?

{
    "hosts" : [ 
        "devdb1:27017", 
        "devdb2:27017", 
        "devdb3:27017"
    ],
    "setName" : "devgapps",
    "setVersion" : 3,
    "ismaster" : false,
    "secondary" : true,
    "primary" : "devdb1:27017",
    "me" : "devdb3:27017",
    "lastWrite" : {
        "opTime" : {
            "ts" : Timestamp(1547122432, 1),
            "t" : NumberLong(1)
        },
        "lastWriteDate" : ISODate("2019-01-10T12:13:52.000Z"),
        "majorityOpTime" : {
            "ts" : Timestamp(1547122432, 1),
            "t" : NumberLong(1)
        },
        "majorityWriteDate" : ISODate("2019-01-10T12:13:52.000Z")
    },
    "maxBsonObjectSize" : 16777216,
    "maxMessageSizeBytes" : 48000000,
    "maxWriteBatchSize" : 100000,
    "localTime" : ISODate("2019-01-10T12:13:54.403Z"),
    "logicalSessionTimeoutMinutes" : 30,
    "minWireVersion" : 0,
    "maxWireVersion" : 6,
    "readOnly" : false,
    "ok" : 1.0,
    "operationTime" : Timestamp(1547122432, 1)
}

One of the problems is internal host names

       "devdb1:27017", 
        "devdb2:27017", 
        "devdb3:27017"

but this may be resolved by adding aliases to TMongoClient.Create('devdb1@192.168.0.1',...'

Offline

#2 2019-01-10 16:13:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,670
Website

Re: MongoDB replicaset PrimarySteppedDown

The SynMongo client replica code is not fully tested (we don't use it on production), so any feedback is welcome!

Offline

Board footer

Powered by FluxBB