8

我想知道复制在分布式数据库中是如何工作的。如果能以一种透彻而又易于理解的方式来解释这一点,那就太好了。

如果您可以在分布式事务和分布式复制之间进行比较,那也很好。

4

3 回答 3

22

Single point of failure

The database server is a central part of an enterprise system, and, if it goes down, service availability might get compromised.

Single point of failure

If the database server is running on a single server, then we have a single point of failure. Any hardware issue (e.g., disk drive failure) or software malfunction (e.g., driver problems, malfunctioning updates) will render the system unavailable.

Limited resources

If there is a single database server node, then vertical scaling is the only option when it comes to accommodating a higher traffic load. Vertical scaling, or scaling up, means buying more powerful hardware, which provides more resources (e.g., CPU, Memory, I/O) to serve the incoming client transactions.

Up to a certain hardware configuration, vertical scaling can be a viable and simple solution to scale a database system. The problem is that the price-performance ratio is not linear, so after a certain threshold, you get diminishing returns from vertical scaling.

Another problem with vertical scaling is that, in order to upgrade the server, the database service needs to be stopped. So, during the hardware upgrade, the application will not be available, which can impact underlying business operations.

Database Replication

To overcome the aforementioned issues associated with having a single database server node, we can set up multiple database server nodes. The more nodes, the more resources we will have to process incoming traffic.

Also, if a database server node is down, the system can still process requests as long as there are spare database nodes to connect to. For this reason, upgrading the hardware or software of a given database server node can be done without affecting the overall system availability.

The challenge of having multiple nodes is data consistency. If all nodes are in-sync at any given time, the system is Linearizable, which is the strongest guarantee when it comes to data consistency across multiple registers.

The process of synchronizing data across all database nodes is called replication, and there are multiple strategies that we can use.

Single-Primary Database Replication

The Single-Primary Replication scheme looks as follows:

Single-Primary Database Replication

The primary node, also known as the Master node, is the one accepting writes while the replica nodes can only process read-only transactions. Having a single source of truth allows us to avoid data conflicts.

To keep the replicas in-sync, the primary nodes must provide the list of changes that were done by all committed transactions.

Relational database systems have a Redo Log, which contains all data changes that were successfully committed.

PostgreSQL uses the WAL (Write-Ahead Log) records to ensure transaction Durability and for Streaming Replication.

Because the storage engine is separated from the MySQL server, MySQL uses a separate Binary Log for replication. The Redo Log is generated by the InnoDB storage engine, and its goal is to provide transaction Durability while the Binary Log is created by the MySQL Server, and it stores the logical logging records, as opposed to physical logging created by the Redo Log.

By applying the same changes recorded in the WAL or Binary Log entries, the replica node can stay in-sync with the primary node.

Horizontal scaling

The Single-Primary Replication provides horizontal scalability for read-only transactions. If the number of read-only transactions increases, we can create more replica nodes to accommodate the incoming traffic.

This is what horizontal scaling, or scaling out, is all about. Unlike vertical scaling, which requires buying more powerful hardware, horizontal scaling can be achieved using commodity hardware.

On the other hand, read-write transactions can only be scaled up (vertical scaling) as there is a single primary node.

于 2020-05-26T20:11:30.100 回答
0

Clustrix 是一个分布式数据库,具有无共享架构,支持分布式事务和复制。有一些可用的技术文档描述了数据分布分布式评估模型和内置的容错,以及架构的概述。

作为 MySQL 的替代品,Clustrix 实现了 MySQL 的复制策略并生成 MySQL 格式的 binlog,这些 binlog 被序列化,以便 Clustrix 可以充当 MySQL 的 Master 或 Slave。

于 2013-05-07T23:29:18.903 回答
0

我建议最初花时间查看 MySQL Docs on Replication。这是数据库复制的一个很好的例子。他们在这里:

http://dev.mysql.com/doc/refman/5.5/en/replication.html

对于一个问题来说,涵盖您问题的整个范围似乎太多了。

如果您有一些具体问题,请随时发布。谢谢!

于 2012-05-11T01:19:54.363 回答