Chinaunix首页 | 论坛 | 博客
  • 博客访问: 671213
  • 博文数量: 63
  • 博客积分: 1327
  • 博客等级: 中尉
  • 技术积分: 2022
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-19 18:39
文章分类

全部博文(63)

文章存档

2013年(3)

2012年(60)

分类: Mysql/postgreSQL

2012-09-22 22:04:25

主从操作日志oplog

MongoDB的Replica Set架构是通过一个日志来存储写操作的,这个日志就叫做”oplog”。 oplog.rs 是一个固定长度的 capped collection,它存在于”local”数据库中,用于记录 Replica Sets 操作日志。在默认情况下,对于64位的MongoDB,oplog是比较大的,可以达到5%的磁盘空间。oplog的大小是可以通过mongod的参数”—oplogSize”来改变oplog的日志大小。

 

Oplog内容样例:

rs1:PRIMARY> use local

switched to db local

rs1:PRIMARY> show collections

oplog.rs

system.replset

rs1:PRIMARY> db.oplog.rs.find()

{ "ts" : { "t" : 1338457763000, "i" : 1 }, "h" : NumberLong(0), "op" : "n", "ns" : "", "o" : { "msg" : "initiating set" } }

{ "ts" : { "t" : 1338459114000, "i" : 1 }, "h" : NumberLong("5493127699725549585"), "op" : "i", "ns" : "test.c1", "o" : { "_id" : ObjectId("4fc743e9aea289af709ac6b5"), "age" : 29, "name" : "Tony" } }

rs1:PRIMARY>

 

字段说明:

l  ts: 某个操作的时间戳

l  op: 操作类型,如下:

u  i: insert

u  d: delete

u  u: update

l  ns: 命名空间,也就是操作的collectionname

l  o: document的内容

 

查看master的oplog元数据信息:

rs1:PRIMARY> db.printReplicationInfo()

configured oplog size:   47.6837158203125MB

log length start to end: 1351secs (0.38hrs)

oplog first event time:  Thu May 31 2012 17:49:23 GMT+0800 (CST)

oplog last event time:   Thu May 31 2012 18:11:54 GMT+0800 (CST)

now:                     Thu May 31 2012 18:21:58 GMT+0800 (CST)

rs1:PRIMARY>

字段说明:

l  configured oplog size:   配置的oplog文件大小

l  log length start to end: oplog日志的启用时间段

l  oplog first event time:   第一个事务日志的产生时间

l  oplog last event time:   最后一个事务日志的产生时间

l  now:                 现在的时间

 

查看slave的同步状态:

rs1:PRIMARY> db.printSlaveReplicationInfo()

source:   localhost:28011

         syncedTo: Thu May 31 2012 18:11:54 GMT+0800 (CST)

                 = 884secs ago (0.25hrs)

source:   localhost:28012

         syncedTo: Thu May 31 2012 18:11:54 GMT+0800 (CST)

                 = 884secs ago (0.25hrs)

rs1:PRIMARY>

字段说明:

l  source:     从库的IP及端口

l  syncedTo:   目前的同步情况,延迟了多久等信息

阅读(3997) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~