在线亚洲黄色-在线亚洲观看-在线亚洲电影-在线亚洲成人-岛国大片在线观看免费版-岛国大片在线播放高清

兩個Redis實例互相SLAVEOF會怎樣?

導讀今天嘗試配置RedisSentinel來監控Redis服務器,中間由于某些設想我突然想到如果兩個Redis實例互相slaveof會怎樣。以下是我的試驗:兩個Redis實例,redis1配置作為master,redis2配置作為slave:slaveofredis1。啟動redis1、redis2。啟動成功并且redis2也成功slaveofredis1后,redis-cli連接redis1,執行命令將redis1設置為redis2的從庫:slaveof[redis2IP][redis2port]執行后的結果是......兩個redis都在重復拋出SYNC命令執行失敗的log,也就是顯然兩個redis不能互相作為從庫。redis1執行slaveof后的log:[14793]06Sep17:36

今天嘗試配置Redis Sentinel 來監控Redis服務器,中間由于某些設想我突然想到如果兩個Redis實例互相slaveof會怎樣。以下是我的試驗: 兩個Redis實例,redis1配置作為master,redis2配置作為slave:slaveof redis1。 啟動redis1、redis2。 啟動成功并且redis2也成功slaveof redis1后,redis-cli連接redis1,執行命令將redis1設置為redis2的從庫: slaveof [redis2 IP][redis2 port] 執行后的結果是......兩個redis都在重復拋出SYNC命令執行失敗的log,也就是顯然兩個redis不能互相作為從庫。 redis1執行slaveof后的log: [14793] 06 Sep 17:36:20.426 * SLAVE OF 10.18.129.49:9778 enabled (user request) [14793] 06 Sep 17:36:20.636 - Accepted 10.18.129.49:44277 [14793] 06 Sep 17:36:20.637 - Client closed connection [14793] 06 Sep 17:36:20.804 * Connecting to MASTER... [14793] 06 Sep 17:36:20.804 * MASTER SLAVE sync started [14793] 06 Sep 17:36:20.804 * Non blocking connect for SYNC fired the event. [14793] 06 Sep 17:36:20.804 * Master replied to PING, replication can continue... [14793] 06 Sep 17:36:20.804 # MASTER aborted replication with an error: ERR Can't SYNC while not connected with my master [14793] 06 Sep 17:36:21.636 - Accepted 10.18.129.49:44279 [14793] 06 Sep 17:36:21.637 - Client closed connection [14793] 06 Sep 17:36:21.804 * Connecting to MASTER... [14793] 06 Sep 17:36:21.804 * MASTER SLAVE sync started [14793] 06 Sep 17:36:21.804 * Non blocking connect for SYNC fired the event. [14793] 06 Sep 17:36:21.804 * Master replied to PING, replication can continue... [14793] 06 Sep 17:36:21.804 # MASTER aborted replication with an error: ERR Can't SYNC while not connected with my master [14793] 06 Sep 17:36:22.636 - Accepted 10.18.129.49:44281 [14793] 06 Sep 17:36:22.637 - Client closed connection [14793] 06 Sep 17:36:22.804 * Connecting to MASTER... [14793] 06 Sep 17:36:22.804 * MASTER SLAVE sync started [14793] 06 Sep 17:36:22.804 * Non blocking connect for SYNC fired the event. [14793] 06 Sep 17:36:22.804 * Master replied to PING, replication can continue.. redis2的log: [14796] 06 Sep 17:36:20.426 - Client closed connection [14796] 06 Sep 17:36:20.636 * Connecting to MASTER... [14796] 06 Sep 17:36:20.636 * MASTER SLAVE sync started [14796] 06 Sep 17:36:20.636 * Non blocking connect for SYNC fired the event. [14796] 06 Sep 17:36:20.636 * Master replied to PING, replication can continue... [14796] 06 Sep 17:36:20.636 # MASTER aborted replication with an error: ERR Can't SYNC while not connected with my master [14796] 06 Sep 17:36:20.804 - Accepted 10.18.129.49:51034 [14796] 06 Sep 17:36:20.805 - Client closed connection [14796] 06 Sep 17:36:21.636 * Connecting to MASTER... [14796] 06 Sep 17:36:21.636 * MASTER SLAVE sync started [14796] 06 Sep 17:36:21.636 * Non blocking connect for SYNC fired the event. [14796] 06 Sep 17:36:21.636 * Master replied to PING, replication can continue... [14796] 06 Sep 17:36:21.637 # MASTER aborted replication with an error: ERR Can't SYNC while not connected with my master [14796] 06 Sep 17:36:21.804 - Accepted 10.18.129.49:51036 [14796] 06 Sep 17:36:21.805 - Client closed connection [14796] 06 Sep 17:36:22.636 - DB 0: 20 keys (0 volatile) in 32 slots HT. [14796] 06 Sep 17:36:22.636 - 0 clients connected (0 slaves), 801176 bytes in use [14796] 06 Sep 17:36:22.636 * Connecting to MASTER... [14796] 06 Sep 17:36:22.636 * MASTER SLAVE sync started [14796] 06 Sep 17:36:22.636 * Non blocking connect for SYNC fired the event. [14796] 06 Sep 17:36:22.636 * Master replied to PING, replication can continue.. 兩個redis就這樣都進入SYNC失敗的死循環狀態。 我想到的疑問是:為什么原來的從庫redis2會重新執行SYNC命令? 從上面的redis2的log第一行可以看到原先的主從連接斷開了。 看了執行主從設置的源碼replication.c,下面是redis1執行slaveof命令的代碼,它在中間執行disconnectSlaves()導致原來的主從連接斷開: void slaveofCommand(redisClient *c) { if (!strcasecmp(c->argv[1]->ptr,"no") &&!strcasecmp(c->argv[2]->ptr,"one")) { // 省略了 } else { // 省略了 /* There was no previous master or the user specified a different one, * we can continue. */ sdsfree(server.masterhost); server.masterhost = sdsdup(c->argv[1]->ptr); server.masterport = port; if (server.master) freeClient(server.master); disconnectSlaves(); /* Force our slaves to resync with us as well. */ cancelReplicationHandshake(); server.repl_state = REDIS_REPL_CONNECT; redisLog(REDIS_NOTICE,"SLAVE OF %s:%d enabled (user request)", server.masterhost, server.masterport); } addReply(c,shared.ok); } disconnectSlaves()旁邊的注解是:Force our slaves to resync with us as well. 意思類似于先把你們(redis2)斷開,等我(redis1)同步我的主庫搞定后你們再來向我同步。這樣導致redis2和redis1斷開了,而redis2一開始作為從庫如果它和主庫斷開它會不斷嘗試重新連接并執行SYNC命令直到成功。 了解了為什么redis2也執行SYNC命令后,第二個疑問是為什么兩個redis的SYNC操作都會一直失敗,實際上原因和第一個差不多。兩個redis的log異常都是:ERR Can't SYNC while not connected with my master。這個log在代碼中是: void syncCommand(redisClient *c) { /* ignore SYNC if already slave or in monitor mode */ if (c->flags & REDIS_SLAVE) return; /* Refuse SYNC requests if we are a slave but the link with our master * is not ok... */ if (server.masterhost && server.repl_state != REDIS_REPL_CONNECTED) { addReplyError(c,"Can't SYNC while not connected with my master"); return; } /* SYNC can't be issued when the server has pending data to send to * the client about already issued commands. We need a fresh reply * buffer registering the differences between the BGSAVE and the current * dataset, so that we can copy to other slaves if needed. */ if (listLength(c->reply) != 0) { addReplyError(c,"SYNC is invalid with pending input"); return; } //省略 } syncCommand函數是Redis作為主庫收到從庫發來的SYNC命令時的處理,看上面注釋部分“Refuse SYNC requests if we are a slave but the link with our master is not ok...”。當redis1作為主庫收到從庫的SYNC命令,會執行syncCommand函數,其中if (server.masterhost && server.repl_state != REDIS_REPL_CONNECTED)... ,redis1剛好設置為別的主庫(redis2)的從庫但還沒完成同步工作(redis1需要向redis2發送SYNC請求并且返回成功才能完成同步,而redis2處理redis1的SYNC請求時又需要redis1處理好redis2的SYNC請求才行,這導致死鎖了),所以這個判斷返回true,redis1直接reply error:Can't SYNC while not connected with my master)。redis2的情況也一樣,所以雙方都處在Can't SYNC while not connected with my master的狀態。

