Skip to content

Commit

Permalink
Merge pull request #6 from RunningXie/feature_support_cubefs_sdk
Browse files Browse the repository at this point in the history
rc4Feature support cubefs sdk
  • Loading branch information
young-scott authored Nov 2, 2023
2 parents ac8df32 + 2d95546 commit a8f5568
Show file tree
Hide file tree
Showing 24 changed files with 1,970 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,7 @@
[submodule "contrib/minizip-ng"]
path = contrib/minizip-ng
url = https://github.com/zlib-ng/minizip-ng
[submodule "contrib/cubefs"]
path = contrib/cubefs
url = https://github.com/RunningXie/cubefs.git
branch = fix_sdk_compilation
1 change: 1 addition & 0 deletions contrib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ add_contrib (libpq-cmake libpq)
add_contrib (nuraft-cmake NuRaft)
add_contrib (fast_float-cmake fast_float)
add_contrib (datasketches-cpp-cmake datasketches-cpp)
add_contrib (cubefs-cmake cubefs)

option(ENABLE_NLP "Enable NLP functions support" ${ENABLE_LIBRARIES})
if (ENABLE_NLP)
Expand Down
1 change: 1 addition & 0 deletions contrib/cubefs
Submodule cubefs added at 5eb497
30 changes: 30 additions & 0 deletions contrib/cubefs-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.20)
message(STATUS "start handle contrib/cubefs-cmake/CMakeLists.txt")
set(CUBEFS_DIR "${ClickHouse_SOURCE_DIR}/contrib/cubefs")
message(STATUS "start execute_process")
execute_process(
COMMAND make libsdk
WORKING_DIRECTORY ${CUBEFS_DIR})
add_library(_cubefs STATIC IMPORTED GLOBAL)
set_target_properties(_cubefs PROPERTIES
IMPORTED_LOCATION "${CUBEFS_DIR}/build/bin/libcfs.a"
)
add_library(ch_contrib::cubefs ALIAS _cubefs)
set(FILE_PATH "${CUBEFS_DIR}/libsdk/libcfs.h")
# Add configuration to ignore warnings in the header file
file(STRINGS ${FILE_PATH} FILE_CONTENTS)
list(FIND FILE_CONTENTS "#pragma GCC diagnostic push" PRAGMA_INDEX)
if (PRAGMA_INDEX EQUAL -1)
execute_process(
COMMAND sh -c "echo '#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Wreserved-identifier\"\n#pragma GCC diagnostic ignored \"-Wmacro-redefined\"\n' | cat - ${FILE_PATH}"
OUTPUT_FILE "${FILE_PATH}.tmp"
)
execute_process(
COMMAND sh -c "echo '#pragma GCC diagnostic pop' >> ${FILE_PATH}.tmp"
)
execute_process(
COMMAND mv "${FILE_PATH}.tmp" "${FILE_PATH}"
)
endif()


25 changes: 25 additions & 0 deletions programs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ option (ENABLE_CLICKHOUSE_EXTRACT_FROM_CONFIG "Configs processor (extract values
# https://clickhouse.com/docs/en/operations/utilities/clickhouse-compressor/
option (ENABLE_CLICKHOUSE_COMPRESSOR "Data compressor and decompressor" ${ENABLE_CLICKHOUSE_ALL})

# cubefs test
option (ENABLE_CLICKHOUSE_CUBEFS_TEST "Cubefs test" ${ENABLE_CLICKHOUSE_ALL})

# https://clickhouse.com/docs/en/operations/utilities/clickhouse-copier/
option (ENABLE_CLICKHOUSE_COPIER "Inter-cluster data copying mode" ${ENABLE_CLICKHOUSE_ALL})

Expand Down Expand Up @@ -114,6 +117,12 @@ else()
message(STATUS "Copier mode: OFF")
endif()

if (ENABLE_CLICKHOUSE_CUBEFS_TEST)
message(STATUS "Cubefs test: ON")
else()
message(STATUS "Cubefs test: OFF")
endif()

if (ENABLE_CLICKHOUSE_FORMAT)
message(STATUS "Format mode: ON")
else()
Expand Down Expand Up @@ -230,6 +239,7 @@ add_subdirectory (install)
add_subdirectory (git-import)
add_subdirectory (bash-completion)
add_subdirectory (static-files-disk-uploader)
add_subdirectory (cubefs-test)

if (ENABLE_CLICKHOUSE_KEEPER)
add_subdirectory (keeper)
Expand Down Expand Up @@ -261,6 +271,7 @@ if (CLICKHOUSE_ONE_SHARED)
${CLICKHOUSE_GIT_IMPORT_SOURCES}
${CLICKHOUSE_ODBC_BRIDGE_SOURCES}
${CLICKHOUSE_KEEPER_SOURCES}
${CLICKHOUSE_CUBEFS_TEST_SOURCES}
${CLICKHOUSE_KEEPER_CONVERTER_SOURCES}
${CLICKHOUSE_STATIC_FILES_DISK_UPLOADER_SOURCES})

