predis/predis

Consider master-link-status state when selecting slaves

Opened this issue · 0 comments

Describe the bug
When a slave server in a Sentinel setup is restarted, the s_down flag for the server is cleared before the server is ready to serve requests. While loading or syncronizing data, the master-link-status for the server returns 'err'. Once the slave is fully synchronized and available, the master-link-status switches to 'ok'.

Currently predis only looks at the server flags ($slave[9]), which is not sufficient.

To Reproduce
Steps to reproduce the behavior:

  1. Restart a server in a Sentinel cluster. If the database contains a lot of data and is configured to use an AOF file, this will require a full resync with the master, which will take some time.
  2. Connect to the Sentinel cluster using predis while the server is syncing and perform a read query. This is likely to return a "LOADING Redis is loading the dataset in memory" response.

Expected behavior
The slave should not be selected before it is ready to serve data. The read query should not fail with a "LOADING" response.

Versions (please complete the following information):

  • Predis: 1.x, 2.x
  • PHP 8.1 (does not matter)
  • Redis Server 7.2.4 (I don't think is matters)
  • OS Ubuntu 22.04

Code sample
If applicable, a small snippet of code that reproduces the issue.

Additional context
Same issue as bug #542.

I'll create a pull request to make predis filter out slaves based on the master-link-status state.