Open antoniomuso opened 3 years ago
I think this could be done subscribing to sdown|odown
channel on sentinel instance and mapping the state of the slaves as they and fallback to using the master. Also, but resource wasteful, by long polling SENTINEL REPLICAS <master name>
The reverse (failover to a slave
when using master
role) would be useful too. My initial idea about this is in https://github.com/luin/ioredis/issues/840.
I think a unavailable master can be detected via error MASTERDOWN
, not sure if a similar error code exist for the reverse situation. Main challenge about this is probably the recovery.
Yeah new roles like master-slave
and slave-master
sgtm.
Don't feel we need to subscribe to any events as ioredis will reconnect when the connected server is down so the only thing we need to do is to add the fallback logic in https://github.com/luin/ioredis/blob/main/lib/connectors/SentinelConnector/index.ts#L328
The only case it won't work is when the master is down but the connection to the server is still live. But it should be a separate job that has already been addressed by https://github.com/luin/ioredis/blob/main/lib/connectors/SentinelConnector/FailoverDetector.ts.
I think can be useful (in a sentinel environment where
role: 'slave'
) to have an option to failover on master when there aren't slaves alive.