YugaByte DB 的复制模型如何?

How is YugaByte DB's replication model?

与PostgreSQL主从复制相比,YugaByte DB的复制模型有何相似或不同?

PostgreSQL 是单节点 RDBMS。表格不会水平 partitioned/sharded 分成更小的组件,因为无论如何所有数据都是从单个节点提供的。在高可用性 (HA) 部署中,使用主从节点对。 master负责处理writes/updates到数据。提交的数据被异步复制到一个完全独立的 "slave" 实例。在主服务器发生故障时,应用程序客户端可以开始与从实例对话,并警告他们不会看到最近在主服务器上提交但尚未复制到从服务器的数据。通常master-to-slave failover,master repair和slave-to-master failback都是手动处理的。

另一方面,YugaByte DB 是 Google Spanner-inspired distributed RDBMS where HA deployments start with a minimum of 3 nodes. Tables are horizontally partitioned/sharded into smaller components called "tablets". Tablets are distributed to all the available nodes evenly. Each tablet is made resilient to failures by automatically storing 2 additional copies on 2 additional nodes, leading to a total of 3 copies. These 3 copies are known as a tablet group. Instead of managing replication at the overall instance level involving all of the data (as PostgreSQL does), YugaByte DB's replication is managed at the individual tablet group level using a distributed consensus protocol called Raft.

Raft(连同称为 Leader Leases 的机制)确保 3 个副本中只有 1 个可以成为领导者(负责服务 writes/updates 和强一致性读取)。给定行的写入由相应的 tablet leader 处理,该 tablet leader 在向客户端应用程序确认成功之前在本地提交数据以及至少 1 个 follower。节点丢失会导致该节点上托管的平板电脑领导者丢失。在剩下的追随者中自动选出新的平板电脑领导者之前,无法处理这些平板电脑上的新更新。这种自动选择通常需要几秒钟,主要取决于节点间的网络延迟。选举完成后,集群准备好接受写入,即使是受节点故障影响的 tablets。

YugaByte DB 遵循的 Google Spanner 设计确实需要比 PostgreSQL 多提交一份数据,这意味着与 PostgreSQL 相比写入延迟增加。但在 return 中,带来的好处是内置修复(通过领导者自动选举)和故障转移(选举后到新领导者)。甚至故障回复(在故障节点重新联机之后)也是自动的。 当基础架构 运行 数据库集群预计比以前更频繁地失败时,这种设计是更好的选择。

有关详细信息,请参阅我关于此主题的 post