From 0b0b46e7a49d67e7c4f4c506e07fc27b8cdb4cc1 Mon Sep 17 00:00:00 2001 From: zhao liwei Date: Tue, 19 Nov 2019 09:11:00 +0800 Subject: [PATCH] fix(bug): resolve static initialization order problem of s_storage_rpc_req_codes (#340) --- include/dsn/tool-api/task_spec.h | 2 +- src/core/core/task_spec.cpp | 8 ++++++-- src/dist/replication/lib/replica.cpp | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/dsn/tool-api/task_spec.h b/include/dsn/tool-api/task_spec.h index bd1b25d4c0..3cd2c80142 100644 --- a/include/dsn/tool-api/task_spec.h +++ b/include/dsn/tool-api/task_spec.h @@ -139,7 +139,7 @@ class message_ex; class admission_controller; typedef void (*task_rejection_handler)(task *, admission_controller *); -extern std::set s_storage_rpc_req_codes; +std::set &get_storage_rpc_req_codes(); class task_spec : public extensible_object { diff --git a/src/core/core/task_spec.cpp b/src/core/core/task_spec.cpp index 3306ffc76d..33788c535a 100644 --- a/src/core/core/task_spec.cpp +++ b/src/core/core/task_spec.cpp @@ -42,7 +42,11 @@ namespace dsn { constexpr int TASK_SPEC_STORE_CAPACITY = 512; -std::set s_storage_rpc_req_codes; +std::set &get_storage_rpc_req_codes() +{ + static std::set s_storage_rpc_req_codes; + return s_storage_rpc_req_codes; +} // A sequential storage maps task_code to task_spec. static std::array, TASK_SPEC_STORE_CAPACITY> s_task_spec_store; @@ -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); } } diff --git a/src/dist/replication/lib/replica.cpp b/src/dist/replication/lib/replica.cpp index 915243919b..3f266670af 100644 --- a/src/dist/replication/lib/replica.cpp +++ b/src/dist/replication/lib/replica.cpp @@ -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] =