Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

fix(bug): resolve static initialization order problem of s_storage_rpc_req_codes #340

Merged
merged 1 commit into from
Nov 19, 2019
Merged
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
2 changes: 1 addition & 1 deletion include/dsn/tool-api/task_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class message_ex;
class admission_controller;
typedef void (*task_rejection_handler)(task *, admission_controller *);

extern std::set<dsn::task_code> s_storage_rpc_req_codes;
std::set<dsn::task_code> &get_storage_rpc_req_codes();

class task_spec : public extensible_object<task_spec, 4>
{
Expand Down
8 changes: 6 additions & 2 deletions src/core/core/task_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ namespace dsn {

constexpr int TASK_SPEC_STORE_CAPACITY = 512;

std::set<dsn::task_code> s_storage_rpc_req_codes;
std::set<dsn::task_code> &get_storage_rpc_req_codes()
{
static std::set<dsn::task_code> s_storage_rpc_req_codes;
return s_storage_rpc_req_codes;
}

// A sequential storage maps task_code to task_spec.
static std::array<std::unique_ptr<task_spec>, TASK_SPEC_STORE_CAPACITY> s_task_spec_store;
Expand Down Expand Up @@ -115,7 +119,7 @@ void task_spec::register_storage_task_code(task_code code,
spec->rpc_request_is_write_allow_batch = allow_batch;
spec->rpc_request_is_write_idempotent = is_idempotent;
if (TASK_TYPE_RPC_REQUEST == type) {
s_storage_rpc_req_codes.insert(code);
get_storage_rpc_req_codes().insert(code);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/dist/replication/lib/replica.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ void replica::init_table_level_latency_counters()

for (int code = 0; code <= max_task_code; code++) {
_counters_table_level_latency[code] = nullptr;
if (s_storage_rpc_req_codes.find(task_code(code)) != s_storage_rpc_req_codes.end()) {
if (get_storage_rpc_req_codes().find(task_code(code)) !=
get_storage_rpc_req_codes().end()) {
std::string counter_str =
fmt::format("table.level.{}.latency(ns)@{}", task_code(code), _app_info.app_name);
_counters_table_level_latency[code] =
Expand Down