MongoDB : 3 member replica set configuration and few scenarios
mkdir m1 m2 m3
mongod --dbpath /home/mongod/m1 --port 30001 --replSet r1 --logpath /var/log/mongodb/mongod_m1.log --fork
mongod --dbpath /home/mongod/m2 --port 30002 --replSet r1 --logpath /var/log/mongodb/mongod_m2.log --fork
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Priority:
++++++++++++++++++++++++++++++++++++++++++++++++++++
Freeze: function is used to stop a secondary node from taking a primary role for a mentioned time period
rs.freeze(5*60)
i am asking secondary to freeze for 60*5 = 300 Secs.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Hidden node: application cannot see the hidden member it can be used for reporting or other work load, without interfering wtih the application load . hidden member cant become primatry ever. But it can vote in election.
var cfg = rs.config()
cfg.members[2].priority=0 --- 0 priority means, it will never become primary
cfg.members[2].hidden=true -- make it hidden
rs.recofig(cfg)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
mongod --dbpath /home/mongod/m1 --port 30001 --replSet r1 --logpath /var/log/mongodb/mongod_m1.log --fork
mongod --dbpath /home/mongod/m2 --port 30002 --replSet r1 --logpath /var/log/mongodb/mongod_m2.log --fork
mongod --dbpath /home/mongod/m3 --port 30003 --replSet r1 --logpath /var/log/mongodb/mongod_m3.log --fork
[mongod@sikki4u1c ~]$ ps -ef| grep mongod
root 2518 2421 0 10:50 pts/0 00:00:00 su - mongod
mongod 2547 2518 0 10:50 pts/0 00:00:00 -bash
mongod 2644 1 5 10:50 ? 00:00:00 mongod --dbpath /home/mongod/m1 --port 30001 --replSet r1 --logpath /var/log/mongodb/mongod_m1.log --fork
mongod 2677 1 9 10:51 ? 00:00:00 mongod --dbpath /home/mongod/m2 --port 30002 --replSet r1 --logpath /var/log/mongodb/mongod_m2.log --fork
mongod 2712 1 15 10:51 ? 00:00:00 mongod --dbpath /home/mongod/m3 --port 30003 --replSet r1 --logpath /var/log/mongodb/mongod_m3.log --fork
mongod 2743 2547 0 10:51 pts/0 00:00:00 ps -ef
mongod 2744 2547 0 10:51 pts/0 00:00:00 grep --color=auto mongod
[mongod@sikki4u1c ~]$
I have started 3 mongod instance on 3 different data directory and port.
Now lets connect to any one instance and do rs.initiate
mongo --port 30001
MongoDB shell version v3.6.13
> rs.initiate()
{
"info2" : "no configuration specified. Using a default configuration for the set",
"me" : "localhost:30001",
"ok" : 1,
"operationTime" : Timestamp(1566816743, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1566816743, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
r1:SECONDARY> --- press enter
r1:SECONDARY> ---- press enter
r1:PRIMARY>
Now instance running on port 30001 in my primary. Now let add member to replicaset.
r1:PRIMARY> rs.add("localhost:30002")
{
"ok" : 1,
"operationTime" : Timestamp(1566816857, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1566816857, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
Adding 3rd node a arbiter----
r1:PRIMARY> rs.add("localhost:30003", true)
{
"ok" : 1,
"operationTime" : Timestamp(1566817075, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1566817075, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
r1:PRIMARY> rs.config()
{
"_id" : "r1",
"version" : 5,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "localhost:30001",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "localhost:30002",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "localhost:30003",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5d63b9e7c542e89fcc1cd25e")
}
}
r1:PRIMARY>
r1:PRIMARY> rs.status()
{
"set" : "r1",
"date" : ISODate("2019-08-26T10:59:13.580Z"),
"myState" : 1,
"term" : NumberLong(1),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1566817145, 1),
"t" : NumberLong(1)
},
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1566817145, 1),
"t" : NumberLong(1)
},
"appliedOpTime" : {
"ts" : Timestamp(1566817145, 1),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1566817145, 1),
"t" : NumberLong(1)
}
},
"members" : [
{
"_id" : 0,
"name" : "localhost:30001",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 499,
"optime" : {
"ts" : Timestamp(1566817145, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2019-08-26T10:59:05Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1566816743, 2),
"electionDate" : ISODate("2019-08-26T10:52:23Z"),
"configVersion" : 5,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "localhost:30002",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 296,
"optime" : {
"ts" : Timestamp(1566817145, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1566817145, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2019-08-26T10:59:05Z"),
"optimeDurableDate" : ISODate("2019-08-26T10:59:05Z"),
"lastHeartbeat" : ISODate("2019-08-26T10:59:11.819Z"),
"lastHeartbeatRecv" : ISODate("2019-08-26T10:59:11.819Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "localhost:30001",
"syncSourceHost" : "localhost:30001",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 5
},
{
"_id" : 2,
"name" : "localhost:30003",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 13,
"lastHeartbeat" : ISODate("2019-08-26T10:59:11.848Z"),
"lastHeartbeatRecv" : ISODate("2019-08-26T10:59:11.644Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : 5
}
],
"ok" : 1,
"operationTime" : Timestamp(1566817145, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1566817145, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
_______ I see all 3 nodes added to replicaset -----
Lets insert some dummy data using a java script. I am on primary
r1:PRIMARY> for(i=0; i<10; i++){db.demo.save({_id:i});}
WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 9 })
r1:PRIMARY> db.demo.find()
{ "_id" : 0 }
{ "_id" : 1 }
{ "_id" : 2 }
{ "_id" : 3 }
{ "_id" : 4 }
{ "_id" : 5 }
{ "_id" : 6 }
{ "_id" : 7 }
{ "_id" : 8 }
{ "_id" : 9 }
r1:PRIMARY>
let connect to secondary.
r1:PRIMARY> db = connect("localhost:30002/test")
connecting to: mongodb://localhost:30002/test
Implicit session: session { "id" : UUID("6cf22711-ebf8-40ff-90fb-4f461d6064c8") }
MongoDB server version: 3.6.13
test
r1:SECONDARY> db.demo.find()
Error: error: {
"operationTime" : Timestamp(1566817515, 1),
"ok" : 0,
"errmsg" : "not master and slaveOk=false",
"code" : 13435,
"codeName" : "NotMasterNoSlaveOk",
"$clusterTime" : {
"clusterTime" : Timestamp(1566817515, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
r1:SECONDARY> rs.slaveOk()
r1:SECONDARY> db.demo.find()
{ "_id" : 0 }
{ "_id" : 4 }
{ "_id" : 2 }
{ "_id" : 3 }
{ "_id" : 7 }
{ "_id" : 6 }
{ "_id" : 1 }
{ "_id" : 5 }
{ "_id" : 8 }
{ "_id" : 9 }
r1:SECONDARY>
here you go.. i see the data in 2nd mongod instance.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Now i am on secondary and i will kill primary to see what happens
[mongod@sikki4u1c ~]$ ps -ef| grep mongod
root 2518 2421 0 10:50 pts/0 00:00:00 su - mongod
mongod 2547 2518 0 10:50 pts/0 00:00:00 -bash
mongod 2644 1 0 10:50 ? 00:00:05 mongod --dbpath /home/mongod/m1 --port 30001 --replSet r1 --logpath /var/log/mongodb/mongod_m1.log --fork
mongod 2677 1 0 10:51 ? 00:00:05 mongod --dbpath /home/mongod/m2 --port 30002 --replSet r1 --logpath /var/log/mongodb/mongod_m2.log --fork
mongod 3132 1 0 10:58 ? 00:00:02 mongod --dbpath /home/mongod/m3 --port 30003 --replSet r1 --logpath /var/log/mongodb/mongod_m3.log --fork
mongod 3302 2547 0 11:04 pts/0 00:00:00 mongo --port 30001
root 3489 3395 0 11:07 pts/1 00:00:00 su - mongod
mongod 3493 3489 0 11:07 pts/1 00:00:00 -bash
mongod 3587 3493 0 11:07 pts/1 00:00:00 ps -ef
mongod 3588 3493 0 11:07 pts/1 00:00:00 grep --color=auto mongod
[mongod@sikki4u1c ~]$ kill 2644
[mongod@sikki4u1c ~]$
Now check the replicaset status on secondary, and note the prompt changing from SECONDARY to PRIMARY. Since 2 of our 3 members were active the instance running on port 30002 was elected as primary.
r1:SECONDARY>
r1:PRIMARY> rs.status()
{
"set" : "r1",
"date" : ISODate("2019-08-26T11:08:22.387Z"),
"myState" : 1,
"term" : NumberLong(2),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1566817675, 1),
"t" : NumberLong(1)
},
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1566817675, 1),
"t" : NumberLong(1)
},
"appliedOpTime" : {
"ts" : Timestamp(1566817693, 1),
"t" : NumberLong(2)
},
"durableOpTime" : {
"ts" : Timestamp(1566817693, 1),
"t" : NumberLong(2)
}
},
"members" : [
{
"_id" : 0,
"name" : "localhost:30001",
"health" : 0,
"state" : 8,
"stateStr" : "(not reachable/healthy)",
"uptime" : 0,
"optime" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDurable" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2019-08-26T11:08:22.338Z"),
"lastHeartbeatRecv" : ISODate("2019-08-26T11:07:59.918Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "Connection refused",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : -1
},
{
"_id" : 1,
"name" : "localhost:30002",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 1042,
"optime" : {
"ts" : Timestamp(1566817693, 1),
"t" : NumberLong(2)
},
"optimeDate" : ISODate("2019-08-26T11:08:13Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1566817692, 1),
"electionDate" : ISODate("2019-08-26T11:08:12Z"),
"configVersion" : 5,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 2,
"name" : "localhost:30003",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 562,
"lastHeartbeat" : ISODate("2019-08-26T11:08:22.333Z"),
"lastHeartbeatRecv" : ISODate("2019-08-26T11:08:21.773Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : 5
}
],
"ok" : 1,
"operationTime" : Timestamp(1566817693, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1566817693, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
r1:PRIMARY>
_______________________________________
Now lets try to kill the arbiter and check the status.
mongod 2677 1 0 10:51 ? 00:00:06 mongod --dbpath /home/mongod/m2 --port 30002 --replSet r1 --logpath /var/log/mongodb/mongod_m2.log --fork
mongod 3132 1 0 10:58 ? 00:00:03 mongod --dbpath /home/mongod/m3 --port 30003 --replSet r1 --logpath /var/log/mongodb/mongod_m3.log --fork
mongod 3302 2547 0 11:04 pts/0 00:00:00 mongo --port 30001
root 3489 3395 0 11:07 pts/1 00:00:00 su - mongod
mongod 3493 3489 0 11:07 pts/1 00:00:00 -bash
mongod 3687 3493 0 11:11 pts/1 00:00:00 ps -ef
mongod 3688 3493 0 11:11 pts/1 00:00:00 grep --color=auto mongod
[mongod@sikki4u1c ~]$ kill 3132
r1:PRIMARY> rs.status()
2019-08-26T11:11:42.702+0000 E QUERY [thread1] Error: error doing query: failed: network error while attempting to run command 'replSetGetStatus' on host 'localhost:30002' :
DB.prototype.runCommand@src/mongo/shell/db.js:168:1
DB.prototype.adminCommand@src/mongo/shell/db.js:186:16
rs.status@src/mongo/shell/utils.js:1268:12
@(shell):1:1
2019-08-26T11:11:42.704+0000 I NETWORK [thread1] trying reconnect to localhost:30002 (127.0.0.1) failed
2019-08-26T11:11:42.704+0000 I NETWORK [thread1] reconnect localhost:30002 (127.0.0.1) ok
r1:SECONDARY>
Mongo has shut down the connections server to prevent and writing to primary. this mechanism prevents application from trying to write to the previous primary.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Priority:
Here i will set priority for member [0] to 10. as of now all are having same priority.
r1:PRIMARY> rs.config()
{
"_id" : "r1",
"version" : 5,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "localhost:30001",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "localhost:30002",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "localhost:30003",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5d63b9e7c542e89fcc1cd25e")
}
}
r1:PRIMARY> var cfg = rs.config()
r1:PRIMARY> cfg.members[0].priority = 10
10
r1:PRIMARY> rs.reconfig(cfg)
{
"ok" : 1,
"operationTime" : Timestamp(1567060050, 2),
"$clusterTime" : {
"clusterTime" : Timestamp(1567060050, 2),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
r1:PRIMARY> rs.config()
{
"_id" : "r1",
"version" : 6,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "localhost:30001",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 10,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "localhost:30002",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "localhost:30003",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5d63b9e7c542e89fcc1cd25e")
}
}
r1:PRIMARY>
How do i now which mongo server i am conncted to
r1:PRIMARY> db.getMongo()
connection to 127.0.0.1:30001
r1:PRIMARY> db=connect('127.0.0.1:30002/test')
connecting to: mongodb://127.0.0.1:30002/test
Implicit session: session { "id" : UUID("34172119-afd2-4a8c-862a-f9789f2878c3") }
MongoDB server version: 3.6.13
test
r1:SECONDARY>
---here i connected to secondary and now i will kill my primary
r1:PRIMARY> rs.config()
{
"_id" : "r1",
"version" : 5,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "localhost:30001",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "localhost:30002",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "localhost:30003",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5d63b9e7c542e89fcc1cd25e")
}
}
r1:PRIMARY> var cfg = rs.config()
r1:PRIMARY> cfg.members[0].priority = 10
10
r1:PRIMARY> rs.reconfig(cfg)
{
"ok" : 1,
"operationTime" : Timestamp(1567060050, 2),
"$clusterTime" : {
"clusterTime" : Timestamp(1567060050, 2),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
r1:PRIMARY> rs.config()
{
"_id" : "r1",
"version" : 6,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "localhost:30001",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 10,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "localhost:30002",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "localhost:30003",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5d63b9e7c542e89fcc1cd25e")
}
}
r1:PRIMARY>
How do i now which mongo server i am conncted to
r1:PRIMARY> db.getMongo()
connection to 127.0.0.1:30001
r1:PRIMARY> db=connect('127.0.0.1:30002/test')
connecting to: mongodb://127.0.0.1:30002/test
Implicit session: session { "id" : UUID("34172119-afd2-4a8c-862a-f9789f2878c3") }
MongoDB server version: 3.6.13
test
r1:SECONDARY>
---here i connected to secondary and now i will kill my primary
as i kill primary the second instance running on port 30002 becomes primary.
Now again if i start my first mongod instance on 30001, it will become primary again as it have higher priority over other nodes.
++++++++++++++++++++++++++++++++++++++++++++++++++++
Freeze: function is used to stop a secondary node from taking a primary role for a mentioned time period
rs.freeze(5*60)
i am asking secondary to freeze for 60*5 = 300 Secs.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Hidden node: application cannot see the hidden member it can be used for reporting or other work load, without interfering wtih the application load . hidden member cant become primatry ever. But it can vote in election.
var cfg = rs.config()
cfg.members[2].priority=0 --- 0 priority means, it will never become primary
cfg.members[2].hidden=true -- make it hidden
rs.recofig(cfg)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home