【Mongodb】 replica set 兩種新增節點方法的日誌分析

楊奇龍發表於2011-11-01
    這篇文章算是《replica set 新增和刪除節點》的點綴,本來沒打算檢視新增節點的第二種方法,即複製其他節點的資料檔案到新的節點,本著“入微”的原則,對兩種方法做一下對比,具體新增節點的過程和前面介紹的一樣,只是在啟動mongod服務之前要複製資料檔案到本機。
下面是空庫新增到一個replica set中的日誌記錄:
####連線primary庫
Tue Nov  1 14:22:57 [initandlisten] connection accepted from 10.250.7.220:54235 #2
Tue Nov  1 14:22:57 [initandlisten] connection accepted from 10.250.7.220:54236 #3
Tue Nov  1 14:22:57 [initandlisten] connection accepted from 10.250.7.220:54237 #4
Tue Nov  1 14:22:57 [rsStart] trying to contact 10.250.7.220:27018
Tue Nov  1 14:22:57 [rsStart] trying to contact 10.250.7.220:27019
Tue Nov  1 14:22:57 [rsStart] trying to contact 10.250.7.220:27020
####從primary庫複製replica set的配置資訊,並儲存到本地 -dbpath 指定的檔案目錄####
Tue Nov  1 14:22:57 [rsStart] replSet got config version 2 from a remote, saving locally
Tue Nov  1 14:22:57 [rsStart] replSet info saving a newer config version to local.system.replset
Tue Nov  1 14:22:57 [FileAllocator] allocating new datafile /opt/mongodata/r1/local.ns, filling with zeroes...
Tue Nov  1 14:22:57 [FileAllocator] creating directory /opt/mongodata/r1/_tmp
Tue Nov  1 14:22:57 [FileAllocator] done allocating datafile /opt/mongodata/r1/local.ns, size: 16MB,  took 0.118 secs
Tue Nov  1 14:22:57 [FileAllocator] allocating new datafile /opt/mongodata/r1/local.0, filling with zeroes...
Tue Nov  1 14:23:01 [FileAllocator] done allocating datafile /opt/mongodata/r1/local.0, size: 64MB,  took 3.807 secs
Tue Nov  1 14:23:01 [FileAllocator] allocating new datafile /opt/mongodata/r1/local.1, filling with zeroes...
Tue Nov  1 14:23:02 [rsStart] replSet saveConfigLocally done
Tue Nov  1 14:23:02 [FileAllocator] done allocating datafile /opt/mongodata/r1/local.1, size: 128MB,  took 1.068 secs
Tue Nov  1 14:23:02 [rsStart] replSet STARTUP2
Tue Nov  1 14:23:02 [rsMgr] replSet total number of votes is even - add arbiter or give one member an extra vote
Tue Nov  1 14:23:02 [rsSync] ******
####建立oplog 日誌檔案####
Tue Nov  1 14:23:02 [rsSync] creating replication oplog of size: 944MB...
Tue Nov  1 14:23:02 [FileAllocator] allocating new datafile /opt/mongodata/r1/local.2, filling with zeroes...
Tue Nov  1 14:23:04 [rsHealthPoll] replSet info member 10.250.7.220:27018 is up
Tue Nov  1 14:23:04 [rsHealthPoll] replSet member 10.250.7.220:27018 is now in state SECONDARY
Tue Nov  1 14:23:04 [rsHealthPoll] replSet info member 10.250.7.220:27019 is up
Tue Nov  1 14:23:04 [rsHealthPoll] replSet member 10.250.7.220:27019 is now in state SECONDARY
Tue Nov  1 14:23:04 [rsHealthPoll] replSet info member 10.250.7.220:27020 is up
Tue Nov  1 14:23:04 [rsHealthPoll] replSet member 10.250.7.220:27020 is now in state PRIMARY
Tue Nov  1 14:23:49 [FileAllocator] done allocating datafile /opt/mongodata/r1/local.2, size: 1024MB,  took 46.28 secs
Tue Nov  1 14:23:50 [rsSync] ******
####應用主庫的日誌,複製資料檔案####
Tue Nov  1 14:23:50 [rsSync] replSet initial sync pending
Tue Nov  1 14:23:50 [rsSync] replSet syncing to: 10.250.7.220:27020
Tue Nov  1 14:23:50 [rsSync] build index local.me { _id: 1 }
Tue Nov  1 14:23:50 [rsSync] build index done 0 records 0.003 secs
Tue Nov  1 14:23:50 [rsSync] replSet initial sync drop all databases
Tue Nov  1 14:23:50 [rsSync] dropAllDatabasesExceptLocal 1
Tue Nov  1 14:23:50 [rsSync] replSet initial sync clone all databases
Tue Nov  1 14:23:50 [rsSync] replSet initial sync cloning db: test
Tue Nov  1 14:23:50 [FileAllocator] allocating new datafile /opt/mongodata/r1/test.ns, filling with zeroes...
Tue Nov  1 14:23:51 [FileAllocator] done allocating datafile /opt/mongodata/r1/test.ns, size: 16MB,  took 0.8 secs
Tue Nov  1 14:23:51 [FileAllocator] allocating new datafile /opt/mongodata/r1/test.0, filling with zeroes...
Tue Nov  1 14:23:55 [FileAllocator] done allocating datafile /opt/mongodata/r1/test.0, size: 64MB,  took 3.643 secs
Tue Nov  1 14:23:55 [FileAllocator] allocating new datafile /opt/mongodata/r1/test.1, filling with zeroes...

