Add a new cluster option
Closed this issue · 0 comments
Hi!
We have used radix recently and it really helps a lot. Thx for the excellent work.
In our situation, we have dozens of addresses, and some may be unuseable at the time due to problems such as unstable network. When calls NewCluster to get a Cluster instance, it will try to create connections for every address provided and return an error immediately if any one of the addresses is found to be unconnected. As a result, the NewCluter will exit with an error and our program can not start successfully. In fact, such situation is really common and the address is just temporarily unavailable. We noticed that if the pool for address is empty, radix client will try to create a new one when synchronizing or executing cmd. Besides, if some nodes really fail, redis server will take measures to ensure the availability of the cluster. So we think it is acceptable that errors of creating pool during the initialization do not cause the cluster instance fail to be created.
What we change:
Here we add an option called initSyncSilent to clusterOpts. If initSyncSilent is set to true, the Sync will not return an error if it fails to create pool for part of the addresses during initializing a cluster. Note that this option will only be applied to Sync when creating a new cluster instance and does not change cluster's behavior at other times. Here is the pr: #247
on summary:
- The setting we add is optional and the default is off.
- If initSyncSilent is set to true, it will only change the cluster's behavior during initialization. In detail, errors of creating pool for every address provided will be ignored when calls NewCluster. This can reduce the failure rate of creating a new cluster instance.
- Even if the address is unavailable, the client will find it when calls Sync or Do, and return an error as expected. This provides a guarantee for availability.
Test:
In addition to the unit tests, we have conducted some experiments to verify the changes. The cluster includes 6 nodes. And connection requests to one master node from the redis client have been dropped temporarily. Then we tried to call Sync, set data to slots of the node and get data from the slots.
When the initSyncSilent was set to true, the client started successfully. But if the node was still unconnected, calls of Sync and cmds of getting and setting would get an error. On the contrary, it worked normally if the node had recovered. The results are consistent with the unit tests results.