MongoDB複本集配置系列四:節點的關閉順序

來源:互聯網
上載者:User

標籤:

接上一篇部落格:http://www.cnblogs.com/xiaoit/p/4522218.html

Primary Secondary Arbiter1:關閉順序PSA :會報錯2:關閉順序PAS :可以3:關閉順序SAP :主節點會變為從節點4:關閉順序SPA :會報錯5:關閉順序APS6:關閉順序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 adminswitched to db admingechongrepl:PRIMARY> db.shutdownServer()

S:

從變為了:gechongrepl:PRIMARY>

gechongrepl:PRIMARY> use adminswitched to db admingechongrepl:PRIMARY> db.shutdownServer()assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:48:06.022-0700Error: assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:48:06.022-0700at 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:42015-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-0700at 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 adminswitched to db admingechongrepl:ARBITER> db.shutdownServer()

  

  

再次關閉S:

S變為了:ggechongrepl:SECONDARY> gechongrepl:SECONDARY> use adminswitched to db admingechongrepl:SECONDARY> db.shutdownServer()

  

2:關閉順序PAS : 已經驗證,不報錯。

3:關閉順序SAP

S:

gechongrepl:SECONDARY> use adminswitched to db admingechongrepl:SECONDARY> db.shutdownServer()

  

A:

gechongrepl:ARBITER> use adminswitched to db admingechongrepl:ARBITER> db.shutdownServer()

  

P:

主變為了:gechongrepl:SECONDARY>gechongrepl:SECONDARY> use adminswitched to db admingechongrepl:SECONDARY> db.shutdownServer()

  

 

4:關閉順序SPA

S:

gechongrepl:SECONDARY> use adminswitched to db admingechongrepl:SECONDARY> db.shutdownServer()

P:

gechongrepl:PRIMARY> use adminswitched to db admingechongrepl:PRIMARY> db.shutdownServer()assert failed : unexpected error: Error: shutdownServer failed: No electable secondaries caught up as of 2015-05-28T23:59:19.685-0700Error: 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:42015-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 adminswitched to db admingechongrepl:ARBITER> db.shutdownServer()

  

再次關閉P:

gechongrepl:PRIMARY> use adminswitched to db admin2015-05-29T00:00:44.938-0700 I NETWORK  DBClientCursor::init call() failed2015-05-29T00:00:44.940-0700 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed2015-05-29T00:00:44.941-0700 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) okgechongrepl:SECONDARY> db.shutdownServer()

  

下面猜測:在關閉最後的Primary節點之前,先關掉仲裁節點即不會報錯。(首先關掉Primary節點,還有其他Secondary不屬於這種情況)

5:關閉順序APS : 不會報錯6:關閉順序ASP : 不會報錯



驗證猜測:

5:關閉順序APS

A:

gechongrepl:ARBITER> use adminswitched to db admingechongrepl:ARBITER> db.shutdownServer()

  

P:

gechongrepl:PRIMARY> use adminswitched to db admingechongrepl:PRIMARY> db.shutdownServer()

  

S:因為仲裁節點關閉了。所以Primary節點不會再自動切換

gechongrepl:SECONDARY> use adminswitched to db admingechongrepl:SECONDARY> db.shutdownServer()

  

6:關閉順序ASP

A:

gechongrepl:ARBITER> use adminswitched to db admingechongrepl:ARBITER> db.shutdownServer()

  

S:

gechongrepl:SECONDARY> use adminswitched to db admingechongrepl:SECONDARY> db.shutdownServer()

  

P:

gechongrepl:PRIMARY> 2015-05-29T00:12:23.962-0700 I NETWORK  DBClientCursor::init call() failed2015-05-29T00:12:23.965-0700 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed2015-05-29T00:12:23.966-0700 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) okgechongrepl:SECONDARY> gechongrepl:SECONDARY> use adminswitched to db admingechongrepl:SECONDARY> db.shutdownServer()

  

總結:

1:先關閉從節點、仲裁節點。或者先關閉仲裁節點,最後關閉從節點。則:主節點自動變為從節點

2:先關閉主節點,則從節點自動變為主節點,在仲裁節點關閉之前,新主節點不能關閉

 

初始化的時候主從節點受priority的影響

priority: 是優先順序,預設為1,優先順序0為被動節點,不能成為活躍節點。優先順序不位0則按照有大到小選出活躍節點。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MongoDB複本集配置系列四:節點的關閉順序

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.