Primary - Mirror Distribution Strategy

This document introduces the mirror distribution strategy in the YMatrix database system.

When deploying a YMatrix database system, you can configure the mirror node (Mirror) on the host.

  • Function:
    • When the data primary node (Primary) goes down, Mirror can transfer database queries to the backup node.
    • Mirror keeps synchronized by syncing data from Primary to Mirror's transaction log replication process.
  • Best Practices:
    • Each Mirror node instance must be deployed to a different machine with its corresponding Primary node instance to prevent the impact of stand-alone failures.

Notes!
The Mirror mechanism is highly recommended to be turned on in production environments.

1 Greenplum mirror distribution strategy

Before elaborating YMatrix's mirror distribution strategy, we first use Greenplum's mirror distribution strategy as background knowledge to lay the groundwork. Greenplum can use two standard mirroring configurations: Group Mirroring and Spread Mirroring, where the group mirroring is its default configuration.

1.1 Hash mirror distribution

Hash mirror distribution spreads the Mirror of each host to the remaining hosts in the cluster and requires more hosts in the cluster than the Primary on each host.
To ensure an average spread, the number of independent hosts in the array must be greater than the number of node examples on each host.

![](https://img.ymatrix.cn/ymatrix_home/hash mirror distribution (screenshot)_1689234437.png)

1.2 Group mirror distribution

Group image distribution treats all the Mirrors of Primary on the same host as one group and are placed together on another host in the cluster.
This is Greenplum's default mirror distribution strategy.

![](https://img.ymatrix.cn/ymatrix_home/group distribution (screenshot)_1689234443.png)

2 YMatrix mirror distribution strategy

YMatrix adopts the Ring Mirroring strategy by default: that is, when there are at least two hosts, the Primary serial number sequence in one host is regarded as a one-dimensional paper tape, folded in half from the middle, and then arrange the Mirror evenly to other hosts from the folded intermediate serial number as the starting point on another host. The addition of a new Primary will not affect the previously distributed closed loop of the mirror, but will open a new mirror loop.
This is YMatrix's default mirror distribution strategy.

![](https://img.ymatrix.cn/ymatrix_home/ring distribution (screenshot)_1689234430.png)

This strategy is a compromise method by neutralizing the pros and cons of the above two strategies. For comparison of the three strategies, please see the table below:

| | Hash distribution | Group distribution | Annular distribution | |--|--|--|--|--| | System Stable | Unstable | Stable | More Stable | | Load balancing | Balance | Unbalanced | More balanced |

Notes!
If you want to use a mirror distribution policy in YMatrix other than the Ring policy, you can do this by customizing the configuration mxaddmirrors.