Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does adding a redis slave issue a blocking call to the master?

It is unclear to me from the documentation on replication whether the SYNC command is blocking.

It seems like it shouldn't be (after all, spinning up a new slave would stop the master from serving requests), but I'd like confirmation of that.

For context, I'm looking at adding a slave to a master hosting about 8GB of data with no disk sync*.

*Historically, data loss has not been a concern. We're changing that, so replication and persistence are being "back ported" to a degree.

like image 959
Kevin Montrose Avatar asked Jan 31 '11 17:01

Kevin Montrose


People also ask

How does Redis master-slave work?

The Redis replication uses an asynchronous method to transfer data from master to slave. The slave periodically acknowledges the received data sent by the master node, and also the master node can have many slaves. Redis can support cascading replication, so the slave can be connected to another slave.

What if Redis master goes down?

Automatic failover. If a master is not working as expected, Sentinel can start a failover process where a slave is promoted to master, the other additional slaves are reconfigured to use the new master, and the applications using the Redis server informed about the new address to use when connecting.

What does Redis master do?

Redis Master does replicate writes to one or more Redis Slaves. The master-slave replication is done asynchronously.


1 Answers

the master will just perform a BGSAVE on SYNC request from the slave, so it's not a blocking operation.

So the sequence is:

  • slave asks for SYNC
  • master BGSAVE, slave waits
  • master BGSAVE finished, the initial bulk data (the .rdb file) is transfered to slave
  • master accumulates all the new differences for the slave
  • master finishes sending the whole initial rdb file to slave
  • master start feeding the slave with the accumulated buffer, and with anything new arriving from clients, if they are writes.

It also works if the master is not configured to save, simply it will produce an .rdb just for master <-> slave synchronization. In master instances configured without "save" lines in redis.conf BGSAVE is not called automatically, but can still be called by the user if there is the need to save an .rdb file.

like image 112
antirez Avatar answered Sep 21 '22 16:09

antirez