forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from RunningXie/feature_support_cubefs_sdk
rc4Feature support cubefs sdk
- Loading branch information
Showing
24 changed files
with
1,970 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.