标签:
接上一篇博客:http://www.cnblogs.com/xiaoit/p/4522218.html
Primary Secondary Arbiter 1:关闭顺序PSA :会报错 2:关闭顺序PAS :可以 3:关闭顺序SAP :主节点会变为从节点 4:关闭顺序SPA :会报错 5:关闭顺序APS 6:关闭顺序ASP :主节点会变为从节点
1:关闭顺序PSA
gechongrepl:PRIMARY> rs.isMaster() { "setName" : "gechongrepl", "setVersion" : 13, "ismaster" : true, "secondary" : false, "hosts" : [ "192.168.91.133:27017", "192.168.91.132:27017", "192.168.91.132:27018" ], "arbiters" : [ "192.168.91.135:27017" ], "primary" : "192.168.91.133:27017", "me" : "192.168.91.133:27017", "electionId" : ObjectId("5568098a6de3d53a2ea91c64"), "maxBsonObjectSize" : 16777216, "maxMessageSizeBytes" : 48000000, "maxWriteBatchSize" : 1000, "localTime" : ISODate("2015-05-29T06:39:36.548Z"), "maxWireVersion" : 3, "minWireVersion" : 0, "ok" : 1 }
P:
gechongrepl:PRIMARY> use admin switched to db admin gechongrepl:PRIMARY> db.shutdownServer()
S:
从变为了:gechongrepl:PRIMARY>
gechongrepl:PRIMARY> use admin switched to db admin gechongrepl:PRIMARY> db.shutdownServer() assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:48:06.022-0700 Error: assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:48:06.022-0700 at Error (<anonymous>) at doassert (src/mongo/shell/assert.js:11:14) at assert (src/mongo/shell/assert.js:20:5) at DB.shutdownServer (src/mongo/shell/db.js:212:9) at (shell):1:4 2015-05-28T23:48:06.023-0700 E QUERY Error: assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:48:06.022-0700 at Error (<anonymous>) at doassert (src/mongo/shell/assert.js:11:14) at assert (src/mongo/shell/assert.js:20:5) at DB.shutdownServer (src/mongo/shell/db.js:212:9) at (shell):1:4 at src/mongo/shell/assert.js:13
A:
gechongrepl:ARBITER> use admin switched to db admin gechongrepl:ARBITER> db.shutdownServer()
再次关闭S:
S变为了:ggechongrepl:SECONDARY> gechongrepl:SECONDARY> use admin switched to db admin gechongrepl:SECONDARY> db.shutdownServer()
2:关闭顺序PAS : 已经验证,不报错。
3:关闭顺序SAP
S:
gechongrepl:SECONDARY> use admin switched to db admin gechongrepl:SECONDARY> db.shutdownServer()
A:
gechongrepl:ARBITER> use admin switched to db admin gechongrepl:ARBITER> db.shutdownServer()
P:
主变为了:gechongrepl:SECONDARY> gechongrepl:SECONDARY> use admin switched to db admin gechongrepl:SECONDARY> db.shutdownServer()
4:关闭顺序SPA
S:
gechongrepl:SECONDARY> use admin switched to db admin gechongrepl:SECONDARY> db.shutdownServer()
P:
gechongrepl:PRIMARY> use admin switched to db admin gechongrepl:PRIMARY> db.shutdownServer() assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:59:19.685-0700 Error: assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:59:19.685-0700 at Error (<anonymous>) at doassert (src/mongo/shell/assert.js:11:14) at assert (src/mongo/shell/assert.js:20:5) at DB.shutdownServer (src/mongo/shell/db.js:212:9) at (shell):1:4 2015-05-28T23:59:19.702-0700 E QUERY Error: assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:59:19.685-0700 at Error (<anonymous>) at doassert (src/mongo/shell/assert.js:11:14) at assert (src/mongo/shell/assert.js:20:5) at DB.shutdownServer (src/mongo/shell/db.js:212:9) at (shell):1:4 at src/mongo/shell/assert.js:13
A:
gechongrepl:ARBITER> use admin switched to db admin gechongrepl:ARBITER> db.shutdownServer()
再次关闭P:
gechongrepl:PRIMARY> use admin switched to db admin 2015-05-29T00:00:44.938-0700 I NETWORK DBClientCursor::init call() failed 2015-05-29T00:00:44.940-0700 I NETWORK trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 2015-05-29T00:00:44.941-0700 I NETWORK reconnect 127.0.0.1:27017 (127.0.0.1) ok gechongrepl:SECONDARY> db.shutdownServer()
下面猜测:在关闭最后的Primary节点之前,先关掉仲裁节点即不会报错。(首先关掉Primary节点,还有其他Secondary不属于这种情况)
5:关闭顺序APS : 不会报错 6:关闭顺序ASP : 不会报错
验证猜测:
5:关闭顺序APS
A:
gechongrepl:ARBITER> use admin switched to db admin gechongrepl:ARBITER> db.shutdownServer()
P:
gechongrepl:PRIMARY> use admin switched to db admin gechongrepl:PRIMARY> db.shutdownServer()
S:因为仲裁节点关闭了。所以Primary节点不会再自动切换
gechongrepl:SECONDARY> use admin switched to db admin gechongrepl:SECONDARY> db.shutdownServer()
6:关闭顺序ASP
A:
gechongrepl:ARBITER> use admin switched to db admin gechongrepl:ARBITER> db.shutdownServer()
S:
gechongrepl:SECONDARY> use admin switched to db admin gechongrepl:SECONDARY> db.shutdownServer()
P:
gechongrepl:PRIMARY> 2015-05-29T00:12:23.962-0700 I NETWORK DBClientCursor::init call() failed 2015-05-29T00:12:23.965-0700 I NETWORK trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 2015-05-29T00:12:23.966-0700 I NETWORK reconnect 127.0.0.1:27017 (127.0.0.1) ok gechongrepl:SECONDARY> gechongrepl:SECONDARY> use admin switched to db admin gechongrepl:SECONDARY> db.shutdownServer()
总结:
1:先关闭从节点、仲裁节点。或者先关闭仲裁节点,最后关闭从节点。则:主节点自动变为从节点
2:先关闭主节点,则从节点自动变为主节点,在仲裁节点关闭之前,新主节点不能关闭
初始化的时候主从节点受priority的影响
priority: 是优先级,默认为1,优先级0为被动节点,不能成为活跃节点。优先级不位0则按照有大到小选出活跃节点。
标签:
原文地址:http://www.cnblogs.com/xiaoit/p/4538608.html