聊聊 Undermoo -為 Memory Broker 設(shè)置備份
項(xiàng)目地址:https://github.com/doyoubi/undermoon
為 Memory Broker 設(shè)置 Replica
構(gòu)建二進(jìn)制文件:
$ cargo build
運(yùn)行 replica
$ RUST_LOG=warp=info,undermoon=info,mem_broker=info UNDERMOON_ADDRESS=127.0.0.1:8899 UNDERMOON_META_FILENAME=metadata2 target/debug/mem_broker
運(yùn)行 master Memory
$ RUST_LOG=warp=info,undermoon=info,mem_broker=info UNDERMOON_REPLICA_ADDRESSES=127.0.0.1:8899 UNDERMOON_SYNC_META_INTERVAL=3 target/debug/mem_broker
# Put some data to the master:
$ ./examples/mem-broker/init.sh
# Verify that on master:
curl localhost:7799/api/v3/metadata
...
# Verify tat on replica after 3 seconds:
curl localhost:7799/api/v3/metadata
...
# Replica should have the same data as master.
請(qǐng)注意,當(dāng) master 失敗時(shí),整個(gè)系統(tǒng)將 不會(huì) 自動(dòng)故障回退到 replica。你需要通過(guò)調(diào)用 coordinator 的 API 來(lái)實(shí)現(xiàn)。在此期間,服務(wù)器代理仍然能夠處理請(qǐng)求,但整個(gè)系統(tǒng)無(wú)法為服務(wù)器代理擴(kuò)展和故障轉(zhuǎn)移,直到 coordinator 的 Memory Broker 端點(diǎn)切換到 replica。
假設(shè)您已經(jīng)運(yùn)行了一個(gè) coordinator:
$ RUST_LOG=undermoon=info,coordinator=info target/debug/coordinator conf/coordinator.toml
然后,您可以通過(guò)連接到 Redis 協(xié)議中的 coordinator 并更改配置來(lái)將 master 更改為 replica。
# 6699 is the port of coordinators.
$ redis-cli -p 6699 CONFIG SET brokers 127.0.0.1:8899
主 memory broker 的最新 metadata 還沒(méi)有被復(fù)制到 replica memory broker,因此失敗了。我們不能恢復(fù)丟失的數(shù)據(jù),但是我們可以通過(guò)從所有記錄的代理中收集 epoch 來(lái)增加元數(shù)據(jù) epoch 以恢復(fù)服務(wù)。
所以我們也需要在重新配置 coordinator 后調(diào)用這個(gè) API。
$ curl -XPUT localhost:7799/api/v3/epoch/recovery
現(xiàn)在系統(tǒng)應(yīng)該能夠再次工作。