Skip to content

Commit

Permalink
fix: redis cluster fails to auto reconnect (sewenew#199) (sewenew#202)
Browse files Browse the repository at this point in the history
When the connection attempts to known shard masters fail, Redis
cluster client does not attempt to reconnect automatically with
user given connection options.

Co-authored-by: Aras Atalar <[email protected]>

Co-authored-by: Aras Atalar <[email protected]>
Co-authored-by: Aras Atalar <[email protected]>
  • Loading branch information
3 people authored Apr 7, 2021
1 parent dc32893 commit 29a9734
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/sw/redis++/shards_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ ConnectionPoolSPtr ShardsPool::fetch(const Node &node) {

void ShardsPool::update() {
// My might send command to a removed node.
// Try at most 3 times.
for (auto idx = 0; idx < 3; ++idx) {
// Try at most 3 times from the current shard masters and finally with the user given connection options.
for (auto idx = 0; idx < 4; ++idx) {
try {
// Randomly pick a connection.
auto pool = fetch();
assert(pool);
SafeConnection safe_connection(*pool);
auto shards = _cluster_slots(safe_connection.connection());
Shards shards;
if (idx < 3) {
// Randomly pick a connection.
auto pool = fetch();
assert(pool);
SafeConnection safe_connection(*pool);
shards = _cluster_slots(safe_connection.connection());
}
else {
Connection connection(_connection_opts);
shards = _cluster_slots(connection);
}


std::unordered_set<Node, NodeHash> nodes;
for (const auto &shard : shards) {
Expand Down

0 comments on commit 29a9734

Please sign in to comment.