From e43242fe4476eb9cd5502108f6a74ed7e99a30f9 Mon Sep 17 00:00:00 2001 From: xy0 Date: Fri, 8 Apr 2022 14:00:52 +0800 Subject: [PATCH] support asan in 3.1_opensource_release --- deps/oblib/src/lib/allocator/ob_tc_malloc.cpp | 36 +++++----- src/observer/ob_server.cpp | 68 ++++++++++--------- src/observer/ob_signal_handle.cpp | 4 +- src/storage/blocksstable/ob_data_buffer.cpp | 22 +++--- 4 files changed, 70 insertions(+), 60 deletions(-) diff --git a/deps/oblib/src/lib/allocator/ob_tc_malloc.cpp b/deps/oblib/src/lib/allocator/ob_tc_malloc.cpp index 86f14f5a11..68b77733dc 100644 --- a/deps/oblib/src/lib/allocator/ob_tc_malloc.cpp +++ b/deps/oblib/src/lib/allocator/ob_tc_malloc.cpp @@ -71,25 +71,25 @@ static uint64_t up2align(uint64_t x, uint64_t align) #define __DIRECT_MALLOC__ __DM_MMAP_ALIGNED #if __DIRECT_MALLOC__ == __DM_MALLOC -void* direct_malloc(int64_t size) +void *direct_malloc(int64_t size) { return ::malloc(size); } -void direct_free(void* p, int64_t size) +void direct_free(void *p, int64_t size) { UNUSED(size); ::free(p); } #elif __DIRECT_MALLOC__ == __DM_MMAP -void* direct_malloc(int64_t size) +void *direct_malloc(int64_t size) { - void* p = NULL; + void *p = NULL; if (MAP_FAILED == (p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0))) { p = NULL; } return p; } -void direct_free(void* p, int64_t size) +void direct_free(void *p, int64_t size) { if (NULL != p) { munmap(p, size); @@ -98,9 +98,9 @@ void direct_free(void* p, int64_t size) #elif __DIRECT_MALLOC__ == __DM_MMAP_ALIGNED const static uint64_t MMAP_BLOCK_ALIGN = 1ULL << 21; -inline void* mmap_aligned(uint64_t size, uint64_t align) +inline void *mmap_aligned(uint64_t size, uint64_t align) { - void* ret = NULL; + void *ret = NULL; if (MAP_FAILED == (ret = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0))) { ret = NULL; } else if (is_aligned((uint64_t)ret, align)) { @@ -115,19 +115,19 @@ inline void* mmap_aligned(uint64_t size, uint64_t align) uint64_t trailer_size = (uint64_t)ret + align - aligned_addr; munmap(ret, header_size); - munmap((void*)(aligned_addr + size), trailer_size); - ret = (void*)aligned_addr; + munmap((void *)(aligned_addr + size), trailer_size); + ret = (void *)aligned_addr; } } return ret; } -void* direct_malloc(int64_t size) +void *direct_malloc(int64_t size) { return mmap_aligned(size, MMAP_BLOCK_ALIGN); } -void direct_free(void* p, int64_t size) +void direct_free(void *p, int64_t size) { if (NULL != p) { munmap(p, size); @@ -138,25 +138,25 @@ void direct_free(void* p, int64_t size) namespace oceanbase { namespace common { -ObIAllocator* global_default_allocator = NULL; +ObIAllocator *global_default_allocator = NULL; int ob_init_memory_pool(int64_t block_size) { UNUSED(block_size); return OB_SUCCESS; } -ObMemLeakChecker& get_mem_leak_checker() +ObMemLeakChecker &get_mem_leak_checker() { return ObMemLeakChecker::get_instance(); } -void reset_mem_leak_checker_label(const char* str) +void reset_mem_leak_checker_label(const char *str) { get_mem_leak_checker().set_str(str); get_mem_leak_checker().reset(); } -const ObCtxInfo& get_global_ctx_info() +const ObCtxInfo &get_global_ctx_info() { static ObCtxInfo info; return info; @@ -166,15 +166,17 @@ void __attribute__((constructor(MALLOC_INIT_PRIORITY))) init_global_memory_pool( { int ret = OB_SUCCESS; // coro local storage construct function - CoRoutine::co_cb_ = [](CoRoutine& coro) { + CoRoutine::co_cb_ = [](CoRoutine &coro) { new (coro.get_context().get_local_store()) ObLocalStore(); new (coro.get_rtctx()) ObRuntimeContext(); - auto cls = reinterpret_cast(coro.get_context().get_local_store()); + auto cls = reinterpret_cast(coro.get_context().get_local_store()); coro.get_context().get_stack(cls->stack_addr_, cls->stack_size_); return OB_SUCCESS; }; global_default_allocator = ObMallocAllocator::get_instance(); +#ifndef OB_USE_ASAN abort_unless(OB_SUCCESS == install_ob_signal_handler()); +#endif } void __attribute__((destructor(MALLOC_INIT_PRIORITY))) deinit_global_memory_pool() diff --git a/src/observer/ob_server.cpp b/src/observer/ob_server.cpp index a198b8e76e..0f088c6853 100644 --- a/src/observer/ob_server.cpp +++ b/src/observer/ob_server.cpp @@ -159,7 +159,7 @@ ObServer::~ObServer() destroy(); } -int ObServer::init(const ObServerOptions& opts, const ObPLogWriterCfg& log_cfg) +int ObServer::init(const ObServerOptions &opts, const ObPLogWriterCfg &log_cfg) { int ret = OB_SUCCESS; opts_ = opts; @@ -214,7 +214,7 @@ int ObServer::init(const ObServerOptions& opts, const ObPLogWriterCfg& log_cfg) if (OB_FAIL(ObTableApiProcessorBase::init_session())) { LOG_WARN("failed to init static session", K(ret)); } else if (OB_FAIL(init_loaddata_global_stat())) { - LOG_WARN("fail to init global load data stat map", K(ret)); + LOG_WARN("fail to init global load data stat map", K(ret)); } } } @@ -234,8 +234,10 @@ int ObServer::init(const ObServerOptions& opts, const ObPLogWriterCfg& log_cfg) LOG_ERROR("should never reach here!", K(ret)); } else if (OB_FAIL(init_restore_ctx())) { LOG_ERROR("init restore context fail", K(ret)); +#ifndef OB_USE_ASAN } else if (OB_FAIL(ObMemoryDump::get_instance().init())) { LOG_ERROR("init memory dumper fail", K(ret)); +#endif } else if (OB_FAIL(ObDagScheduler::get_instance().init(OBSERVER.get_self()))) { LOG_ERROR("init scheduler fail, ", K(ret)); } else if (OB_FAIL(init_global_kvcache())) { @@ -588,7 +590,7 @@ int ObServer::stop() LOG_INFO("cache size calcucator has stopped"); LOG_INFO("begin stop distributed scheduler manager"); - ObDistributedSchedulerManager* dist_sched_mgr = ObDistributedSchedulerManager::get_instance(); + ObDistributedSchedulerManager *dist_sched_mgr = ObDistributedSchedulerManager::get_instance(); if (OB_ISNULL(dist_sched_mgr)) { LOG_ERROR("distributed scheduler manager instance is NULL"); } else if (OB_FAIL(dist_sched_mgr->stop())) { @@ -804,7 +806,7 @@ int ObServer::init_config() bool has_config_file = true; // set dump path - const char* dump_path = "etc/observer.config.bin"; + const char *dump_path = "etc/observer.config.bin"; config_mgr_.set_dump_path(dump_path); if (OB_FILE_NOT_EXIST == (ret = config_mgr_.load_config())) { has_config_file = false; @@ -826,7 +828,7 @@ int ObServer::init_config() config_.devname.set_version(start_time_); } else { if (!has_config_file) { - const char* devname = get_default_if(); + const char *devname = get_default_if(); if (devname && '\0' != devname[0]) { LOG_INFO("guess interface name", K(devname)); config_.devname.set_value(devname); @@ -1110,7 +1112,7 @@ int ObServer::init_restore_ctx() int ObServer::init_interrupt() { int ret = OB_SUCCESS; - ObGlobalInterruptManager* mgr = ObGlobalInterruptManager::getInstance(); + ObGlobalInterruptManager *mgr = ObGlobalInterruptManager::getInstance(); if (OB_ISNULL(mgr)) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_ERROR("fail get interrupt mgr instance", K(ret)); @@ -1123,7 +1125,7 @@ int ObServer::init_interrupt() int ObServer::init_loaddata_global_stat() { int ret = OB_SUCCESS; - ObGlobalLoadDataStatMap* map = ObGlobalLoadDataStatMap::getInstance(); + ObGlobalLoadDataStatMap *map = ObGlobalLoadDataStatMap::getInstance(); if (OB_ISNULL(map)) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_ERROR("fail allocate load data map for status", K(ret)); @@ -1253,7 +1255,7 @@ int ObServer::init_multi_tenant() // init allocator for OB_SYS_TENANT_ID and OB_SERVER_TENANT_ID int64_t min_sys_tenant_memory = config_.get_min_sys_tenant_memory(); int64_t max_sys_tenant_memory = config_.get_max_sys_tenant_memory(); - ObMallocAllocator* allocator = ObMallocAllocator::get_instance(); + ObMallocAllocator *allocator = ObMallocAllocator::get_instance(); if (OB_SUCC(ret)) { if (!OB_ISNULL(allocator)) { allocator->set_tenant_limit(OB_SYS_TENANT_ID, max_sys_tenant_memory); @@ -1262,7 +1264,7 @@ int ObServer::init_multi_tenant() } // set tenant mem limits - ObTenantManager& omti = ObTenantManager::get_instance(); + ObTenantManager &omti = ObTenantManager::get_instance(); if (OB_SUCC(ret)) { if (OB_FAIL( omti.init(self_addr_, srv_rpc_proxy_, rs_rpc_proxy_, rs_mgr_, net_frame_.get_req_transport(), &config_))) { @@ -1433,7 +1435,7 @@ int ObServer::init_sql_runner() int ObServer::init_sequence() { int ret = OB_SUCCESS; - ObSequenceCache& cache = ObSequenceCache::get_instance(); + ObSequenceCache &cache = ObSequenceCache::get_instance(); if (OB_FAIL(cache.init(schema_service_, sql_proxy_))) { LOG_ERROR("init sequence engine failed", K(ret)); } else { @@ -1588,7 +1590,7 @@ int ObServer::wait_gts() int ObServer::init_ts_mgr() { int ret = OB_SUCCESS; - ObILocationAdapter* location_adapter = ObPartitionService::get_instance().get_trans_service()->get_location_adapter(); + ObILocationAdapter *location_adapter = ObPartitionService::get_instance().get_trans_service()->get_location_adapter(); if (OB_FAIL(OB_TS_MGR.init(self_addr_, location_adapter, net_frame_.get_req_transport(), >s_))) { LOG_ERROR("gts cache mgr init failed", K_(self_addr), KP(location_adapter), K(ret)); @@ -1633,7 +1635,7 @@ int ObServer::init_storage() } if (OB_SUCC(ret)) { - const char* redundancy_level = config_.redundancy_level; + const char *redundancy_level = config_.redundancy_level; if (0 == strcasecmp(redundancy_level, "EXTERNAL")) { storage_env_.redundancy_level_ = ObStorageEnv::EXTERNAL_REDUNDANCY; } else if (0 == strcasecmp(redundancy_level, "NORMAL")) { @@ -1706,7 +1708,7 @@ int ObServer::init_gc_partition_adapter() return ret; } -int ObServer::get_network_speed_from_sysfs(int64_t& network_speed) +int ObServer::get_network_speed_from_sysfs(int64_t &network_speed) { int ret = OB_SUCCESS; // sys_bkgd_net_percentage_ = config_.sys_bkgd_net_percentage; @@ -1722,9 +1724,9 @@ int ObServer::get_network_speed_from_sysfs(int64_t& network_speed) return ret; } -char* strtrim(char* str) +char *strtrim(char *str) { - char* ptr; + char *ptr; if (str == NULL) { return NULL; @@ -1742,9 +1744,9 @@ char* strtrim(char* str) return str; } -static int64_t nic_rate_parse(const char* str, bool& valid) +static int64_t nic_rate_parse(const char *str, bool &valid) { - char* p_unit = nullptr; + char *p_unit = nullptr; int64_t value = 0; if (OB_ISNULL(str) || '\0' == str[0]) { @@ -1776,16 +1778,16 @@ static int64_t nic_rate_parse(const char* str, bool& valid) return value; } -int ObServer::get_network_speed_from_config_file(int64_t& network_speed) +int ObServer::get_network_speed_from_config_file(int64_t &network_speed) { int ret = OB_SUCCESS; - const char* nic_rate_path = "etc/nic.rate.config"; + const char *nic_rate_path = "etc/nic.rate.config"; const int64_t MAX_NIC_CONFIG_FILE_SIZE = 1 << 10; // 1KB - FILE* fp = nullptr; - char* buf = nullptr; + FILE *fp = nullptr; + char *buf = nullptr; static int nic_rate_file_exist = 1; - if (OB_ISNULL(buf = static_cast(ob_malloc(MAX_NIC_CONFIG_FILE_SIZE + 1, ObModIds::OB_BUFFER)))) { + if (OB_ISNULL(buf = static_cast(ob_malloc(MAX_NIC_CONFIG_FILE_SIZE + 1, ObModIds::OB_BUFFER)))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_ERROR("alloc buffer failed", LITERAL_K(MAX_NIC_CONFIG_FILE_SIZE), K(ret)); } else if (OB_ISNULL(fp = fopen(nic_rate_path, "r"))) { @@ -1810,7 +1812,7 @@ int ObServer::get_network_speed_from_config_file(int64_t& network_speed) } memset(buf, 0, MAX_NIC_CONFIG_FILE_SIZE + 1); fread(buf, 1, MAX_NIC_CONFIG_FILE_SIZE, fp); - char* prate = nullptr; + char *prate = nullptr; if (OB_UNLIKELY(0 != ferror(fp))) { ret = OB_IO_ERROR; @@ -1953,7 +1955,7 @@ int ObServer::check_server_can_start_service() return ret; } -storage::ObPartitionService& ObServer::get_partition_service() +storage::ObPartitionService &ObServer::get_partition_service() { return ObPartitionService::get_instance(); } @@ -1961,7 +1963,7 @@ storage::ObPartitionService& ObServer::get_partition_service() ObServer::ObCTASCleanUpTask::ObCTASCleanUpTask() : obs_(nullptr), is_inited_(false) {} -int ObServer::ObCTASCleanUpTask::init(ObServer* obs, int tg_id) +int ObServer::ObCTASCleanUpTask::init(ObServer *obs, int tg_id) { int ret = OB_SUCCESS; if (OB_UNLIKELY(is_inited_)) { @@ -2009,7 +2011,7 @@ void ObServer::ObCTASCleanUpTask::runTimerTask() // Traverse the current session and determine whether the given table schema needs to be deleted according to the // session id and last active time -bool ObServer::ObCTASCleanUp::operator()(sql::ObSQLSessionMgr::Key key, sql::ObSQLSessionInfo* sess_info) +bool ObServer::ObCTASCleanUp::operator()(sql::ObSQLSessionMgr::Key key, sql::ObSQLSessionInfo *sess_info) { int ret = OB_SUCCESS; if ((ObCTASCleanUp::TEMP_TAB_PROXY_RULE == get_cleanup_type() && get_drop_flag()) || @@ -2073,7 +2075,7 @@ bool ObServer::ObCTASCleanUp::operator()(sql::ObSQLSessionMgr::Key key, sql::ObS // Traverse the current session, if the session has updated sess_active_time recently, execute alter system refresh // tables in session xxx Synchronously update the last active time of all temporary tables under the current session -bool ObServer::ObRefreshTime::operator()(sql::ObSQLSessionMgr::Key key, sql::ObSQLSessionInfo* sess_info) +bool ObServer::ObRefreshTime::operator()(sql::ObSQLSessionMgr::Key key, sql::ObSQLSessionInfo *sess_info) { int ret = OB_SUCCESS; UNUSED(key); @@ -2098,7 +2100,7 @@ bool ObServer::ObRefreshTime::operator()(sql::ObSQLSessionMgr::Key key, sql::ObS ObServer::ObRefreshTimeTask::ObRefreshTimeTask() : obs_(nullptr), is_inited_(false) {} -int ObServer::ObRefreshTimeTask::init(ObServer* obs, int tg_id) +int ObServer::ObRefreshTimeTask::init(ObServer *obs, int tg_id) { int ret = OB_SUCCESS; if (OB_UNLIKELY(is_inited_)) { @@ -2155,7 +2157,7 @@ int ObServer::refresh_temp_table_sess_active_time() ObServer::ObRefreshNetworkSpeedTask::ObRefreshNetworkSpeedTask() : obs_(nullptr), is_inited_(false) {} -int ObServer::ObRefreshNetworkSpeedTask::init(ObServer* obs, int tg_id) +int ObServer::ObRefreshNetworkSpeedTask::init(ObServer *obs, int tg_id) { int ret = OB_SUCCESS; if (OB_UNLIKELY(is_inited_)) { @@ -2271,12 +2273,12 @@ int ObServer::clean_up_invalid_tables() int ret = OB_SUCCESS; int tmp_ret = OB_SUCCESS; ObSchemaGetterGuard schema_guard; - const ObDatabaseSchema* database_schema = NULL; - ObSEArray table_schemas; + const ObDatabaseSchema *database_schema = NULL; + ObSEArray table_schemas; const int64_t CONNECT_TIMEOUT_VALUE = 50L * 60L * 60L * 1000L * 1000L; // default value is 50hrs obrpc::ObDropTableArg drop_table_arg; obrpc::ObTableItem table_item; - obrpc::ObCommonRpcProxy* common_rpc_proxy = NULL; + obrpc::ObCommonRpcProxy *common_rpc_proxy = NULL; char create_host_str[OB_MAX_HOST_NAME_LENGTH]; if (OB_FAIL(schema_service_.get_schema_guard(schema_guard))) { LOG_WARN("fail to get schema guard", K(ret)); @@ -2289,7 +2291,7 @@ int ObServer::clean_up_invalid_tables() common_rpc_proxy = GCTX.rs_rpc_proxy_; MYADDR.ip_port_to_string(create_host_str, OB_MAX_HOST_NAME_LENGTH); for (int64_t i = 0; i < table_schemas.count() && OB_SUCC(tmp_ret); i++) { - const ObTableSchema* table_schema = table_schemas.at(i); + const ObTableSchema *table_schema = table_schemas.at(i); if (OB_ISNULL(table_schema)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("got invalid schema", K(ret), K(i)); diff --git a/src/observer/ob_signal_handle.cpp b/src/observer/ob_signal_handle.cpp index 9759bef780..6e2fbf6424 100644 --- a/src/observer/ob_signal_handle.cpp +++ b/src/observer/ob_signal_handle.cpp @@ -76,7 +76,7 @@ int ObSignalHandle::change_signal_mask() return ret; } -int ObSignalHandle::add_signums_to_set(sigset_t& sig_set) +int ObSignalHandle::add_signums_to_set(sigset_t &sig_set) { int ret = OB_SUCCESS; if (0 != sigemptyset(&sig_set)) { @@ -221,8 +221,10 @@ int ObSignalHandle::deal_signals(int signum) break; } case 60: { +#ifndef OB_USE_ASAN send_request_and_wait(VERB_LEVEL_1, syscall(SYS_gettid) /*exclude_id*/); break; +#endif } case 62: { // RESP_DUMP_TRACE_TO_FILE(); diff --git a/src/storage/blocksstable/ob_data_buffer.cpp b/src/storage/blocksstable/ob_data_buffer.cpp index cf082e3131..9eb2241579 100644 --- a/src/storage/blocksstable/ob_data_buffer.cpp +++ b/src/storage/blocksstable/ob_data_buffer.cpp @@ -19,7 +19,7 @@ using namespace common; namespace oceanbase { namespace blocksstable { -ObSelfBufferWriter::ObSelfBufferWriter(const int64_t size, const char* label, const bool need_align) +ObSelfBufferWriter::ObSelfBufferWriter(const int64_t size, const char *label, const bool need_align) : ObBufferWriter(NULL, 0, 0), label_(label), is_aligned_(need_align), macro_block_mem_ctx_() { int ret = OB_SUCCESS; @@ -39,11 +39,11 @@ ObSelfBufferWriter::~ObSelfBufferWriter() macro_block_mem_ctx_.destroy(); } -char* ObSelfBufferWriter::alloc(const int64_t size) +char *ObSelfBufferWriter::alloc(const int64_t size) { - char* data = NULL; + char *data = NULL; if (size == macro_block_mem_ctx_.get_block_size()) { - data = (char*)macro_block_mem_ctx_.alloc(); + data = (char *)macro_block_mem_ctx_.alloc(); if (OB_ISNULL(data)) { STORAGE_LOG(WARN, "fail to alloc buf from mem ctx", K(size)); } @@ -52,9 +52,9 @@ char* ObSelfBufferWriter::alloc(const int64_t size) // alloc from mem ctx fail if (OB_ISNULL(data)) { if (is_aligned_) { - data = (char*)ob_malloc_align(BUFFER_ALIGN_SIZE, size, label_); + data = (char *)ob_malloc_align(BUFFER_ALIGN_SIZE, size, label_); } else { - data = (char*)ob_malloc(size, label_); + data = (char *)ob_malloc(size, label_); } } return data; @@ -79,7 +79,7 @@ int ObSelfBufferWriter::ensure_space(int64_t size) } } else if (capacity_ < size) { // resize; - char* new_data = NULL; + char *new_data = NULL; if (NULL == (new_data = alloc(size))) { STORAGE_LOG(WARN, "allocate buffer memory error.", K(size)); ret = OB_ALLOCATE_MEMORY_FAILED; @@ -97,17 +97,21 @@ int ObSelfBufferWriter::ensure_space(int64_t size) void ObSelfBufferWriter::free() { if (NULL != data_) { +#ifndef OB_USE_ASAN if (macro_block_mem_ctx_.get_allocator().contains(data_)) { macro_block_mem_ctx_.free(data_); - } else { + data_ = NULL; + } +#endif + if (NULL != data_) { if (is_aligned_) { ob_free_align(data_); } else { ob_free(data_); } + data_ = NULL; } } - data_ = NULL; } } // namespace blocksstable } // namespace oceanbase -- GitLab