Tue Nov  1 14:23:55 [rsSync] build index test.yql { _id: 1 }
Tue Nov  1 14:23:56 [rsSync] build index done 1 records 0.006 secs
Tue Nov  1 14:23:56 [rsSync] replSet initial sync query minValid
Tue Nov  1 14:23:56 [rsSync] replSet initial oplog application from 10.250.7.220:27020 starting at Nov  1 14:14:05:1 to Nov  1 14:14:05:1
Tue Nov  1 14:23:57 [rsSync] replSet initial sync finishing up
Tue Nov  1 14:23:57 [rsSync] replSet set minValid=4eaf8e2d:1
Tue Nov  1 14:23:57 [rsSync] build index local.replset.minvalid { _id: 1 }
Tue Nov  1 14:23:57 [rsSync] build index done 0 records 0.023 secs
Tue Nov  1 14:23:57 [rsSync] replSet initial sync done
Tue Nov  1 14:23:58 [rsSync] replSet syncing to: 10.250.7.220:27020
Tue Nov  1 14:23:58 [rsSync] replSet SECONDARY
Tue Nov  1 14:24:02 [FileAllocator] done allocating datafile /opt/mongodata/r1/test.1, size: 128MB,  took 7.428 secs
Tue Nov  1 14:24:16 [clientcursormon] mem (MB) res:16 virt:2848 mapped:1312
Tue Nov  1 14:24:42 [initandlisten] connection accepted from 127.0.0.1:21141 #5
Tue Nov  1 14:29:16 [clientcursormon] mem (MB) res:16 virt:2849 mapped:1312
Tue Nov  1 14:34:16 [clientcursormon] mem (MB) res:16 virt:2913 mapped:1312
Tue Nov  1 14:39:16 [clientcursormon] mem (MB) res:16 virt:2913 mapped:1312
===下面是刪除節點以後的日誌==
Tue Nov  1 14:39:28 [conn2] end connection 10.250.7.220:54235
Tue Nov  1 14:39:29 [rsMgr] replset msgReceivedNewConfig version: version: 3
Tue Nov  1 14:39:29 [rsMgr] replSet info saving a newer config version to local.system.replset
Tue Nov  1 14:39:29 [rsMgr] replSet saveConfigLocally done
Tue Nov  1 14:39:29 [rsMgr] replSet error self not present in the repl set configuration:
Tue Nov  1 14:39:29 [rsMgr] { _id: "myset", version: 3, members: [ { _id: 0, host: "10.250.7.220:27018" }, { _id: 1, host: "10.250.7.220:27019" }, { _id: 2, host: "10.
250.7.220:27020" } ] }
-------------------------------------------------------------------------
這是複製replica set myset 中其他節點的資料檔案!(記住是資料檔案,一定不要mongod.lock 每個mongod程式都需要自己的資料目錄,如果你要執行3個mongod的例項,那麼就需要3個獨自的目錄。mongod啟動的時候會在資料目錄建立一個mongod.lock檔案,阻止其他程式使用此目錄.)
####連線primary庫,這一點和上面一種方法一樣。
Tue Nov  1 15:53:24 [initandlisten] connection accepted from 10.250.7.220:54761 #2
Tue Nov  1 15:53:28 [initandlisten] connection accepted from 10.250.7.220:54763 #3
Tue Nov  1 15:53:28 [initandlisten] connection accepted from 10.250.7.220:54764 #4
Tue Nov  1 15:53:34 [clientcursormon] mem (MB) res:31 virt:2606 mapped:1232
Tue Nov  1 15:53:34 [rsStart] trying to contact 10.250.7.220:27018
Tue Nov  1 15:53:34 [rsStart] trying to contact 10.250.7.220:27019
Tue Nov  1 15:53:34 [rsStart] trying to contact 10.250.7.220:27020
####複製配置檔案,並儲存。這一點和上面一種方法一樣。
Tue Nov  1 15:53:34 [rsStart] replSet got config version 6 from a remote, saving locally
Tue Nov  1 15:53:34 [rsStart] replSet info saving a newer config version to local.system.replset
Tue Nov  1 15:53:34 [rsStart] replSet saveConfigLocally done

Tue Nov  1 15:53:34 [rsStart] replSet STARTUP2
Tue Nov  1 15:53:34 [rsMgr] replSet total number of votes is even - add arbiter or give one member an extra vote
Tue Nov  1 15:53:34 [rsSync] replSet SECONDARY
Tue Nov  1 15:53:34 [rsHealthPoll] replSet info member 10.250.7.220:27018 is up
Tue Nov  1 15:53:34 [rsHealthPoll] replSet member 10.250.7.220:27018 is now in state SECONDARY
Tue Nov  1 15:53:34 [rsHealthPoll] replSet info member 10.250.7.220:27019 is up
Tue Nov  1 15:53:34 [rsHealthPoll] replSet member 10.250.7.220:27019 is now in state SECONDARY
Tue Nov  1 15:53:34 [rsHealthPoll] replSet info member 10.250.7.220:27020 is up
Tue Nov  1 15:53:34 [rsHealthPoll] replSet member 10.250.7.220:27020 is now in state PRIMARY
Tue Nov  1 15:53:34 [rsMgr] replSet can't see a majority, will not try to elect self
Tue Nov  1 15:53:38 [rsSync] replSet syncing to: 10.250.7.220:27020
從上面的日誌來看,整個第二種方法初始化的速度比較快。當然考慮複製資料檔案的時間,在大量資料的時候,才能看到哪一個比較好!
Note:學習mongodb 的時候注意檢視輸出日誌。從裡面能看到很多重要的資訊。如果對mongodb 進行監控的話,也要對輸出日誌進行分析!


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-710057/,如需轉載,請註明出處,否則將追究法律責任。

相關文章