MongoDB 2.0就开始支持链式复制,目的是减少从主库来同步,MongoDB 2.2增加了个replSetSyncFrom的命令用于改变sync Target,但这些对于初始化同步没有作用,因此打算在这方面做个小的改进,有人提出过类似需求,官方半年多了都没人理,见SERVER-7680,最近给mongod加了个参数syncFrom,用于指定初始化同步的sync Target。 测试架构: 10.0.0.45:20011 主库 10.0.0.46:20011 从库 添加一个成员10.0.0.45:20013,设置syncFrom=10.0.0.46:20011,也就是从从库同步数据(默认从closest成员同步,通常是主库),初始化同步完后,切换回主库正常同步,如果再需要指定syncTarget,就可以通过[replSetSyncFrom命令][3]设置了。

Mon Jul  1 13:12:53 [rsSync] sync from:10.0.0.46:20011
Mon Jul  1 13:12:53 [rsSync] replSet syncing to: 10.0.0.46:20011 by request

log:

Mon Jul  1 13:12:53 [rsStart] trying to contact 10.0.0.45:20011
Mon Jul  1 13:12:53 [rsStart] trying to contact 10.0.0.46:20011
Mon Jul  1 13:12:53 [rsStart] replSet I am 10.0.0.45:20013
Mon Jul  1 13:12:53 [rsStart] replSet got config version 2 from a remote, saving locally
Mon Jul  1 13:12:53 [rsStart] replSet info saving a newer config version to local.system.replset
Mon Jul  1 13:12:53 [rsStart] replSet saveConfigLocally done
Mon Jul  1 13:12:53 [rsStart] replSet STARTUP2
Mon Jul  1 13:12:53 [rsSync] ******
Mon Jul  1 13:12:53 [rsMgr] replSet total number of votes is even - add arbiter or give one member an extra vote
Mon Jul  1 13:12:53 [rsSync] creating replication oplog of size: 48701MB...
Mon Jul  1 13:12:53 [rsSync] ******
Mon Jul  1 13:12:53 [rsSync] replSet initial sync pending
Mon Jul  1 13:12:53 [rsSync] sync from:10.0.0.46:20011
Mon Jul  1 13:12:53 [rsSync] replSet syncing to: 10.0.0.46:20011 by request
Mon Jul  1 13:12:53 [rsSync] build index local.me { _id: 1 }
Mon Jul  1 13:12:53 [rsSync] build index done.  scanned 0 total records. 0 secs
Mon Jul  1 13:12:53 [rsSync] replSet initial sync drop all databases
Mon Jul  1 13:12:53 [rsSync] dropAllDatabasesExceptLocal 1
Mon Jul  1 13:12:53 [rsSync] replSet initial sync clone all databases
Mon Jul  1 13:12:53 [rsSync] replSet initial sync cloning db: test
Mon Jul  1 13:12:55 [rsHealthPoll] replSet member 10.0.0.46:20011 is up
Mon Jul  1 13:12:55 [rsHealthPoll] replSet member 10.0.0.46:20011 is now in state SECONDARY
Mon Jul  1 13:12:55 [rsHealthPoll] replSet member 10.0.0.45:20011 is up
Mon Jul  1 13:12:55 [rsHealthPoll] replSet member 10.0.0.45:20011 is now in state PRIMARY
Mon Jul  1 13:13:19 [rsSync] build index test.ccj { _id: 1 }
Mon Jul  1 13:13:29 [rsSync]        6079100/10000000    60%
Mon Jul  1 13:13:35 [rsSync]     external sort used : 10 files  in 16 secs
Mon Jul  1 13:13:45 [rsSync]        4845200/10000000    48%
Mon Jul  1 13:13:53 [rsSync]     done building bottom layer, going to commit
Mon Jul  1 13:13:54 [rsSync]     fastBuildIndex dupsToDrop:0
Mon Jul  1 13:13:54 [rsSync] build index done.  scanned 10000000 total records. 35.45 secs
Mon Jul  1 13:13:54 [rsSync] replSet initial sync cloning db: tuan
Mon Jul  1 13:13:54 [rsSync] build index tuan.team { _id: 1 }
Mon Jul  1 13:13:54 [rsSync]     fastBuildIndex dupsToDrop:0
Mon Jul  1 13:13:54 [rsSync] build index done.  scanned 0 total records. 0 secs
Mon Jul  1 13:13:54 [rsSync] build index tuan.system.users { _id: 1 }
Mon Jul  1 13:13:54 [rsSync]     fastBuildIndex dupsToDrop:0
Mon Jul  1 13:13:54 [rsSync] build index done.  scanned 2 total records. 0 secs
Mon Jul  1 13:13:54 [rsSync] replSet initial sync cloning db: admin
Mon Jul  1 13:13:54 [rsSync] build index admin.system.users { _id: 1 }
Mon Jul  1 13:13:54 [rsSync]     fastBuildIndex dupsToDrop:0
Mon Jul  1 13:13:54 [rsSync] build index done.  scanned 2 total records. 0 secs
Mon Jul  1 13:13:54 [rsSync] replSet initial sync data copy, starting syncup
Mon Jul  1 13:13:54 [rsSync] oplog sync 1 of 3
Mon Jul  1 13:13:54 [rsSync] oplog sync 2 of 3
Mon Jul  1 13:13:54 [rsSync] replSet initial sync building indexes
Mon Jul  1 13:13:54 [rsSync] replSet initial sync cloning indexes for : test
Mon Jul  1 13:13:54 [rsSync] replSet initial sync cloning indexes for : tuan
Mon Jul  1 13:13:54 [rsSync] build index tuan.team { team_id: 1.0 }
Mon Jul  1 13:13:54 [rsSync] build index done.  scanned 0 total records. 0 secs
Mon Jul  1 13:13:54 [rsSync] replSet initial sync cloning indexes for : admin
Mon Jul  1 13:13:54 [rsSync] oplog sync 3 of 3
Mon Jul  1 13:13:54 [rsSync] replSet initial sync finishing up
Mon Jul  1 13:13:54 [rsSync] replSet set minValid=51d0fe0f:2c21
Mon Jul  1 13:13:54 [rsSync] build index local.replset.minvalid { _id: 1 }
Mon Jul  1 13:13:54 [rsSync] build index done.  scanned 0 total records. 0 secs
Mon Jul  1 13:13:54 [rsSync] replSet RECOVERING
Mon Jul  1 13:13:54 [rsSync] replSet initial sync done
Mon Jul  1 13:13:55 [rsBackgroundSync] replSet syncing to: 10.0.0.45:20011
Mon Jul  1 13:13:55 [rsSyncNotifier] replset setting oplog notifier to 10.0.0.45:20011
Mon Jul  1 13:13:56 [rsSync] replSet SECONDARY

[3]: http://nosql-db.com/topic/51cbf8484308d66406097a70

0 回复
需要 登录 后方可回复, 如果你还没有账号你可以 注册 一个帐号。