Redis和Zookeeper的复制模式
Redis
redis.conf配置文件里面关于复制的描述:
# 1) Redis replication is asynchronous, but you can configure a master to
# stop accepting writes if it appears to be not connected with at least
# a given number of slaves.
# 2) Redis slaves are able to perform a partial resynchronization with the
# master if the replication link is lost for a relatively small amount of
# time. You may want to configure the replication backlog size (see the next
# sections of this file) with a sensible value depending on your needs.
# 3) Replication is automatic and does not need user intervention. After a
# network partition slaves automatically try to reconnect to masters
# and resynchronize with them.
总结一下, redis为了追求极致性能, 主从复制是异步的, 这个没得商量, 客户端和服务端的交互过程如下:
你可能有疑问, “如果slave挂了, master还一直接受写, 岂不造成数据不一致? ”
所以redis提供了一个可选配置项,当master和多少个slave失去联系之后, 就拒绝再接受写请求了.
即使及时止损, 数据还是可能会出现一定程度的不一致, 怎么办?
其实redis有一套非常重要的机制, 那就是当slave和master失去了联系之后, slave会自动重连并执行“局部再同步”partial resynchronization, 以确保数据的最终一致性.
Zookeeper
与redis追求极致性能不同, zk主从复制是同步的, 只要有一半以上的从节点复制成功就行了, 所以也不会太耗性能, 客户端和服务端的交互过程如下:
以上是 Redis和Zookeeper的复制模式 的全部内容, 来源链接: utcz.com/z/511016.html