From 74e1273e2e69a10161faed0b09bb2cdbb5c6df64 Mon Sep 17 00:00:00 2001 From: young scott Date: Mon, 13 Nov 2023 07:53:16 +0000 Subject: [PATCH] fix coredump caused by incorrent lib path --- src/Disks/CubeFS/DiskCubeFS.cpp | 19 +++++++++++++------ src/Disks/CubeFS/DiskCubeFS.h | 4 ++-- src/Disks/CubeFS/registerDiskCubeFS.cpp | 25 +++++++++++++------------ src/Disks/CubeFS/sdkLoader.cpp | 8 ++++---- src/Disks/CubeFS/sdkLoader.h | 4 ++-- 5 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/Disks/CubeFS/DiskCubeFS.cpp b/src/Disks/CubeFS/DiskCubeFS.cpp index 7e09b29e1b1a..7eecba6907ba 100644 --- a/src/Disks/CubeFS/DiskCubeFS.cpp +++ b/src/Disks/CubeFS/DiskCubeFS.cpp @@ -131,21 +131,21 @@ bool DiskCubeFS::tryReserve(UInt64 bytes) UInt64 DiskCubeFS::getTotalSpace() const { - LOG_DEBUG(logger, "Use mock getTotalSpace function"); + LOG_TEST(logger, "Use mock getTotalSpace function"); return 419585155072; //throwFromErrnoWithPath("DiskCubeFs does not support function getTotalSpace!", settings->disk_path, ErrorCodes::LOGICAL_ERROR); } UInt64 DiskCubeFS::getAvailableSpace() const { - LOG_DEBUG(logger, "Use mock getAvailableSpace function"); + LOG_TEST(logger, "Use mock getAvailableSpace function"); return 151697231872; //throwFromErrnoWithPath("DiskCubeFs does not support function getAvailableSpace!", settings->disk_path, ErrorCodes::LOGICAL_ERROR); } UInt64 DiskCubeFS::getUnreservedSpace() const { - LOG_DEBUG(logger, "Use mock getUnreservedSpace function"); + LOG_TEST(logger, "Use mock getUnreservedSpace function"); return 151697231872; //throwFromErrnoWithPath("DiskCubeFs does not support function getUnreservedSpace!", settings->disk_path, ErrorCodes::LOGICAL_ERROR); } @@ -530,7 +530,14 @@ void DiskCubeFS::createHardLink(const String &, const String &) DiskCubeFS::DiskCubeFS(const String & name_, SettingsPtr settings_, UInt64 keep_free_space_bytes_) : name(name_), settings(std::move(settings_)), logger(&Poco::Logger::get("DiskCubeFS")),keep_free_space_bytes(keep_free_space_bytes_) { - sdk_loader = std::make_shared(settings->lib_path); + try + { + sdk_loader = std::make_shared(settings->lib_name); + } + catch(...) + { + throw; + } id = sdk_loader->cfsNewClient(); if (id <= 0) { @@ -582,7 +589,7 @@ DiskCubeFSSettings ::DiskCubeFSSettings( String secret_key_, String push_addr_, String disk_path_, - String lib_path_) + String lib_name_) : vol_name(vol_name_) , master_addr(master_addr_) , log_dir(log_dir_) @@ -591,7 +598,7 @@ DiskCubeFSSettings ::DiskCubeFSSettings( , secret_key(secret_key_) , push_addr(push_addr_) , disk_path(disk_path_) - , lib_path(lib_path_) + , lib_name(lib_name_) { } diff --git a/src/Disks/CubeFS/DiskCubeFS.h b/src/Disks/CubeFS/DiskCubeFS.h index d1add66048c9..e88173f14428 100644 --- a/src/Disks/CubeFS/DiskCubeFS.h +++ b/src/Disks/CubeFS/DiskCubeFS.h @@ -17,7 +17,7 @@ struct DiskCubeFSSettings String secret_key_, String push_addr_, String disk_path_, - String lib_path_); + String lib_name_); String vol_name; String master_addr; String log_dir; @@ -26,7 +26,7 @@ struct DiskCubeFSSettings String secret_key; String push_addr; String disk_path; - String lib_path; + String lib_name; }; class DiskCubeFSCheckThread; class DiskCubeFS final : public IDisk diff --git a/src/Disks/CubeFS/registerDiskCubeFS.cpp b/src/Disks/CubeFS/registerDiskCubeFS.cpp index 77286c4093ca..fe16684ab52d 100644 --- a/src/Disks/CubeFS/registerDiskCubeFS.cpp +++ b/src/Disks/CubeFS/registerDiskCubeFS.cpp @@ -20,25 +20,26 @@ getSettings(const String & name, ContextPtr context, const Poco::Util::AbstractC throw Exception(ErrorCodes::BAD_ARGUMENTS, "Disk path must end with /. Disk {}", name); if (disk_path == context->getPath()) throw Exception(ErrorCodes::BAD_ARGUMENTS, "Disk path ('{}') cannot be equal to . Use disk instead.", disk_path); - LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "volumn name: {}", config.getString(config_prefix + ".vol_name")); - LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "master address: {}", config.getString(config_prefix + ".master_addr")); - LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "log directory: {}", config.getString(config_prefix + ".log_dir")); - LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "log level: {}", config.getString(config_prefix + ".log_level")); - LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "access key: {}", config.getString(config_prefix + ".access_key")); - LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "secret key: {}", config.getString(config_prefix + ".secret_key")); - LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "push address: {}", config.getString(config_prefix + ".push_addr")); - LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "disk path: {}", disk_path); - LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "lib path: {}", config.getString(config_prefix + ".lib_path")); - return std::make_shared( + auto cubefs_settings = std::make_shared( config.getString(config_prefix + ".vol_name"), config.getString(config_prefix + ".master_addr"), - config.getString(config_prefix + ".log_dir"), + config.getString(config_prefix + ".log_dir", "/home/service/var/clickhouse/logs/"), config.getString(config_prefix + ".log_level", "debug"), config.getString(config_prefix + ".access_key"), config.getString(config_prefix + ".secret_key"), config.getString(config_prefix + ".push_addr"), disk_path, - config.getString(config_prefix + ".lib_path")); + config.getString(config_prefix + ".lib_name", "libcfs.so")); + LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "volumn name: {}", cubefs_settings->vol_name); + LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "master address: {}", cubefs_settings->master_addr); + LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "log directory: {}", cubefs_settings->log_dir); + LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "log level: {}", cubefs_settings->log_level); + LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "access key: {}", cubefs_settings->access_key); + LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "secret key: {}", cubefs_settings->secret_key); + LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "push address: {}", cubefs_settings->push_addr); + LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "disk path: {}", cubefs_settings->disk_path); + LOG_DEBUG(&Poco::Logger::get("DiskCubeFS"), "lib name: {}", cubefs_settings->lib_name); + return cubefs_settings; } void registerDiskCubeFS(DiskFactory & factory) diff --git a/src/Disks/CubeFS/sdkLoader.cpp b/src/Disks/CubeFS/sdkLoader.cpp index 188f47e81d4a..9741287bf3a2 100644 --- a/src/Disks/CubeFS/sdkLoader.cpp +++ b/src/Disks/CubeFS/sdkLoader.cpp @@ -7,14 +7,14 @@ namespace ErrorCodes { extern const int EXTERNAL_LIBRARY_ERROR; } -SdkLoader::SdkLoader(String lib_path_) : lib_path(lib_path_), logger(&Poco::Logger::get("sdkLoader")) +SdkLoader::SdkLoader(String lib_name_) : lib_name(lib_name_), logger(&Poco::Logger::get("sdkLoader")) { - LOG_DEBUG(logger, "load cubefs shared library from path: {}", lib_path_); - void * handle = dlopen(lib_path_.c_str(), RTLD_LAZY); + void * handle = dlopen(lib_name_.c_str(),RTLD_NOW); if (!handle) { - throwFromErrnoWithPath("Failed to open the dynamic library", lib_path_, ErrorCodes::EXTERNAL_LIBRARY_ERROR); + throwFromErrnoWithPath("Failed to open the dynamic library (" + lib_name_ + ")", lib_name_, ErrorCodes::EXTERNAL_LIBRARY_ERROR); } + LOG_DEBUG(logger, "load cubefs shared library from name: {}", lib_name_); cfsNewClient = reinterpret_cast(dlsym(handle, "cfs_new_client")); cfsSetClient = reinterpret_cast(dlsym(handle, "cfs_set_client")); cfsStartClient = reinterpret_cast(dlsym(handle, "cfs_start_client")); diff --git a/src/Disks/CubeFS/sdkLoader.h b/src/Disks/CubeFS/sdkLoader.h index 77c35527fe1b..5bd4679c3f10 100644 --- a/src/Disks/CubeFS/sdkLoader.h +++ b/src/Disks/CubeFS/sdkLoader.h @@ -8,7 +8,7 @@ namespace DB class SdkLoader { public: - SdkLoader(String lib_path_); + SdkLoader(String lib_name_); typedef int64_t (*CfsNewClientFunction)(); typedef int (*CfsSetClientFunction)(int64_t, char *, char *); @@ -57,7 +57,7 @@ class SdkLoader CfsReaddirFunction cfsReaddir; private: - String lib_path; + String lib_name; Poco::Logger * logger; }; }