From dffaac55ea2a07c53bf0a7b05ed1b2a71da903f1 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 6 Nov 2023 14:57:32 +0800 Subject: [PATCH] fix:move cos from util to common --- include/{util => common}/cos.h | 0 include/{util => common}/rsync.h | 0 source/common/CMakeLists.txt | 69 +++++++++++++++++++++++++++++ source/{util => common}/src/cos.c | 21 ++++----- source/{util => common}/src/rsync.c | 0 source/dnode/vnode/CMakeLists.txt | 69 ----------------------------- 6 files changed, 80 insertions(+), 79 deletions(-) rename include/{util => common}/cos.h (100%) rename include/{util => common}/rsync.h (100%) rename source/{util => common}/src/cos.c (98%) rename source/{util => common}/src/rsync.c (100%) diff --git a/include/util/cos.h b/include/common/cos.h similarity index 100% rename from include/util/cos.h rename to include/common/cos.h diff --git a/include/util/rsync.h b/include/common/rsync.h similarity index 100% rename from include/util/rsync.h rename to include/common/rsync.h diff --git a/source/common/CMakeLists.txt b/source/common/CMakeLists.txt index c35845f9df..c7831b2b6d 100644 --- a/source/common/CMakeLists.txt +++ b/source/common/CMakeLists.txt @@ -46,6 +46,75 @@ target_link_libraries( INTERFACE api ) +if(${BUILD_S3}) + + if(${BUILD_WITH_S3}) + target_include_directories( + common + + PUBLIC "$ENV{HOME}/.cos-local.2/include" + ) + + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + set(CMAKE_PREFIX_PATH $ENV{HOME}/.cos-local.2) + find_library(S3_LIBRARY s3) + find_library(CURL_LIBRARY curl $ENV{HOME}/.cos-local.2/lib NO_DEFAULT_PATH) + find_library(XML2_LIBRARY xml2) + find_library(SSL_LIBRARY ssl $ENV{HOME}/.cos-local.2/lib64 NO_DEFAULT_PATH) + find_library(CRYPTO_LIBRARY crypto $ENV{HOME}/.cos-local.2/lib64 NO_DEFAULT_PATH) + target_link_libraries( + common + + # s3 + PUBLIC ${S3_LIBRARY} + PUBLIC ${CURL_LIBRARY} + PUBLIC ${SSL_LIBRARY} + PUBLIC ${CRYPTO_LIBRARY} + PUBLIC ${XML2_LIBRARY} + ) + + add_definitions(-DUSE_S3) + endif() + + if(${BUILD_WITH_COS}) + + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + find_library(APR_LIBRARY apr-1 PATHS /usr/local/apr/lib/) + find_library(APR_UTIL_LIBRARY aprutil-1 PATHS /usr/local/apr/lib/) + find_library(MINIXML_LIBRARY mxml) + find_library(CURL_LIBRARY curl) + target_link_libraries( + common + + # s3 + PUBLIC cos_c_sdk_static + PUBLIC ${APR_UTIL_LIBRARY} + PUBLIC ${APR_LIBRARY} + PUBLIC ${MINIXML_LIBRARY} + PUBLIC ${CURL_LIBRARY} + ) + + # s3 + FIND_PROGRAM(APR_CONFIG_BIN NAMES apr-config apr-1-config PATHS /usr/bin /usr/local/bin /usr/local/apr/bin/) + IF (APR_CONFIG_BIN) + EXECUTE_PROCESS( + COMMAND ${APR_CONFIG_BIN} --includedir + OUTPUT_VARIABLE APR_INCLUDE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + ENDIF() + include_directories (${APR_INCLUDE_DIR}) + target_include_directories( + common + PUBLIC "${TD_SOURCE_DIR}/contrib/cos-c-sdk-v5/cos_c_sdk" + PUBLIC "$ENV{HOME}/.cos-local.1/include" + ) + + add_definitions(-DUSE_COS) + endif(${BUILD_WITH_COS}) + +endif() + if(${BUILD_TEST}) ADD_SUBDIRECTORY(test) endif(${BUILD_TEST}) diff --git a/source/util/src/cos.c b/source/common/src/cos.c similarity index 98% rename from source/util/src/cos.c rename to source/common/src/cos.c index 23b2d53990..67ddb4a748 100644 --- a/source/util/src/cos.c +++ b/source/common/src/cos.c @@ -13,6 +13,7 @@ extern int8_t tsS3Https; #if defined(USE_S3) #include "libs3.h" +#include "tarray.h" static int verifyPeerG = 0; static const char *awsRegionG = NULL; @@ -34,7 +35,7 @@ static int32_t s3Begin() { } if ((status = S3_initialize("s3", verifyPeerG | S3_INIT_ALL, hostname)) != S3StatusOK) { - vError("Failed to initialize libs3: %s\n", S3_get_status_name(status)); + uError("Failed to initialize libs3: %s\n", S3_get_status_name(status)); return -1; } @@ -65,9 +66,9 @@ static int should_retry() { static void s3PrintError(const char *func, S3Status status, char error_details[]) { if (status < S3StatusErrorAccessDenied) { - vError("%s: %s", __func__, S3_get_status_name(status)); + uError("%s: %s", __func__, S3_get_status_name(status)); } else { - vError("%s: %s, %s", __func__, S3_get_status_name(status), error_details); + uError("%s: %s, %s", __func__, S3_get_status_name(status), error_details); } } @@ -445,13 +446,13 @@ int32_t s3PutObjectFromFile2(const char *file, const char *object) { data.noStatus = noStatus; if (taosStatFile(file, &contentLength, NULL, NULL) < 0) { - vError("ERROR: %s Failed to stat file %s: ", __func__, file); + uError("ERROR: %s Failed to stat file %s: ", __func__, file); code = TAOS_SYSTEM_ERROR(errno); return code; } if (!(data.infileFD = taosOpenFile(file, TD_FILE_READ))) { - vError("ERROR: %s Failed to open file %s: ", __func__, file); + uError("ERROR: %s Failed to open file %s: ", __func__, file); code = TAOS_SYSTEM_ERROR(errno); return code; } @@ -486,7 +487,7 @@ int32_t s3PutObjectFromFile2(const char *file, const char *object) { s3PrintError(__func__, data.status, data.err_msg); code = TAOS_SYSTEM_ERROR(EIO); } else if (data.contentLength) { - vError("ERROR: %s Failed to read remaining %llu bytes from input", __func__, + uError("ERROR: %s Failed to read remaining %llu bytes from input", __func__, (unsigned long long)data.contentLength); code = TAOS_SYSTEM_ERROR(EIO); } @@ -667,9 +668,9 @@ void s3DeleteObjectsByPrefix(const char *prefix) { const char *marker = 0, *delimiter = 0; int maxkeys = 0, allDetails = 0; list_bucket_callback_data data; - data.objectArray = taosArrayInit(32, POINTER_BYTES); + data.objectArray = taosArrayInit(32, sizeof(void*)); if (!data.objectArray) { - vError("%s: %s", __func__, "out of memoty"); + uError("%s: %s", __func__, "out of memoty"); return; } if (marker) { @@ -758,7 +759,7 @@ int32_t s3GetObjectBlock(const char *object_name, int64_t offset, int64_t size, } while (S3_status_is_retryable(cbd.status) && should_retry()); if (cbd.status != S3StatusOK) { - vError("%s: %d(%s)", __func__, cbd.status, cbd.err_msg); + uError("%s: %d(%s)", __func__, cbd.status, cbd.err_msg); return TAOS_SYSTEM_ERROR(EIO); } @@ -782,7 +783,7 @@ long s3Size(const char *object_name) { } while (S3_status_is_retryable(cbd.status) && should_retry()); if ((cbd.status != S3StatusOK) && (cbd.status != S3StatusErrorPreconditionFailed)) { - vError("%s: %d(%s)", __func__, cbd.status, cbd.err_msg); + uError("%s: %d(%s)", __func__, cbd.status, cbd.err_msg); } size = cbd.content_length; diff --git a/source/util/src/rsync.c b/source/common/src/rsync.c similarity index 100% rename from source/util/src/rsync.c rename to source/common/src/rsync.c diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index 27cb0f93f7..dc43da7fe7 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -160,75 +160,6 @@ target_link_libraries( PUBLIC index ) -if(${BUILD_S3}) - -if(${BUILD_WITH_S3}) - target_include_directories( - vnode - - PUBLIC "$ENV{HOME}/.cos-local.2/include" - ) - - set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") - set(CMAKE_PREFIX_PATH $ENV{HOME}/.cos-local.2) - find_library(S3_LIBRARY s3) - find_library(CURL_LIBRARY curl $ENV{HOME}/.cos-local.2/lib NO_DEFAULT_PATH) - find_library(XML2_LIBRARY xml2) - find_library(SSL_LIBRARY ssl $ENV{HOME}/.cos-local.2/lib64 NO_DEFAULT_PATH) - find_library(CRYPTO_LIBRARY crypto $ENV{HOME}/.cos-local.2/lib64 NO_DEFAULT_PATH) - target_link_libraries( - vnode - - # s3 - PUBLIC ${S3_LIBRARY} - PUBLIC ${CURL_LIBRARY} - PUBLIC ${SSL_LIBRARY} - PUBLIC ${CRYPTO_LIBRARY} - PUBLIC ${XML2_LIBRARY} - ) - - add_definitions(-DUSE_S3) -endif() - -if(${BUILD_WITH_COS}) - -set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") -find_library(APR_LIBRARY apr-1 PATHS /usr/local/apr/lib/) -find_library(APR_UTIL_LIBRARY aprutil-1 PATHS /usr/local/apr/lib/) -find_library(MINIXML_LIBRARY mxml) -find_library(CURL_LIBRARY curl) -target_link_libraries( - vnode - - # s3 - PUBLIC cos_c_sdk_static - PUBLIC ${APR_UTIL_LIBRARY} - PUBLIC ${APR_LIBRARY} - PUBLIC ${MINIXML_LIBRARY} - PUBLIC ${CURL_LIBRARY} -) - -# s3 -FIND_PROGRAM(APR_CONFIG_BIN NAMES apr-config apr-1-config PATHS /usr/bin /usr/local/bin /usr/local/apr/bin/) -IF (APR_CONFIG_BIN) - EXECUTE_PROCESS( - COMMAND ${APR_CONFIG_BIN} --includedir - OUTPUT_VARIABLE APR_INCLUDE_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE - ) -ENDIF() -include_directories (${APR_INCLUDE_DIR}) -target_include_directories( - vnode - PUBLIC "${TD_SOURCE_DIR}/contrib/cos-c-sdk-v5/cos_c_sdk" - PUBLIC "$ENV{HOME}/.cos-local.1/include" - ) - - add_definitions(-DUSE_COS) -endif(${BUILD_WITH_COS}) - -endif() - IF (TD_GRANT) TARGET_LINK_LIBRARIES(vnode PUBLIC grant) ENDIF ()