Expand All @@ -277,6 +288,7 @@ if (CLICKHOUSE_ONE_SHARED)
${CLICKHOUSE_GIT_IMPORT_LINK}
${CLICKHOUSE_ODBC_BRIDGE_LINK}
${CLICKHOUSE_KEEPER_LINK}
${CLICKHOUSE_CUBEFS_TEST_LINK}
${CLICKHOUSE_KEEPER_CONVERTER_LINK}
${CLICKHOUSE_STATIC_FILES_DISK_UPLOADER_LINK})

Expand All @@ -293,6 +305,7 @@ if (CLICKHOUSE_ONE_SHARED)
${CLICKHOUSE_GIT_IMPORT_INCLUDE}
${CLICKHOUSE_ODBC_BRIDGE_INCLUDE}
${CLICKHOUSE_KEEPER_INCLUDE}
${CLICKHOUSE_CUBEFS_TEST_INCLUDE}
${CLICKHOUSE_KEEPER_CONVERTER_INCLUDE})

set_target_properties(clickhouse-lib PROPERTIES SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR} VERSION ${VERSION_SO} OUTPUT_NAME clickhouse DEBUG_POSTFIX "")
Expand Down Expand Up @@ -330,6 +343,10 @@ if (CLICKHOUSE_SPLIT_BINARY)
list (APPEND CLICKHOUSE_ALL_TARGETS clickhouse-keeper-converter)
endif ()

if (ENABLE_CLICKHOUSE_CUBEFS_TEST)
list (APPEND CLICKHOUSE_ALL_TARGETS clickhouse-cubefs-test)
endif ()

set_target_properties(${CLICKHOUSE_ALL_TARGETS} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ..)

add_custom_target (clickhouse-bundle ALL DEPENDS ${CLICKHOUSE_ALL_TARGETS})
Expand All @@ -356,6 +373,9 @@ else ()
if (ENABLE_CLICKHOUSE_LOCAL)
clickhouse_target_link_split_lib(clickhouse local)
endif ()
if (ENABLE_CLICKHOUSE_CUBEFS_TEST)
clickhouse_target_link_split_lib(clickhouse cubefs-test)
endif ()
if (ENABLE_CLICKHOUSE_BENCHMARK)
clickhouse_target_link_split_lib(clickhouse benchmark)
endif ()
Expand Down Expand Up @@ -416,6 +436,11 @@ else ()
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/clickhouse-copier" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT clickhouse)
list(APPEND CLICKHOUSE_BUNDLE clickhouse-copier)
endif ()
if (ENABLE_CLICKHOUSE_CUBEFS_TEST)
add_custom_target (clickhouse-cubefs-test ALL COMMAND ${CMAKE_COMMAND} -E create_symlink clickhouse clickhouse-cubefs-test DEPENDS clickhouse)
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/clickhouse-cubefs-test" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT clickhouse)
list(APPEND CLICKHOUSE_BUNDLE clickhouse-cubefs-test)
endif ()
if (ENABLE_CLICKHOUSE_EXTRACT_FROM_CONFIG)
add_custom_target (clickhouse-extract-from-config ALL COMMAND ${CMAKE_COMMAND} -E create_symlink clickhouse clickhouse-extract-from-config DEPENDS clickhouse)
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/clickhouse-extract-from-config" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT clickhouse)
Expand Down
1 change: 1 addition & 0 deletions programs/config_tools.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
#cmakedefine01 ENABLE_CLICKHOUSE_KEEPER
#cmakedefine01 ENABLE_CLICKHOUSE_KEEPER_CONVERTER
#cmakedefine01 ENABLE_CLICKHOUSE_STATIC_FILES_DISK_UPLOADER
#cmakedefine01 ENABLE_CLICKHOUSE_CUBEFS_TEST
4 changes: 4 additions & 0 deletions programs/cubefs-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set (CLICKHOUSE_CUBEFS_TEST_SOURCES cubefs-test.cpp clickhouse-cubefs-test.cpp)
set (CLICKHOUSE_CUBEFS_TEST_LINK dbms ch_contrib::cubefs)
set (CLICKHOUSE_CUBEFS_TEST_INCLUDE PUBLIC ${ClickHouse_SOURCE_DIR}/contrib/cubefs/libsdk)
clickhouse_program_add(cubefs-test)
5 changes: 5 additions & 0 deletions programs/cubefs-test/clickhouse-cubefs-test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int mainEntryClickHouseCubefsTest(int argc, char ** argv);
int main(int argc_, char ** argv_)
{
return mainEntryClickHouseCubefsTest(argc_, argv_);
}
165 changes: 165 additions & 0 deletions programs/cubefs-test/cubefs-dlopen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#include <cstring>
#include <iostream>
#include <dlfcn.h>
#include <libcfs.h>


