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

fix(ddl_client): sleep for a while before retry once meta server is busy #1453

Merged
merged 23 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7762625
feat(new_metrics): retry after waiting for an fixed interval while re…
empiredan Apr 13, 2023
4f0affe
feat(new_metrics): retry after waiting for an fixed interval while re…
empiredan Apr 14, 2023
56952a8
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 17, 2023
89a08f1
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 17, 2023
6cdd5bd
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 17, 2023
4cff3ac
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 18, 2023
cea029d
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 18, 2023
7916325
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 18, 2023
520bed2
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 18, 2023
e79ef2f
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 18, 2023
b0cb7db
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 18, 2023
279bcbb
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 18, 2023
958b5eb
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 18, 2023
75a6dca
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 19, 2023
5e1b2e4
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 19, 2023
44f50a2
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 19, 2023
e6080aa
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 20, 2023
c3dd72c
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 20, 2023
7f151dd
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 21, 2023
d6be548
fix(ddl_client): after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPI…
empiredan Apr 21, 2023
4d7d5f7
fix(ddl_client): sleep for a while before retry once meta server is busy
empiredan Apr 22, 2023
b39c7c7
fix(ddl_client): sleep for a while before retry once meta server is busy
empiredan Apr 23, 2023
7d26c9d
fix(ddl_client): sleep for a while before retry once meta server is busy
empiredan Apr 23, 2023
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
96 changes: 84 additions & 12 deletions src/client/replication_ddl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,23 @@
#include "runtime/api_layer1.h"
#include "runtime/rpc/group_address.h"
#include "utils/error_code.h"
#include "utils/flags.h"
#include "utils/fmt_logging.h"
#include "utils/output_utils.h"
#include "utils/time_utils.h"
#include "utils/utils.h"

DSN_DEFINE_uint32(ddl_client,
ddl_client_max_attempt_count,
3,
"The max count that attempt for failed requests to meta server.");

DSN_DEFINE_uint32(ddl_client,
ddl_client_busy_retry_interval_ms,
10 * 1000,
"The retry interval after receiving ERR_BUSY_CREATING or ERR_BUSY_DROPPING from"
"meta server.");

namespace dsn {
namespace replication {

Expand Down Expand Up @@ -1434,23 +1446,83 @@ bool replication_ddl_client::valid_app_char(int c)
return (bool)std::isalnum(c) || c == '_' || c == '.' || c == ':';
}

namespace {

bool is_busy(const dsn::error_code &err)
{
return err == dsn::ERR_BUSY_CREATING || err == dsn::ERR_BUSY_DROPPING;
}

bool need_retry(uint32_t attempt_count, uint32_t busy_attempt_count, const dsn::error_code &err)
{
if (err == dsn::ERR_OK) {
return false;
}

if (attempt_count < FLAGS_ddl_client_max_attempt_count) {
return true;
}

if (!is_busy(err)) {
return false;
}

return busy_attempt_count < FLAGS_ddl_client_max_attempt_count;
}

bool should_sleep_before_retry(const dsn::error_code &err, uint32_t &sleep_ms)
{
if (is_busy(err)) {
sleep_ms = FLAGS_ddl_client_busy_retry_interval_ms;
return true;
}

return false;
}

} // anonymous namespace

void replication_ddl_client::end_meta_request(const rpc_response_task_ptr &callback,
int retry_times,
error_code err,
uint32_t attempt_count,
acelyc111 marked this conversation as resolved.
Show resolved Hide resolved
uint32_t busy_attempt_count,
const error_code &err,
dsn::message_ex *request,
dsn::message_ex *resp)
{
if (err != dsn::ERR_OK && retry_times < 2) {
rpc::call(_meta_server,
request,
&_tracker,
[this, retry_times, callback](
error_code err, dsn::message_ex *request, dsn::message_ex *response) mutable {
end_meta_request(callback, retry_times + 1, err, request, response);
});
} else {
callback->enqueue(err, (message_ex *)resp);
++attempt_count;
if (is_busy(err)) {
++busy_attempt_count;
}

LOG_INFO("attempt {}: attempt_count={}, busy_attempt_count={}, max_replica_count={}, err={}",
request->local_rpc_code,
attempt_count,
busy_attempt_count,
FLAGS_ddl_client_max_attempt_count,
err);

if (!need_retry(attempt_count, busy_attempt_count, err)) {
callback->enqueue(err, (message_ex *)resp);
return;
}

uint32_t sleep_ms = 0;
acelyc111 marked this conversation as resolved.
Show resolved Hide resolved
if (should_sleep_before_retry(err, sleep_ms)) {
LOG_WARNING("sleep {} milliseconds before launch another attempt for {}: err={}",
sleep_ms,
request->local_rpc_code,
err);
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_ms));
}

rpc::call(_meta_server,
request,
&_tracker,
[this, attempt_count, busy_attempt_count, callback](
error_code err, dsn::message_ex *request, dsn::message_ex *response) mutable {
end_meta_request(
callback, attempt_count, busy_attempt_count, err, request, response);
});
}

dsn::error_code replication_ddl_client::get_app_envs(const std::string &app_name,
Expand Down
7 changes: 4 additions & 3 deletions src/client/replication_ddl_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ class replication_ddl_client
bool static valid_app_char(int c);

void end_meta_request(const rpc_response_task_ptr &callback,
int retry_times,
error_code err,
uint32_t attempt_count,
uint32_t busy_attempt_count,
const error_code &err,
dsn::message_ex *request,
dsn::message_ex *resp);

Expand All @@ -278,7 +279,7 @@ class replication_ddl_client
&_tracker,
[this, task](
error_code err, dsn::message_ex *request, dsn::message_ex *response) mutable {
end_meta_request(std::move(task), 0, err, request, response);
end_meta_request(std::move(task), 0, 0, err, request, response);
});
return task;
}
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/task/task_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@ DEFINE_TASK_CODE(TASK_CODE_INVALID, TASK_PRIORITY_COMMON, THREAD_POOL_DEFAULT)
// define a task_code "task_code_inlined", it's mainly used in situations when you want execute
// a task with "inline" mode.
DEFINE_TASK_CODE(TASK_CODE_EXEC_INLINED, TASK_PRIORITY_COMMON, THREAD_POOL_DEFAULT)
}

} // namespace dsn