问题描述
存在具有三个成员(主要,次要,次要)的副本.假设第二个备份中的一个中断一天,在将第二个备份返回到副本后,我如何找到它是否已同步?
there is the replica with three member (primary,secondary,secondary).Suppose one of secondaries down for a day, after return secondary back to replica how can i find, is it synced yet or not?
我是在测试环境中这样做的,但是找不到来自rs.status()
和db.printReplicationInfo()
的有用数据.
I did that in testing environment, But couldn't find useful data from rs.status()
and db.printReplicationInfo()
.
在db.printReplicationInfo()
中有日志长度开始到结束".但是默认情况下这是个大时间,并且在次要数据库关闭时会增长.
there is "log length start to end" in db.printReplicationInfo()
. but it's big time by default and grows when secondary is down.
推荐答案
注意:请务必检查答案由 arcseldon 提供,以实现对用户友好的等效功能.
Note: Be sure to check the answer provided by arcseldon for an user friendly equivalent.
您可以使用rs.status()
的输出.如果辅助数据库已同步并且不是使用slaveDelay
选项创建的,则辅助数据库的optime
和optimeDate
应该等于或接近于主要数据库的optime
和optimeDate
(如果有当前操作).在这种情况下,stateStr
应该等于SECONDARY
.因此,如果同步了辅助服务器,您应该会看到与此类似的输出(为清楚起见,已从输出中删除了一个成员):
You can use output of rs.status()
. If secondary is synced and wasn't created with slaveDelay
option then optime
and optimeDate
of secondary should be equal or close (if there are current operations) to those of primary. In that case stateStr
should be equal to SECONDARY
. So if secondary is synced you should see output similar to this (one member has been removed from output for clarity):
{
"set" : "rs0",
"date" : ISODate("2013-11-08T14:58:49Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "hostname:27001",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 155,
"optime" : Timestamp(1383915748, 1),
"optimeDate" : ISODate("2013-11-08T13:02:28Z"),
"self" : true
},
{
"_id" : 2,
"name" : "hostname:27003",
"health" : 0,
"state" : 8,
"stateStr" : "SECONDARY",
"uptime" : 0,
"optime" : Timestamp(1383915748, 1),
"optimeDate" : ISODate("2013-11-08T13:02:28Z"),
"lastHeartbeat" : ISODate("2013-11-08T14:58:48Z"),
"lastHeartbeatRecv" : ISODate("2013-11-08T14:58:42Z"),
"pingMs" : 0,
"syncingTo" : "hostname:27001"
}
],
"ok" : 1
}
如果其中一个副本未同步,则对于同一副本集,您的输出为rs.status()
.首先,您会看到hostname:27003
的optime
和optimeDate
与主变量不同,stateStr设置为RECOVERING
,并且有适当的lastHeartbeatMessage
.
Here you have output of rs.status()
for the same replica set if one of secondaries is not synced. First of all you'll see that optime
and optimeDate
for hostname:27003
differs from primary, stateStr is set to RECOVERING
and there is appropriate lastHeartbeatMessage
.
{
"set" : "rs0",
"date" : ISODate("2013-11-08T15:01:34Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "hostname:27001",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 320,
"optime" : Timestamp(1383922858, 767),
"optimeDate" : ISODate("2013-11-08T15:00:58Z"),
"self" : true
},
{
"_id" : 2,
"name" : "hostname:27003",
"health" : 1,
"state" : 3,
"stateStr" : "RECOVERING",
"uptime" : 14,
"optime" : Timestamp(1383915748, 1),
"optimeDate" : ISODate("2013-11-08T13:02:28Z"),
"lastHeartbeat" : ISODate("2013-11-08T15:01:34Z"),
"lastHeartbeatRecv" : ISODate("2013-11-08T15:01:34Z"),
"pingMs" : 0,
"lastHeartbeatMessage" : "still syncing, not yet to minValid optime 527cfc90:19c4",
"syncingTo" : "hostname:27001"
}
],
"ok" : 1
}
如果使用slaveDelay
创建了辅助对象,则optime
和optimeDate
可以不同,但是stateStr
和lastHeartbeatMessage
将指示是否存在滞后.
If secondary has been created with slaveDelay
then optime
and optimeDate
can be different but stateStr
and lastHeartbeatMessage
will indicate if there is some lag.
这篇关于如何检查辅助节点现在是否同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!