int main()
{
void * handle = dlopen("./libcfs.so", RTLD_LAZY);
if (!handle)
{
std::cerr << "Failed to open the dynamic library: " << dlerror() << std::endl;
return 1;
}
typedef int64_t (*CfsNewClientFunction)();
typedef int (*CfsSetClientFunction)(int64_t, char *, char *);
typedef int (*CfsStartClientFunction)(int64_t);
typedef void (*CfsCloseClientFunction)(int64_t);
typedef int (*CfsChdirFunction)(int64_t, char *);
typedef char * (*CfsGetcwdFunction)(int64_t);
typedef int (*CfsGetattrFunction)(int64_t, char *, struct cfs_stat_info *);
typedef int (*CfsSetattrFunction)(int64_t, char *, struct cfs_stat_info *, int);
typedef int (*CfsOpenFunction)(int64_t, char *, int, mode_t);
typedef int (*CfsFlushFunction)(int64_t, int);
typedef void (*CfsCloseFunction)(int64_t, int);
typedef ssize_t (*CfsWriteFunction)(int64_t, int, void *, size_t, off_t);
typedef ssize_t (*CfsReadFunction)(int64_t, int, void *, size_t, off_t);
typedef int (*CfsBatchGetInodesFunction)(int64_t, int, void *, GoSlice, int);
typedef int (*CfsRefreshSummaryFunction)(int64_t, char *, int);
typedef int (*CfsReaddirFunction)(int64_t, int, GoSlice, int);
typedef int (*CfsLsdirFunction)(int64_t, int, GoSlice, int);
typedef int (*CfsMkdirsFunction)(int64_t, char *, mode_t);
typedef int (*CfsRmdirFunction)(int64_t, char *);
typedef int (*CfsUnlinkFunction)(int64_t, char *);
typedef int (*CfsRenameFunction)(int64_t, char *, char *);
typedef int (*CfsFchmodFunction)(int64_t, int, mode_t);
typedef int (*CfsGetsummaryFunction)(int64_t, char *, struct cfs_summary_info *, char *, int);
CfsNewClientFunction cfsNewClient = (CfsNewClientFunction)dlsym(handle, "cfs_new_client");
CfsSetClientFunction cfsSetClient = (CfsSetClientFunction)dlsym(handle, "cfs_set_client");
CfsStartClientFunction cfsStartClient = (CfsStartClientFunction)dlsym(handle, "cfs_start_client");
CfsCloseClientFunction cfsCloseClient = (CfsCloseClientFunction)dlsym(handle, "cfs_close_client");
CfsChdirFunction cfsChdir = (CfsChdirFunction)dlsym(handle, "cfs_chdir");
CfsGetcwdFunction cfsGetcwd = (CfsGetcwdFunction)dlsym(handle, "cfs_getcwd");
CfsGetattrFunction cfsGetattr = (CfsGetattrFunction)dlsym(handle, "cfs_getattr");
CfsSetattrFunction cfsSetattr = (CfsSetattrFunction)dlsym(handle, "cfs_setattr");
CfsOpenFunction cfsOpen = (CfsOpenFunction)dlsym(handle, "cfs_open");
CfsFlushFunction cfsFlush = (CfsFlushFunction)dlsym(handle, "cfs_flush");
CfsCloseFunction cfsClose = (CfsCloseFunction)dlsym(handle, "cfs_close");
CfsLsdirFunction cfsLsdir = (CfsLsdirFunction)dlsym(handle, "cfs_lsdir");
CfsMkdirsFunction cfsMkdirs = (CfsMkdirsFunction)dlsym(handle, "cfs_mkdirs");
CfsRmdirFunction cfsRmdir = (CfsRmdirFunction)dlsym(handle, "cfs_rmdir");
CfsUnlinkFunction cfsUnlink = (CfsUnlinkFunction)dlsym(handle, "cfs_unlink");
CfsRenameFunction cfsRename = (CfsRenameFunction)dlsym(handle, "cfs_rename");
CfsFchmodFunction cfsFchmod = (CfsFchmodFunction)dlsym(handle, "cfs_fchmod");
CfsGetsummaryFunction cfsGetsummary = (CfsGetsummaryFunction)dlsym(handle, "cfs_getsummary");
CfsWriteFunction cfsWrite = (CfsWriteFunction)dlsym(handle, "cfs_write");
CfsReadFunction cfsRead = (CfsReadFunction)dlsym(handle, "cfs_read");
if (!cfsNewClient || !cfsSetClient || !cfsStartClient || !cfsCloseClient || !cfsChdir || !cfsGetcwd || !cfsGetattr || !cfsSetattr
|| !cfsOpen || !cfsFlush || !cfsClose || !cfsWrite || !cfsRead || !cfsLsdir || !cfsMkdirs || !cfsRmdir || !cfsUnlink || !cfsRename
|| !cfsFchmod || !cfsGetsummary)
{
std::cerr << "Failed to find one or more functions: " << dlerror() << std::endl;
dlclose(handle);
return 1;
}
int64_t clientId = cfsNewClient();
if (clientId == 0)
{
std::cerr << "Failed to create client" << std::endl;
dlclose(handle);
return 1;
}
int result = cfsSetClient(clientId, strdup("volName"), strdup("xieyichen"));
if (result != 0)
{
std::cerr << "Failed to set client" << std::endl;
cfsCloseClient(clientId);
dlclose(handle);
return 1;
}
result = cfsSetClient(clientId, strdup("masterAddr"), strdup("cfs-south.oppo.local"));
if (result != 0)
{
std::cerr << "Failed to set client" << std::endl;
cfsCloseClient(clientId);
dlclose(handle);
return 1;
}
result = cfsSetClient(clientId, strdup("logDir"), strdup("/home/service/var/logs/cfs/test-log"));
if (result != 0)
{
std::cerr << "Failed to set client" << std::endl;
cfsCloseClient(clientId);
dlclose(handle);
return 1;
}
result = cfsSetClient(clientId, strdup("logLevel"), strdup("debug"));
if (result != 0)
{
std::cerr << "Failed to set client" << std::endl;
cfsCloseClient(clientId);
dlclose(handle);
return 1;
}
result = cfsSetClient(clientId, strdup("accessKey"), strdup("jRlZO65q7XlH5bnV"));
if (result != 0)
{
std::cerr << "Failed to set client" << std::endl;
cfsCloseClient(clientId);
dlclose(handle);
return 1;
}
result = cfsSetClient(clientId, strdup("secretKey"), strdup("V1m730UzREHaK1jCkC0kL0cewOX0kH3K"));
if (result != 0)
{
std::cerr << "Failed to set client" << std::endl;
cfsCloseClient(clientId);
dlclose(handle);
return 1;
}
result = cfsSetClient(clientId, strdup("pushAddr"), strdup("cfs.dg-push.wanyol.com"));
if (result != 0)
{
std::cerr << "Failed to set client" << std::endl;
cfsCloseClient(clientId);
dlclose(handle);
return 1;
}
result = cfsStartClient(clientId);
if (result != 0)
{
std::cerr << "Failed to start client" << std::endl;
cfsCloseClient(clientId);
dlclose(handle);
return 1;
}
int fd = cfsOpen(clientId, strdup("/test_dir/file.txt"), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd < 0)
{
printf("Failed to open file\n");
cfsCloseClient(clientId);
return -1;
}
const char * data = "xieyichen";
if (cfsWrite(clientId, fd, static_cast<void *>(const_cast<char *>(data)), strlen(data), 0) < 0)
{
printf("Failed to write file\n");
cfsClose(clientId, fd);
cfsCloseClient(clientId);
return -1;
}
char buffer[1024];
memset(buffer, 0, sizeof(buffer));
if (cfsRead(clientId, fd, static_cast<void *>(const_cast<char *>(buffer)), sizeof(buffer), 0) < 0)
{
printf("Failed to read file\n");
cfsClose(clientId, fd);
cfsCloseClient(clientId);
return -1;
}
printf("Read file content: %s\n", buffer);
cfsCloseClient(clientId);
dlclose(handle);
return 0;
}
Loading

0 comments on commit a8f5568

Please sign in to comment.