主从操作日志oplog
MongoDB的Replica Set架构是通过一个日志来存储写操作的,这个日志就叫做"oplog"。oplog.rs是一个固定长度的capped collection,它存在于"local"数据库中,用于记录Replica Sets操作日志。在默认情况下,对于64位的MongoDB,oplog是比较大的,可以达到5%的磁盘空间。oplog的大小是可以通过mongod的参数“--oplogSize”来设置。
- rs1:PRIMARY>uselocal
- switchedtodblocal
- rs1:PRIMARY>showcollections
- oplog.rs
- system.replset
- rs1:PRIMARY>db.oplog.rs.find()
- {"ts":{"t":1338457763000,"i":1},"h":NumberLong(0),"op":"n","ns":"","o":{"msg":
- "initiatingset"}}
- {"ts":{"t":1338459114000,"h":NumberLong("5493127699725549585"),"op":"i",
- "ns":"test.c1","o":{"_id":ObjectId("4fc743e9aea289af709ac6b5"),"age":29,"name":
- "Tony"}}
- rs1:PRIMARY>
ts: 某个操作的时间戳
op: 操作类型,如下:
i: insert
d: delete
u: update
ns: 命名空间,也就是操作的collection name
o: document 的内容
查看master 的oplog 元数据信息:
- rs1:PRIMARY>db.printReplicationInfo()
- configuredoplogsize:47.6837158203125MB
- loglengthstarttoend:1351secs(0.38hrs)
- oplogfirsteventtime:ThuMay31201217:49:23GMT+0800(CST)
- oploglasteventtime:ThuMay31201218:11:54GMT+0800(CST)
- now:ThuMay31201218:21:58GMT+0800(CST)
- rs1:PRIMARY>
log length start to end: oplog 日志的启用时间段
oplog first event time: 第一个事务日志的产生时间
oplog last event time: 最后一个事务日志的产生时间
now: 现在的时间
查看slave 的同步状态
- rs1:PRIMARY>db.printSlaveReplicationInfo()
- source:localhost:28011
- syncedTo:ThuMay31201218:11:54GMT+0800(CST)
- =884secsago(0.25hrs)
- source:localhost:28012
- syncedTo:ThuMay31201218:11:54GMT+0800(CST)
- =884secsago(0.25hrs)
- rs1:PRIMARY>
source: 从库的IP 及端口
syncedTo: 目前的同步情况,延迟了多久等信息
主从配置信息
在local库中不仅有主从日志oplog集合,还有一个集合用于记录主从配置信息,即:system.replset
- rs1:PRIMARY>db.system.replset.find()
- {"_id":"rs1","version":1,"members":[
- {
- "_id":0,108); list-style:decimal-leading-zero outside; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "host":"localhost:28010"
- },108); list-style:decimal-leading-zero outside; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "_id":1,108); list-style:decimal-leading-zero outside; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "host":"localhost:28011"
- "_id":2,108); list-style:decimal-leading-zero outside; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "host":"localhost:28012"
- }
- ]}
- rs1:PRIMARY>