有些时候,有些判断是无法做到真实,但是能做到最优也不错了

来源:互联网 发布:mac怎么保存文档 编辑:程序博客网 时间:2024/06/06 03:45

有些时候,有些判断是无法做到真实,但是能做到最优也不错了

比如
redis cluster的配置参数cluster-slave-validity-factor就运用了这种思维:
A slave of a failing master will avoid to start a failover if its data
looks too old.

There is no simple way for a slave to actually have a exact measure of
its “data age”, so the following two checks are performed:

1) If there are multiple slaves able to failover, they exchange messages
in order to try to give an advantage to the slave with the best
replication offset (more data from the master processed).
Slaves will try to get their rank by offset, and apply to the start
of the failover a delay proportional to their rank.

2) Every single slave computes the time of the last interaction with
its master. This can be the last ping or command received (if the master
is still in the “connected” state), or the time that elapsed since the
disconnection with the master (if the replication link is currently down).
If the last interaction is too old, the slave will not try to failover
at all.

The point “2” can be tuned by user. Specifically a slave will not perform
the failover if, since the last interaction with the master, the time
elapsed is greater than:

(node-timeout * slave-validity-factor) + repl-ping-slave-period

So for example if node-timeout is 30 seconds, and the slave-validity-factor
is 10, and assuming a default repl-ping-slave-period of 10 seconds, the
slave will not try to failover if it was not able to talk with the master
for longer than 310 seconds.

A large slave-validity-factor may allow slaves with too old data to failover
a master, while a too small value may prevent the cluster from being able to
elect a slave at all.

For maximum availability, it is possible to set the slave-validity-factor
to a value of 0, which means, that slaves will always try to failover the
master regardless of the last time they interacted with the master.
(However they’ll always try to apply a delay proportional to their
offset rank).

Zero is the only value able to guarantee that when all the partitions heal
the cluster will always be able to continue.

延伸

NP问题(Non-Deterministic Polynomial Complete Problems)

0 0