Skip to content

Commit

Permalink
fix coredump caused by incorrent lib path
Browse files Browse the repository at this point in the history
  • Loading branch information
young-scott committed Nov 13, 2023
1 parent ecbb1c3 commit 74e1273
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
19 changes: 13 additions & 6 deletions src/Disks/CubeFS/DiskCubeFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<SdkLoader>(settings->lib_path);
try
{
sdk_loader = std::make_shared<SdkLoader>(settings->lib_name);
}
catch(...)
{
throw;
}
id = sdk_loader->cfsNewClient();
if (id <= 0)
{
Expand Down Expand Up @@ -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_)
Expand All @@ -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_)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Disks/CubeFS/DiskCubeFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
25 changes: 13 additions & 12 deletions src/Disks/CubeFS/registerDiskCubeFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path>. Use <default> 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<DiskCubeFSSettings>(
auto cubefs_settings = std::make_shared<DiskCubeFSSettings>(
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)
Expand Down
8 changes: 4 additions & 4 deletions src/Disks/CubeFS/sdkLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CfsNewClientFunction>(dlsym(handle, "cfs_new_client"));
cfsSetClient = reinterpret_cast<CfsSetClientFunction>(dlsym(handle, "cfs_set_client"));
cfsStartClient = reinterpret_cast<CfsStartClientFunction>(dlsym(handle, "cfs_start_client"));
Expand Down
4 changes: 2 additions & 2 deletions src/Disks/CubeFS/sdkLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down Expand Up @@ -57,7 +57,7 @@ class SdkLoader
CfsReaddirFunction cfsReaddir;

private:
String lib_path;
String lib_name;
Poco::Logger * logger;
};
}

0 comments on commit 74e1273

Please sign in to comment.