Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add retry times parameters #498

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/sw/redis++/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ struct ConnectionOptions {

std::chrono::milliseconds socket_timeout{0};

int command_retry = 1;

int shards_update_retry = 3;

tls::TlsOptions tls;

// `readonly` is only used for reading from a slave node in Redis Cluster mode.
Expand Down
2 changes: 2 additions & 0 deletions src/sw/redis++/redis_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,8 @@ class RedisCluster {
template <typename Output, typename Cmd, typename ...Args>
ReplyUPtr _score_command(Cmd cmd, Args &&... args);

int command_retry() { return _pool.command_retry(); }

ShardsPool _pool;
};

Expand Down
2 changes: 1 addition & 1 deletion src/sw/redis++/redis_cluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ ReplyUPtr RedisCluster::_command(Cmd cmd, Connection &connection, Args &&...args

template <typename Cmd, typename ...Args>
ReplyUPtr RedisCluster::_command(Cmd cmd, const StringView &key, Args &&...args) {
for (auto idx = 0; idx < 2; ++idx) {
for (auto idx = 0; idx < command_retry() + 1; ++idx) {
try {
auto pool = _pool.fetch(key);
assert(pool);
Expand Down
6 changes: 6 additions & 0 deletions src/sw/redis++/redis_uri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ void Uri::_set_option(const std::string &key, const std::string &val) {
_opts.socket_timeout = _parse_timeout_option(val);
} else if (key == "resp") {
_opts.resp = _parse_int_option(val);
} else if (key == "command_retry") {
auto retry = _parse_int_option(val);
_opts.command_retry = retry >= 0 ? retry : 1;
} else if (key == "shards_update_retry") {
auto retry = _parse_int_option(val);
_opts.shards_update_retry = retry >= 0 ? retry : 3;
} else if (key == "pool_size") {
_pool_opts.size = _parse_int_option(val);
} else if (key == "pool_wait_timeout") {
Expand Down
5 changes: 3 additions & 2 deletions src/sw/redis++/shards_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ ConnectionPoolSPtr ShardsPool::fetch(const Node &node) {
void ShardsPool::update() {
// My might send command to a removed node.
// 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) {
auto retry = shards_update_retry();
for (auto idx = 0; idx < retry + 1; ++idx) {
try {
Shards shards;
if (idx < 3) {
if (idx < retry) {
// Randomly pick a connection.
auto pool = fetch();
assert(pool);
Expand Down
4 changes: 4 additions & 0 deletions src/sw/redis++/shards_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class ShardsPool {

Shards shards();

int command_retry() { return _connection_opts.command_retry; }

private:
void _move(ShardsPool &&that);

Expand Down Expand Up @@ -99,6 +101,8 @@ class ShardsPool {

NodeMap::iterator _add_node(const Node &node);

int shards_update_retry() { return _connection_opts.shards_update_retry; }

ConnectionPoolOptions _pool_opts;

ConnectionOptions _connection_opts;
Expand Down