為你推薦
資訊專欄
熱門視頻
相關推薦
有男人用的雙眼皮貼嗎 剛買的阿迪達斯 黑色短袖掉色了怎么辦 美國加州的州稅是多少啊? 怎么改快手密碼 工傷認定書沒有下來,可以去上班嗎? 牛仔褲可以改小嗎? 含桑蠶絲成分很高的衣服,可以用熨斗熨嗎?如果能,大概需要多少溫度?如果不能,那衣服皺了怎么處理呢? 維茲·卡利法的人物生平 冬天摩托車難啟動怎么辦? 辦理進京證必須要車主的身份證嗎 讀書報告與讀后感的區別 為什么要收基本電費 為什么內窺鏡光源叫做冷光源? 用水能泡死螨蟲嗎? 中國的煙草專賣什么時候開放的? 國標2×1.5電纜線可以帶多少個千瓦 自定義“復制粘貼的快捷鍵”的方法有哪些? LED燈有哪些種類,戶外廣告燈箱用哪種 燃氣灶品牌有哪些? 摩托車幾年前被盜沒報案,現該如何注銷 北京市衛生局監督投訴電話是?? 拜托各位了.. 新辦營業執照,地稅報道需要什么資料? 沸石為什么能防止暴沸? 房地產開發企業取得土地使用權繳納的契稅和耕地占用稅是計入“取得土地使用權所支付金額”還是“開發成本 Photoshop里去色的快捷鍵是什么? BOSSsunwen和BOSS是一個品牌嗎 在施工現場安全管理工作有什么建議? YY語音是干嘛的? 男女之間有什么有趣的差異? PS怎么插入表格? 什么叫高級脂肪酸? 一種像螞蟻的黃色小蟲子,捏死后有臭味,還挺重的,有時候會咬人,請問這是什么? 鑄造和冶煉的區別 怎么看牛幾歲!怎么看牛 蘋果里的通用里的訪問限制怎么關閉 潮州的春節習俗 南京方山風景區有玻璃棧道嗎? 瑪瑙怎樣區分是天然的還是人工合成的啊? “建筑工程合同”的范本是什么? 直行是綠燈,左轉彎是紅燈,從左轉彎車道直行是否屬于闖紅燈?
Top 主站蜘蛛池模板: 国产精选在线观看 | 一边摸一边叫床一边爽视频 | 精品综合一区二区三区 | 欧美理论电影在线观看 | 午夜看一级特黄a大片黑 | 国产日韩欧美精品 | 亚洲色图欧美自拍 | 国产va精品免费观看 | 国产二区视频 | 亚洲一区日韩一区欧美一区a | 成人一级免费视频 | 国产高清美女一级a毛片久久 | 欧美色亚洲 | 国产激情一区二区三区成人91 | 美日韩在线视频 | 亚洲一区二区三区精品影院 | 国产日韩在线视频 | 激情另类国内一区二区视频 | 日韩精品免费观看 | 亚洲欧美网站 | 国产在线精品一区二区三区 | 夜夜操夜夜 | 国产成人综合一区精品 | 欧美另类第一页 | 日韩中文在线观看 | 国产伦精品一区二区三区在线观看 | 日韩三级一区二区 | 国产日韩一区二区三区在线观看 | 黄色a免费| 精品欧美一区手机在线观看 | 国产a国产片| 欧美在线免费 | 91综合 | 中文字幕第7页 | 日韩第三页 | 天堂精品高清1区2区3区 | 日韩精品a在线视频 | 国产一区二区三区欧美 | 欧美 韩国 精品 另类 综合 | 天天操夜夜草 | 日韩不卡一区 |