2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Redis Sentinel構成のQuorumを理解する

Posted at

概要

sentinel.confに書く

sentinel.conf
# sentinel monitor <master-name> <ip> <redis-port> <quorum>
sentinel monitor mymaster 127.0.0.1 6379 2

の最後に付いてる2の話です。

結論

Sentinel構成台数は奇数にして、quorumには台数/2(切り捨て)+1を設定する。

※quorumを低くしたり、高くしたりすると、フェイルオーバーしにくくなったり、しやすくなったりするので、そのような挙動が良い場合は、下の方(最低稼働台数≠quorumの場合はどうなる?)参照。

なぜSentinel構成台数は奇数にするのか?

Sentinel構成台数と、最低稼働台数の関係は、下表のようになります。

Sentinel構成台数 最低稼働台数 ダウン許容台数
3 2 1
4 3 1
5 3 2
6 3 2
7 4 3

3台→4台、5台→6台に増やしても、ダウン許容台数が増えないので、コスパが悪いというのが理由になります。
そしてquorumには、最低稼働台数と同じ値を設定します。

Sentinelのフェイルオーバーの判断

ドキュメントに記載されています。
(参考)
Redis Sentinel Documentation – Redis
※パーマリンクないので補足すると、かなり下の方です。

The previous sections showed that every master monitored by Sentinel is associated to a configured quorum. It specifies the number of Sentinel processes that need to agree about the unreachability or error condition of the master in order to trigger a failover.

However, after the failover is triggered, in order for the failover to actually be performed, at least a majority of Sentinels must authorize the Sentinel to failover. Sentinel never performs a failover in the partition where a minority of Sentinels exist.

意訳すると、下記2つを満たすことが条件です。

  1. フェイルオーバーのトリガー
    • quorum数のSentinelプロセスが、マスターの到達不能またはエラー状態について合意する
  2. フェイルオーバーの実行
    • 大多数のSentinelプロセスが、フェイルオーバーを許可する

大多数ってのがあいまいなんですが、等しいのはダメなので、3台なら2台(2>1)、4台なら3台(3>1)5台なら3台(3>2)、つまり、元の台数/2(切り捨て)+1が大多数に該当します。

最低稼働台数≠quorumの場合はどうなる?

これもドキュメントの同じところに記載されています。

(参考)
Redis Sentinel Documentation – Redis

  1. If a the quorum is set to a value smaller than the majority of Sentinels we deploy, we are basically making Sentinel more sensitive to master failures, triggering a failover as soon as even just a minority of Sentinels is no longer able to talk with the master.
  2. If a quorum is set to a value greater than the majority of Sentinels, we are making Sentinel able to failover only when there are a very large number (larger than majority) of well connected Sentinels which agree about the master being down.

つまり、

  • quorum < 最低稼働台数の場合、フェイルオーバーしやすくなる
  • quorum > 最低稼働台数の場合、フェイルオーバーしにくくなる

ということですね。

実験

5台構成のRedis Sentinel構成を組んで、quorum=3のときと、quorum=4のときを比べてみました。

手順

  1. master1台+replica4台のRedis Sentinel構成を構築する
  2. masterのサーバを停止する
    3. replicaのどれかにフェイルオーバーする
  3. フェイルオーバーしたmasterのサーバをさらに停止する
    4. 残ったreplicaのどれかにフェイルオーバーする(はず)

結果

quorum=3の場合

手順2、手順3いずれもフェイルオーバーした(想定通り)

quorum=4の場合

手順2ではフェイルオーバーしたが、手順3ではフェイルオーバーしなかった。
フェイルオーバーのトリガーのためのSentinelプロセス数を満たさなかったためと思われる。(replica -> masterへのコネクションフェイルが延々と出続けた)

Sentinel構成を組んで、フェイルオーバーしたくないっていうのは、どういうケースか分からないので(kubernetesとかですぐ復活する場合?)、通常は、quorum=最低稼働台数とすると良いと思います。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?