Old version master/slave replication

The old master/slave copy has one main operation:

  1. Sync
  2. Command propagate

1. The synchronous

2. Command propagation

Defect:

Full replication is required each time a disconnection is performed, affecting resources

1. The RDB snapshot generated by BGSAVE affects the I/O and CPU resources of the primary server. Transferring a large amount of data wastes network resources. 3. Synchronization from the server is blocked and command requests cannot be processedCopy the code

New version of replication psync

  1. Complete synchronization
  2. Part of the synchronization

Partial synchronization implementation

Repl_backlog_buffer

If the data to be synchronized exceeds the replication backlog, a full copy is required.

PSYNC implementation

Some TRICKY POINT

How to do from too many libraries:

Master slave modeCopy the code

The difference between the repl-backlog-buffer and replication buffer

Repl_backlog_buffer: The circular buffer I explained above is designed to find master/slave differential data once disconnected from the library, thus avoiding the performance overhead of full synchronization. If the slave is disconnected for too long and the repl_backlog_buffer ring buffer is overwritten by the master, the slave will only be able to perform a full synchronization once it is connected to the master, so keep the REPL_backlog_buffer configuration as large as possible to reduce the probability of full synchronization after the slave is disconnected. How to send the data in the repl_backlog_buffer to the slave library? This uses the replication buffer.

2. Replication buffer: Whether Redis communicates with the client or with the slave library, Redis needs to allocate a memory buffer for data interaction. The client is a client, and the slave library is also a client. After connecting each client to Redis, Redis allocates a client buffer through which all data interaction takes place: Redis writes data to this buffer, and then sends the data from the buffer to the client socket over the network. Therefore, in the case of incremental synchronization between master and slave, the slave library, as a client, will also allocate a buffer, but this buffer is specifically used to propagate user write commands to the slave library to ensure data consistency between master and slave. This buffer is usually called replication buffer.

Ref

  • Redis design and implementation