未验证 提交 1a1a12b7 编写于 作者: W wade zhang 提交者: GitHub

Merge pull request #22327 from taosdata/fix/TD-25010-3

feat(tsdb/cos): s3 migration
# apr-util
ExternalProject_Add(aprutil-1
URL https://dlcdn.apache.org//apr/apr-util-1.6.3.tar.gz
URL_HASH SHA256=2b74d8932703826862ca305b094eef2983c27b39d5c9414442e9976a9acf1983
DOWNLOAD_NO_PROGRESS 1
DOWNLOAD_DIR "${TD_CONTRIB_DIR}/deps-download"
#GIT_REPOSITORY https://github.com/apache/apr-util.git
#GIT_TAG 1.5.4
SOURCE_DIR "${TD_CONTRIB_DIR}/apr-util"
#BINARY_DIR ""
BUILD_IN_SOURCE TRUE
BUILD_ALWAYS 1
#UPDATE_COMMAND ""
CONFIGURE_COMMAND ./configure --prefix=$ENV{HOME}/.cos-local.1/ --with-apr=$ENV{HOME}/.cos-local.1
#CONFIGURE_COMMAND ./configure --with-apr=/usr/local/apr
BUILD_COMMAND make
INSTALL_COMMAND make install
TEST_COMMAND ""
)
# apr
ExternalProject_Add(apr-1
URL https://dlcdn.apache.org//apr/apr-1.7.4.tar.gz
URL_HASH SHA256=a4137dd82a185076fa50ba54232d920a17c6469c30b0876569e1c2a05ff311d9
DOWNLOAD_NO_PROGRESS 1
DOWNLOAD_DIR "${TD_CONTRIB_DIR}/deps-download"
#GIT_REPOSITORY https://github.com/apache/apr.git
#GIT_TAG 1.5.2
SOURCE_DIR "${TD_CONTRIB_DIR}/apr"
BUILD_IN_SOURCE TRUE
UPDATE_DISCONNECTED TRUE
BUILD_ALWAYS 1
#UPDATE_COMMAND ""
CONFIGURE_COMMAND ./configure --prefix=$ENV{HOME}/.cos-local.1/ --enable-shared=no
#CONFIGURE_COMMAND ./configure
BUILD_COMMAND make
INSTALL_COMMAND make install
TEST_COMMAND ""
)
...@@ -125,6 +125,16 @@ option( ...@@ -125,6 +125,16 @@ option(
ON ON
) )
IF(${TD_LINUX})
option(
BUILD_WITH_COS
"If build with cos"
ON
)
ENDIF ()
option( option(
BUILD_WITH_SQLITE BUILD_WITH_SQLITE
"If build with sqlite" "If build with sqlite"
......
# cos
ExternalProject_Add(cos
GIT_REPOSITORY https://github.com/tencentyun/cos-c-sdk-v5.git
GIT_TAG v5.0.16
SOURCE_DIR "${TD_CONTRIB_DIR}/cos-c-sdk-v5"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
# curl
ExternalProject_Add(curl
URL https://curl.se/download/curl-8.2.1.tar.gz
DOWNLOAD_NO_PROGRESS 1
DOWNLOAD_DIR "${TD_CONTRIB_DIR}/deps-download"
#GIT_REPOSITORY https://github.com/curl/curl.git
#GIT_TAG curl-7_88_1
SOURCE_DIR "${TD_CONTRIB_DIR}/curl"
BUILD_IN_SOURCE TRUE
BUILD_ALWAYS 1
#UPDATE_COMMAND ""
CONFIGURE_COMMAND ./configure --prefix=$ENV{HOME}/.cos-local.1 --without-ssl --enable-shared=no --disable-ldap --disable-ldaps --without-brotli
#CONFIGURE_COMMAND ./configure --without-ssl
BUILD_COMMAND make
INSTALL_COMMAND make install
TEST_COMMAND ""
)
# cos
ExternalProject_Add(mxml
GIT_REPOSITORY https://github.com/michaelrsweet/mxml.git
GIT_TAG release-2.10
SOURCE_DIR "${TD_CONTRIB_DIR}/mxml"
#BINARY_DIR ""
BUILD_IN_SOURCE TRUE
#UPDATE_COMMAND ""
CONFIGURE_COMMAND ./configure --prefix=$ENV{HOME}/.cos-local.1 --enable-shared=no
#CONFIGURE_COMMAND ./configure
BUILD_COMMAND make
INSTALL_COMMAND make install
TEST_COMMAND ""
)
...@@ -6,6 +6,39 @@ function(cat IN_FILE OUT_FILE) ...@@ -6,6 +6,39 @@ function(cat IN_FILE OUT_FILE)
file(APPEND ${OUT_FILE} "${CONTENTS}") file(APPEND ${OUT_FILE} "${CONTENTS}")
endfunction(cat IN_FILE OUT_FILE) endfunction(cat IN_FILE OUT_FILE)
if(${TD_LINUX})
set(CONTRIB_TMP_FILE3 "${CMAKE_BINARY_DIR}/deps_tmp_CMakeLists.txt.in3")
configure_file("${TD_SUPPORT_DIR}/deps_CMakeLists.txt.in" ${CONTRIB_TMP_FILE3})
if(${BUILD_WITH_COS})
file(MAKE_DIRECTORY $ENV{HOME}/.cos-local.1/)
cat("${TD_SUPPORT_DIR}/mxml_CMakeLists.txt.in" ${CONTRIB_TMP_FILE3})
cat("${TD_SUPPORT_DIR}/apr_CMakeLists.txt.in" ${CONTRIB_TMP_FILE3})
cat("${TD_SUPPORT_DIR}/curl_CMakeLists.txt.in" ${CONTRIB_TMP_FILE3})
endif(${BUILD_WITH_COS})
configure_file(${CONTRIB_TMP_FILE3} "${TD_CONTRIB_DIR}/deps-download/CMakeLists.txt")
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${TD_CONTRIB_DIR}/deps-download")
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${TD_CONTRIB_DIR}/deps-download")
set(CONTRIB_TMP_FILE2 "${CMAKE_BINARY_DIR}/deps_tmp_CMakeLists.txt.in2")
configure_file("${TD_SUPPORT_DIR}/deps_CMakeLists.txt.in" ${CONTRIB_TMP_FILE2})
if(${BUILD_WITH_COS})
cat("${TD_SUPPORT_DIR}/apr-util_CMakeLists.txt.in" ${CONTRIB_TMP_FILE2})
endif(${BUILD_WITH_COS})
configure_file(${CONTRIB_TMP_FILE2} "${TD_CONTRIB_DIR}/deps-download/CMakeLists.txt")
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${TD_CONTRIB_DIR}/deps-download")
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${TD_CONTRIB_DIR}/deps-download")
endif(${TD_LINUX})
set(CONTRIB_TMP_FILE "${CMAKE_BINARY_DIR}/deps_tmp_CMakeLists.txt.in") set(CONTRIB_TMP_FILE "${CMAKE_BINARY_DIR}/deps_tmp_CMakeLists.txt.in")
configure_file("${TD_SUPPORT_DIR}/deps_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) configure_file("${TD_SUPPORT_DIR}/deps_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
...@@ -122,6 +155,16 @@ if(${BUILD_WITH_SQLITE}) ...@@ -122,6 +155,16 @@ if(${BUILD_WITH_SQLITE})
cat("${TD_SUPPORT_DIR}/sqlite_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) cat("${TD_SUPPORT_DIR}/sqlite_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_SQLITE}) endif(${BUILD_WITH_SQLITE})
# cos
if(${BUILD_WITH_COS})
#cat("${TD_SUPPORT_DIR}/mxml_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
#cat("${TD_SUPPORT_DIR}/apr_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
#cat("${TD_SUPPORT_DIR}/apr-util_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
#cat("${TD_SUPPORT_DIR}/curl_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
cat("${TD_SUPPORT_DIR}/cos_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
add_definitions(-DUSE_COS)
endif(${BUILD_WITH_COS})
# lucene # lucene
if(${BUILD_WITH_LUCENE}) if(${BUILD_WITH_LUCENE})
cat("${TD_SUPPORT_DIR}/lucene_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) cat("${TD_SUPPORT_DIR}/lucene_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
...@@ -347,6 +390,31 @@ if (${BUILD_WITH_ROCKSDB}) ...@@ -347,6 +390,31 @@ if (${BUILD_WITH_ROCKSDB})
endif() endif()
endif() endif()
# cos
if(${BUILD_WITH_COS})
if(${TD_LINUX})
set(CMAKE_PREFIX_PATH $ENV{HOME}/.cos-local.1)
#ADD_DEFINITIONS(-DMINIXML_LIBRARY=${CMAKE_BINARY_DIR}/build/lib/libxml.a)
option(ENABLE_TEST "Enable the tests" OFF)
INCLUDE_DIRECTORIES($ENV{HOME}/.cos-local.1/include)
MESSAGE("$ENV{HOME}/.cos-local.1/include")
set(CMAKE_BUILD_TYPE debug)
set(ORIG_CMAKE_PROJECT_NAME ${CMAKE_PROJECT_NAME})
set(CMAKE_PROJECT_NAME cos_c_sdk)
add_subdirectory(cos-c-sdk-v5 EXCLUDE_FROM_ALL)
target_include_directories(
cos_c_sdk
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cos-c-sdk-v5/cos_c_sdk>
)
set(CMAKE_PROJECT_NAME ${ORIG_CMAKE_PROJECT_NAME})
else()
endif(${TD_LINUX})
endif(${BUILD_WITH_COS})
# lucene # lucene
# To support build on ubuntu: sudo apt-get install libboost-all-dev # To support build on ubuntu: sudo apt-get install libboost-all-dev
if(${BUILD_WITH_LUCENE}) if(${BUILD_WITH_LUCENE})
......
...@@ -3,6 +3,11 @@ if(${BUILD_WITH_ROCKSDB}) ...@@ -3,6 +3,11 @@ if(${BUILD_WITH_ROCKSDB})
add_subdirectory(rocksdb) add_subdirectory(rocksdb)
endif(${BUILD_WITH_ROCKSDB}) endif(${BUILD_WITH_ROCKSDB})
# cos
if(${BUILD_WITH_COS})
add_subdirectory(cos)
endif(${BUILD_WITH_COS})
if(${BUILD_WITH_LUCENE}) if(${BUILD_WITH_LUCENE})
add_subdirectory(lucene) add_subdirectory(lucene)
endif(${BUILD_WITH_LUCENE}) endif(${BUILD_WITH_LUCENE})
......
add_executable(cosTest "")
target_sources(cosTest
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/main.c"
)
#find_path(APR_INCLUDE_DIR apr-1/apr_time.h)
#find_path(APR_UTIL_INCLUDE_DIR apr/include/apr-1/apr_md5.h)
#find_path(MINIXML_INCLUDE_DIR mxml.h)
#find_path(CURL_INCLUDE_DIR curl/curl.h)
#include_directories (${MINIXML_INCLUDE_DIR})
#include_directories (${CURL_INCLUDE_DIR})
FIND_PROGRAM(APR_CONFIG_BIN NAMES apr-config apr-1-config PATHS /usr/bin /usr/local/bin /usr/local/apr/bin/)
#FIND_PROGRAM(APU_CONFIG_BIN NAMES apu-config apu-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()
#IF (APU_CONFIG_BIN)
# EXECUTE_PROCESS(
# COMMAND ${APU_CONFIG_BIN} --includedir
# OUTPUT_VARIABLE APR_UTIL_INCLUDE_DIR
# OUTPUT_STRIP_TRAILING_WHITESPACE
# )
#ENDIF()
include_directories (${APR_INCLUDE_DIR})
#include_directories (${APR_UTIL_INCLUDE_DIR})
target_include_directories(
cosTest
PUBLIC "${TD_SOURCE_DIR}/contrib/cos-c-sdk-v5/cos_c_sdk"
)
#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(cosTest cos_c_sdk)
target_link_libraries(cosTest apr-1})
target_link_libraries(cosTest aprutil-1})
target_link_libraries(cosTest mxml)
target_link_libraries(cosTest curl)
#include <stdint.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include "cos_api.h"
#include "cos_http_io.h"
#include "cos_log.h"
// endpoint 是 COS 访问域名信息,详情请参见 https://cloud.tencent.com/document/product/436/6224 文档
// static char TEST_COS_ENDPOINT[] = "cos.ap-guangzhou.myqcloud.com";
// static char TEST_COS_ENDPOINT[] = "http://oss-cn-beijing.aliyuncs.com";
static char TEST_COS_ENDPOINT[] = "http://cos.ap-beijing.myqcloud.com";
// 数据万象的访问域名,详情请参见 https://cloud.tencent.com/document/product/460/31066 文档
static char TEST_CI_ENDPOINT[] = "https://ci.ap-guangzhou.myqcloud.com";
// 开发者拥有的项目身份ID/密钥,可在 https://console.cloud.tencent.com/cam/capi 页面获取
static char *TEST_ACCESS_KEY_ID; // your secret_id
static char *TEST_ACCESS_KEY_SECRET; // your secret_key
// 开发者访问 COS 服务时拥有的用户维度唯一资源标识,用以标识资源,可在 https://console.cloud.tencent.com/cam/capi
// 页面获取
// static char TEST_APPID[] = "<APPID>"; // your appid
// static char TEST_APPID[] = "119"; // your appid
static char TEST_APPID[] = "1309024725"; // your appid
// the cos bucket name, syntax: [bucket]-[appid], for example: mybucket-1253666666,可在
// https://console.cloud.tencent.com/cos5/bucket 查看 static char TEST_BUCKET_NAME[] = "<bucketname-appid>";
// static char TEST_BUCKET_NAME[] = "<bucketname-appid>";
// static char TEST_BUCKET_NAME[] = "test-bucket-119";
static char TEST_BUCKET_NAME[] = "test0711-1309024725";
// 对象拥有者,比如用户UIN:100000000001
static char TEST_UIN[] = "<Uin>"; // your uin
// 地域信息,枚举值可参见 https://cloud.tencent.com/document/product/436/6224
// 文档,例如:ap-beijing、ap-hongkong、eu-frankfurt 等
static char TEST_REGION[] = "ap-guangzhou"; // region in endpoint
// 对象键,对象(Object)在存储桶(Bucket)中的唯一标识。有关对象与对象键的进一步说明,请参见
// https://cloud.tencent.com/document/product/436/13324 文档
static char TEST_OBJECT_NAME1[] = "1.txt";
static char TEST_OBJECT_NAME2[] = "test2.dat";
static char TEST_OBJECT_NAME3[] = "test3.dat";
static char TEST_OBJECT_NAME4[] = "multipart.txt";
// static char TEST_DOWNLOAD_NAME2[] = "download_test2.dat";
static char *TEST_APPEND_NAMES[] = {"test.7z.001", "test.7z.002"};
static char TEST_DOWNLOAD_NAME3[] = "download_test3.dat";
static char TEST_MULTIPART_OBJECT[] = "multipart.dat";
static char TEST_DOWNLOAD_NAME4[] = "multipart_download.dat";
static char TEST_MULTIPART_FILE[] = "test.zip";
// static char TEST_MULTIPART_OBJECT2[] = "multipart2.dat";
static char TEST_MULTIPART_OBJECT3[] = "multipart3.dat";
static char TEST_MULTIPART_OBJECT4[] = "multipart4.dat";
static void print_headers(cos_table_t *headers) {
const cos_array_header_t *tarr;
const cos_table_entry_t *telts;
int i = 0;
if (apr_is_empty_table(headers)) {
return;
}
tarr = cos_table_elts(headers);
telts = (cos_table_entry_t *)tarr->elts;
printf("headers:\n");
for (; i < tarr->nelts; i++) {
telts = (cos_table_entry_t *)(tarr->elts + i * tarr->elt_size);
printf("%s: %s\n", telts->key, telts->val);
}
}
void init_test_config(cos_config_t *config, int is_cname) {
cos_str_set(&config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&config->appid, TEST_APPID);
config->is_cname = is_cname;
}
void init_test_request_options(cos_request_options_t *options, int is_cname) {
options->config = cos_config_create(options->pool);
init_test_config(options->config, is_cname);
options->ctl = cos_http_controller_create(options->pool, 0);
}
void log_status(cos_status_t *s) {
cos_warn_log("status->code: %d", s->code);
if (s->error_code) cos_warn_log("status->error_code: %s", s->error_code);
if (s->error_msg) cos_warn_log("status->error_msg: %s", s->error_msg);
if (s->req_id) cos_warn_log("status->req_id: %s", s->req_id);
}
void test_sign() {
cos_pool_t *p = NULL;
const unsigned char secret_key[] = "your secret_key";
const unsigned char time_str[] = "1480932292;1481012292";
unsigned char sign_key[40];
cos_buf_t *fmt_str;
const char *value = NULL;
const char *uri = "/testfile";
const char *host = "testbucket-125000000.cn-north.myqcloud.com&range=bytes%3d0-3";
unsigned char fmt_str_hex[40];
cos_pool_create(&p, NULL);
fmt_str = cos_create_buf(p, 1024);
cos_get_hmac_sha1_hexdigest(sign_key, secret_key, sizeof(secret_key) - 1, time_str, sizeof(time_str) - 1);
char *pstr = apr_pstrndup(p, (char *)sign_key, sizeof(sign_key));
cos_warn_log("sign_key: %s", pstr);
// method
value = "get";
cos_buf_append_string(p, fmt_str, value, strlen(value));
cos_buf_append_string(p, fmt_str, "\n", sizeof("\n") - 1);
// canonicalized resource(URI)
cos_buf_append_string(p, fmt_str, uri, strlen(uri));
cos_buf_append_string(p, fmt_str, "\n", sizeof("\n") - 1);
// query-parameters
cos_buf_append_string(p, fmt_str, "\n", sizeof("\n") - 1);
// Host
cos_buf_append_string(p, fmt_str, "host=", sizeof("host=") - 1);
cos_buf_append_string(p, fmt_str, host, strlen(host));
cos_buf_append_string(p, fmt_str, "\n", sizeof("\n") - 1);
char *pstr3 = apr_pstrndup(p, (char *)fmt_str->pos, cos_buf_size(fmt_str));
cos_warn_log("Format string: %s", pstr3);
// Format-String sha1hash
cos_get_sha1_hexdigest(fmt_str_hex, (unsigned char *)fmt_str->pos, cos_buf_size(fmt_str));
char *pstr2 = apr_pstrndup(p, (char *)fmt_str_hex, sizeof(fmt_str_hex));
cos_warn_log("Format string sha1hash: %s", pstr2);
cos_pool_destroy(p);
}
void test_bucket() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_acl_e cos_acl = COS_ACL_PRIVATE;
cos_string_t bucket;
cos_table_t *resp_headers = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
// create test bucket
s = cos_create_bucket(options, &bucket, cos_acl, &resp_headers);
log_status(s);
// list object (get bucket)
cos_list_object_params_t *list_params = NULL;
list_params = cos_create_list_object_params(p);
cos_str_set(&list_params->encoding_type, "url");
s = cos_list_object(options, &bucket, list_params, &resp_headers);
log_status(s);
cos_list_object_content_t *content = NULL;
char *line = NULL;
cos_list_for_each_entry(cos_list_object_content_t, content, &list_params->object_list, node) {
line = apr_psprintf(p, "%.*s\t%.*s\t%.*s\n", content->key.len, content->key.data, content->size.len,
content->size.data, content->last_modified.len, content->last_modified.data);
printf("%s", line);
printf("next marker: %s\n", list_params->next_marker.data);
}
cos_list_object_common_prefix_t *common_prefix = NULL;
cos_list_for_each_entry(cos_list_object_common_prefix_t, common_prefix, &list_params->common_prefix_list, node) {
printf("common prefix: %s\n", common_prefix->prefix.data);
}
// delete bucket
s = cos_delete_bucket(options, &bucket, &resp_headers);
log_status(s);
cos_pool_destroy(p);
}
void test_list_objects() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers = NULL;
//创建内存池
cos_pool_create(&p, NULL);
//初始化请求选项
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
//获取对象列表
cos_list_object_params_t *list_params = NULL;
cos_list_object_content_t *content = NULL;
list_params = cos_create_list_object_params(p);
s = cos_list_object(options, &bucket, list_params, &resp_headers);
if (cos_status_is_ok(s)) {
printf("list object succeeded\n");
cos_list_for_each_entry(cos_list_object_content_t, content, &list_params->object_list, node) {
printf("object: %.*s\n", content->key.len, content->key.data);
}
} else {
printf("list object failed\n");
}
//销毁内存池
cos_pool_destroy(p);
}
void test_bucket_lifecycle() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_list_t rule_list;
cos_list_init(&rule_list);
cos_lifecycle_rule_content_t *rule_content = NULL;
rule_content = cos_create_lifecycle_rule_content(p);
cos_str_set(&rule_content->id, "testrule1");
cos_str_set(&rule_content->prefix, "abc/");
cos_str_set(&rule_content->status, "Enabled");
rule_content->expire.days = 365;
cos_list_add_tail(&rule_content->node, &rule_list);
rule_content = cos_create_lifecycle_rule_content(p);
cos_str_set(&rule_content->id, "testrule2");
cos_str_set(&rule_content->prefix, "efg/");
cos_str_set(&rule_content->status, "Disabled");
cos_str_set(&rule_content->transition.storage_class, "Standard_IA");
rule_content->transition.days = 999;
cos_list_add_tail(&rule_content->node, &rule_list);
rule_content = cos_create_lifecycle_rule_content(p);
cos_str_set(&rule_content->id, "testrule3");
cos_str_set(&rule_content->prefix, "xxx/");
cos_str_set(&rule_content->status, "Enabled");
rule_content->abort.days = 1;
cos_list_add_tail(&rule_content->node, &rule_list);
s = cos_put_bucket_lifecycle(options, &bucket, &rule_list, &resp_headers);
log_status(s);
cos_list_t rule_list_ret;
cos_list_init(&rule_list_ret);
s = cos_get_bucket_lifecycle(options, &bucket, &rule_list_ret, &resp_headers);
log_status(s);
cos_delete_bucket_lifecycle(options, &bucket, &resp_headers);
log_status(s);
cos_pool_destroy(p);
}
void test_put_object_with_limit() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t file;
cos_table_t *resp_headers = NULL;
cos_table_t *headers = NULL;
//创建内存池
cos_pool_create(&p, NULL);
//初始化请求选项
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
//限速值设置范围为819200 - 838860800,即100KB/s - 100MB/s,如果超出该范围将返回400错误
headers = cos_table_make(p, 1);
cos_table_add_int(headers, "x-cos-traffic-limit", 819200);
//上传对象
cos_str_set(&file, "test_file.bin");
cos_str_set(&object, TEST_OBJECT_NAME1);
s = cos_put_object_from_file(options, &bucket, &object, &file, headers, &resp_headers);
if (cos_status_is_ok(s)) {
printf("put object succeeded\n");
} else {
printf("put object failed\n");
}
//销毁内存池
cos_pool_destroy(p);
}
void test_get_object_with_limit() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t file;
cos_table_t *resp_headers = NULL;
cos_table_t *headers = NULL;
//创建内存池
cos_pool_create(&p, NULL);
//初始化请求选项
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
//限速值设置范围为819200 - 838860800,即100KB/s - 100MB/s,如果超出该范围将返回400错误
headers = cos_table_make(p, 1);
cos_table_add_int(headers, "x-cos-traffic-limit", 819200);
//下载对象
cos_str_set(&file, "test_file.bin");
cos_str_set(&object, TEST_OBJECT_NAME1);
s = cos_get_object_to_file(options, &bucket, &object, headers, NULL, &file, &resp_headers);
if (cos_status_is_ok(s)) {
printf("get object succeeded\n");
} else {
printf("get object failed\n");
}
//销毁内存池
cos_pool_destroy(p);
}
void test_gen_object_url() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, TEST_OBJECT_NAME1);
printf("url:%s\n", cos_gen_object_url(options, &bucket, &object));
cos_pool_destroy(p);
}
void test_create_dir() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_table_t *resp_headers;
cos_table_t *headers = NULL;
cos_list_t buffer;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, "folder/");
//上传文件夹
cos_list_init(&buffer);
s = cos_put_object_from_buffer(options, &bucket, &object, &buffer, headers, &resp_headers);
if (cos_status_is_ok(s)) {
printf("put object succeeded\n");
} else {
printf("put object failed\n");
}
cos_pool_destroy(p);
}
void test_object() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_table_t *resp_headers;
cos_table_t *headers = NULL;
cos_list_t buffer;
cos_buf_t *content = NULL;
char *str = "This is my test data.";
cos_string_t file;
int traffic_limit = 0;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, TEST_OBJECT_NAME1);
cos_list_init(&buffer);
content = cos_buf_pack(options->pool, str, strlen(str));
cos_list_add_tail(&content->node, &buffer);
s = cos_put_object_from_buffer(options, &bucket, &object, &buffer, headers, &resp_headers);
log_status(s);
cos_list_t download_buffer;
cos_list_init(&download_buffer);
if (traffic_limit) {
// 限速值设置范围为819200 - 838860800,即100KB/s - 100MB/s,如果超出该范围将返回400错误
headers = cos_table_make(p, 1);
cos_table_add_int(headers, "x-cos-traffic-limit", 819200);
}
s = cos_get_object_to_buffer(options, &bucket, &object, headers, NULL, &download_buffer, &resp_headers);
log_status(s);
print_headers(resp_headers);
int64_t len = 0;
int64_t size = 0;
int64_t pos = 0;
cos_list_for_each_entry(cos_buf_t, content, &download_buffer, node) { len += cos_buf_size(content); }
char *buf = cos_pcalloc(p, (apr_size_t)(len + 1));
buf[len] = '\0';
cos_list_for_each_entry(cos_buf_t, content, &download_buffer, node) {
size = cos_buf_size(content);
memcpy(buf + pos, content->pos, (size_t)size);
pos += size;
}
cos_warn_log("Download data=%s", buf);
cos_str_set(&file, TEST_OBJECT_NAME4);
cos_str_set(&object, TEST_OBJECT_NAME4);
s = cos_put_object_from_file(options, &bucket, &object, &file, NULL, &resp_headers);
log_status(s);
cos_str_set(&file, TEST_DOWNLOAD_NAME3);
cos_str_set(&object, TEST_OBJECT_NAME3);
s = cos_get_object_to_file(options, &bucket, &object, NULL, NULL, &file, &resp_headers);
log_status(s);
cos_str_set(&object, TEST_OBJECT_NAME2);
s = cos_head_object(options, &bucket, &object, NULL, &resp_headers);
log_status(s);
cos_str_set(&object, TEST_OBJECT_NAME1);
s = cos_delete_object(options, &bucket, &object, &resp_headers);
log_status(s);
cos_str_set(&object, TEST_OBJECT_NAME3);
s = cos_delete_object(options, &bucket, &object, &resp_headers);
log_status(s);
cos_pool_destroy(p);
}
void test_append_object() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t file;
cos_table_t *resp_headers = NULL;
//创建内存池
cos_pool_create(&p, NULL);
//初始化请求选项
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
//追加上传对象
cos_str_set(&object, TEST_OBJECT_NAME3);
int32_t count = sizeof(TEST_APPEND_NAMES) / sizeof(char *);
int32_t index = 0;
int64_t position = 0;
s = cos_head_object(options, &bucket, &object, NULL, &resp_headers);
if (s->code == 200) {
char *content_length_str = (char *)apr_table_get(resp_headers, COS_CONTENT_LENGTH);
if (content_length_str != NULL) {
position = atol(content_length_str);
}
}
for (; index < count; index++) {
cos_str_set(&file, TEST_APPEND_NAMES[index]);
s = cos_append_object_from_file(options, &bucket, &object, position, &file, NULL, &resp_headers);
log_status(s);
s = cos_head_object(options, &bucket, &object, NULL, &resp_headers);
if (s->code == 200) {
char *content_length_str = (char *)apr_table_get(resp_headers, COS_CONTENT_LENGTH);
if (content_length_str != NULL) {
position = atol(content_length_str);
}
}
}
//销毁内存池
cos_pool_destroy(p);
}
void test_head_object() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_table_t *resp_headers = NULL;
//创建内存池
cos_pool_create(&p, NULL);
//初始化请求选项
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
//获取对象元数据
cos_str_set(&object, TEST_OBJECT_NAME1);
s = cos_head_object(options, &bucket, &object, NULL, &resp_headers);
print_headers(resp_headers);
if (cos_status_is_ok(s)) {
long size = 0;
char *content_length_str = (char *)apr_table_get(resp_headers, COS_CONTENT_LENGTH);
if (content_length_str != NULL) {
size = atol(content_length_str);
}
printf("head object succeeded: %ld\n", size);
} else {
printf("head object failed\n");
}
//销毁内存池
cos_pool_destroy(p);
}
void test_check_object_exist() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_table_t *resp_headers;
cos_table_t *headers = NULL;
cos_object_exist_status_e object_exist;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, TEST_OBJECT_NAME1);
// 检查对象是否存在
s = cos_check_object_exist(options, &bucket, &object, headers, &object_exist, &resp_headers);
if (object_exist == COS_OBJECT_NON_EXIST) {
printf("object: %.*s non exist.\n", object.len, object.data);
} else if (object_exist == COS_OBJECT_EXIST) {
printf("object: %.*s exist.\n", object.len, object.data);
} else {
printf("object: %.*s unknown status.\n", object.len, object.data);
log_status(s);
}
cos_pool_destroy(p);
}
void test_object_restore() {
cos_pool_t *p = NULL;
cos_string_t bucket;
cos_string_t object;
int is_cname = 0;
cos_table_t *resp_headers = NULL;
cos_request_options_t *options = NULL;
cos_status_t *s = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, "test_restore.dat");
cos_object_restore_params_t *restore_params = cos_create_object_restore_params(p);
restore_params->days = 30;
cos_str_set(&restore_params->tier, "Standard");
s = cos_post_object_restore(options, &bucket, &object, restore_params, NULL, NULL, &resp_headers);
log_status(s);
cos_pool_destroy(p);
}
void progress_callback(int64_t consumed_bytes, int64_t total_bytes) {
printf("consumed_bytes = %" APR_INT64_T_FMT ", total_bytes = %" APR_INT64_T_FMT "\n", consumed_bytes, total_bytes);
}
void test_put_object_from_file() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_table_t *resp_headers;
cos_string_t file;
int traffic_limit = 0;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_table_t *headers = NULL;
if (traffic_limit) {
// 限速值设置范围为819200 - 838860800,即100KB/s - 100MB/s,如果超出该范围将返回400错误
headers = cos_table_make(p, 1);
cos_table_add_int(headers, "x-cos-traffic-limit", 819200);
}
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&file, TEST_OBJECT_NAME4);
cos_str_set(&object, TEST_OBJECT_NAME4);
s = cos_put_object_from_file(options, &bucket, &object, &file, headers, &resp_headers);
log_status(s);
cos_pool_destroy(p);
}
void test_put_object_from_file_with_sse() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_table_t *resp_headers;
cos_string_t file;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_table_t *headers = NULL;
headers = cos_table_make(p, 3);
// apr_table_add(headers, "x-cos-server-side-encryption", "AES256");
apr_table_add(headers, "x-cos-server-side-encryption-customer-algorithm", "AES256");
apr_table_add(headers, "x-cos-server-side-encryption-customer-key", "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=");
apr_table_add(headers, "x-cos-server-side-encryption-customer-key-MD5", "U5L61r7jcwdNvT7frmUG8g==");
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&file, "/home/jojoliang/data/test.jpg");
cos_str_set(&object, "pic");
s = cos_put_object_from_file(options, &bucket, &object, &file, headers, &resp_headers);
log_status(s);
{
int i = 0;
apr_array_header_t *pp = (apr_array_header_t *)apr_table_elts(resp_headers);
for (; i < pp->nelts; i++) {
apr_table_entry_t *ele = (apr_table_entry_t *)pp->elts + i;
printf("%s: %s\n", ele->key, ele->val);
}
}
cos_pool_destroy(p);
}
void test_get_object_to_file_with_sse() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_table_t *resp_headers;
cos_string_t file;
cos_table_t *headers = NULL;
cos_table_t *params = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
headers = cos_table_make(p, 3);
/*
apr_table_add(headers, "x-cos-server-side-encryption", "AES256");
*/
/*
apr_table_add(headers, "x-cos-server-side-encryption-customer-algorithm", "AES256");
apr_table_add(headers, "x-cos-server-side-encryption-customer-key",
"MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY="); apr_table_add(headers,
"x-cos-server-side-encryption-customer-key-MD5", "U5L61r7jcwdNvT7frmUG8g==");
*/
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&file, "getfile");
cos_str_set(&object, TEST_OBJECT_NAME1);
s = cos_get_object_to_file(options, &bucket, &object, headers, params, &file, &resp_headers);
log_status(s);
{
int i = 0;
apr_array_header_t *pp = (apr_array_header_t *)apr_table_elts(resp_headers);
for (; i < pp->nelts; i++) {
apr_table_entry_t *ele = (apr_table_entry_t *)pp->elts + i;
printf("%s: %s\n", ele->key, ele->val);
}
}
cos_pool_destroy(p);
}
void multipart_upload_file_from_file() {
cos_pool_t *p = NULL;
cos_string_t bucket;
cos_string_t object;
int is_cname = 0;
cos_table_t *headers = NULL;
cos_table_t *complete_headers = NULL;
cos_table_t *resp_headers = NULL;
cos_request_options_t *options = NULL;
cos_string_t upload_id;
cos_upload_file_t *upload_file = NULL;
cos_status_t *s = NULL;
cos_list_upload_part_params_t *params = NULL;
cos_list_t complete_part_list;
cos_list_part_content_t *part_content = NULL;
cos_complete_part_content_t *complete_part_content = NULL;
int part_num = 1;
int64_t pos = 0;
int64_t file_length = 0;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
headers = cos_table_make(p, 1);
complete_headers = cos_table_make(p, 1);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, TEST_MULTIPART_OBJECT);
// init mulitipart
s = cos_init_multipart_upload(options, &bucket, &object, &upload_id, headers, &resp_headers);
if (cos_status_is_ok(s)) {
printf("Init multipart upload succeeded, upload_id:%.*s\n", upload_id.len, upload_id.data);
} else {
printf("Init multipart upload failed\n");
cos_pool_destroy(p);
return;
}
// upload part from file
int res = COSE_OK;
cos_file_buf_t *fb = cos_create_file_buf(p);
res = cos_open_file_for_all_read(p, TEST_MULTIPART_FILE, fb);
if (res != COSE_OK) {
cos_error_log("Open read file fail, filename:%s\n", TEST_MULTIPART_FILE);
return;
}
file_length = fb->file_last;
apr_file_close(fb->file);
while (pos < file_length) {
upload_file = cos_create_upload_file(p);
cos_str_set(&upload_file->filename, TEST_MULTIPART_FILE);
upload_file->file_pos = pos;
pos += 2 * 1024 * 1024;
upload_file->file_last = pos < file_length ? pos : file_length; // 2MB
s = cos_upload_part_from_file(options, &bucket, &object, &upload_id, part_num++, upload_file, &resp_headers);
if (cos_status_is_ok(s)) {
printf("Multipart upload part from file succeeded\n");
} else {
printf("Multipart upload part from file failed\n");
}
}
// list part
params = cos_create_list_upload_part_params(p);
params->max_ret = 1000;
cos_list_init(&complete_part_list);
s = cos_list_upload_part(options, &bucket, &object, &upload_id, params, &resp_headers);
if (cos_status_is_ok(s)) {
printf("List multipart succeeded\n");
cos_list_for_each_entry(cos_list_part_content_t, part_content, &params->part_list, node) {
printf("part_number = %s, size = %s, last_modified = %s, etag = %s\n", part_content->part_number.data,
part_content->size.data, part_content->last_modified.data, part_content->etag.data);
}
} else {
printf("List multipart failed\n");
cos_pool_destroy(p);
return;
}
cos_list_for_each_entry(cos_list_part_content_t, part_content, &params->part_list, node) {
complete_part_content = cos_create_complete_part_content(p);
cos_str_set(&complete_part_content->part_number, part_content->part_number.data);
cos_str_set(&complete_part_content->etag, part_content->etag.data);
cos_list_add_tail(&complete_part_content->node, &complete_part_list);
}
// complete multipart
s = cos_complete_multipart_upload(options, &bucket, &object, &upload_id, &complete_part_list, complete_headers,
&resp_headers);
if (cos_status_is_ok(s)) {
printf("Complete multipart upload from file succeeded, upload_id:%.*s\n", upload_id.len, upload_id.data);
} else {
printf("Complete multipart upload from file failed\n");
}
cos_pool_destroy(p);
}
void multipart_upload_file_from_buffer() {
cos_pool_t *p = NULL;
cos_string_t bucket;
cos_string_t object;
int is_cname = 0;
cos_table_t *headers = NULL;
cos_table_t *complete_headers = NULL;
cos_table_t *resp_headers = NULL;
cos_request_options_t *options = NULL;
cos_string_t upload_id;
cos_status_t *s = NULL;
cos_list_t complete_part_list;
cos_complete_part_content_t *complete_part_content = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
headers = cos_table_make(p, 1);
complete_headers = cos_table_make(p, 1);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, TEST_MULTIPART_OBJECT);
// init mulitipart
s = cos_init_multipart_upload(options, &bucket, &object, &upload_id, headers, &resp_headers);
if (cos_status_is_ok(s)) {
printf("Init multipart upload succeeded, upload_id:%.*s\n", upload_id.len, upload_id.data);
} else {
printf("Init multipart upload failed\n");
cos_pool_destroy(p);
return;
}
// upload part from buffer
char *str = "This is my test data....";
cos_list_t buffer;
cos_buf_t *content;
// 上传一个分块
cos_list_init(&buffer);
content = cos_buf_pack(p, str, strlen(str));
cos_list_add_tail(&content->node, &buffer);
s = cos_upload_part_from_buffer(options, &bucket, &object, &upload_id, 1, &buffer, &resp_headers);
// 直接获取etag
char *etag = apr_pstrdup(p, (char *)apr_table_get(resp_headers, "ETag"));
cos_list_init(&complete_part_list);
complete_part_content = cos_create_complete_part_content(p);
cos_str_set(&complete_part_content->part_number, "1");
cos_str_set(&complete_part_content->etag, etag);
cos_list_add_tail(&complete_part_content->node, &complete_part_list);
// 也可以通过 list part 获取取etag
/*
//list part
params = cos_create_list_upload_part_params(p);
params->max_ret = 1000;
cos_list_init(&complete_part_list);
s = cos_list_upload_part(options, &bucket, &object, &upload_id,
params, &resp_headers);
if (cos_status_is_ok(s)) {
printf("List multipart succeeded\n");
cos_list_for_each_entry(cos_list_part_content_t, part_content, &params->part_list, node) {
printf("part_number = %s, size = %s, last_modified = %s, etag = %s\n",
part_content->part_number.data,
part_content->size.data,
part_content->last_modified.data,
part_content->etag.data);
}
} else {
printf("List multipart failed\n");
cos_pool_destroy(p);
return;
}
cos_list_for_each_entry(cos_list_part_content_t, part_content, &params->part_list, node) {
complete_part_content = cos_create_complete_part_content(p);
cos_str_set(&complete_part_content->part_number, part_content->part_number.data);
cos_str_set(&complete_part_content->etag, part_content->etag.data);
cos_list_add_tail(&complete_part_content->node, &complete_part_list);
}
*/
// complete multipart
s = cos_complete_multipart_upload(options, &bucket, &object, &upload_id, &complete_part_list, complete_headers,
&resp_headers);
if (cos_status_is_ok(s)) {
printf("Complete multipart upload from file succeeded, upload_id:%.*s\n", upload_id.len, upload_id.data);
} else {
printf("Complete multipart upload from file failed\n");
}
cos_pool_destroy(p);
}
void abort_multipart_upload() {
cos_pool_t *p = NULL;
cos_string_t bucket;
cos_string_t object;
int is_cname = 0;
cos_table_t *headers = NULL;
cos_table_t *resp_headers = NULL;
cos_request_options_t *options = NULL;
cos_string_t upload_id;
cos_status_t *s = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
headers = cos_table_make(p, 1);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, TEST_MULTIPART_OBJECT);
s = cos_init_multipart_upload(options, &bucket, &object, &upload_id, headers, &resp_headers);
if (cos_status_is_ok(s)) {
printf("Init multipart upload succeeded, upload_id:%.*s\n", upload_id.len, upload_id.data);
} else {
printf("Init multipart upload failed\n");
cos_pool_destroy(p);
return;
}
s = cos_abort_multipart_upload(options, &bucket, &object, &upload_id, &resp_headers);
if (cos_status_is_ok(s)) {
printf("Abort multipart upload succeeded, upload_id::%.*s\n", upload_id.len, upload_id.data);
} else {
printf("Abort multipart upload failed\n");
}
cos_pool_destroy(p);
}
void list_multipart() {
cos_pool_t *p = NULL;
cos_string_t bucket;
cos_string_t object;
int is_cname = 0;
cos_table_t *resp_headers = NULL;
cos_request_options_t *options = NULL;
cos_status_t *s = NULL;
cos_list_multipart_upload_params_t *list_multipart_params = NULL;
cos_list_upload_part_params_t *list_upload_param = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
list_multipart_params = cos_create_list_multipart_upload_params(p);
list_multipart_params->max_ret = 999;
s = cos_list_multipart_upload(options, &bucket, list_multipart_params, &resp_headers);
log_status(s);
list_upload_param = cos_create_list_upload_part_params(p);
list_upload_param->max_ret = 1000;
cos_string_t upload_id;
cos_str_set(&upload_id, "149373379126aee264fecbf5fe8ddb8b9cd23b76c73ab1af0bcfd50683cc4254f81ebe2386");
cos_str_set(&object, TEST_MULTIPART_OBJECT);
s = cos_list_upload_part(options, &bucket, &object, &upload_id, list_upload_param, &resp_headers);
if (cos_status_is_ok(s)) {
printf("List upload part succeeded, upload_id::%.*s\n", upload_id.len, upload_id.data);
cos_list_part_content_t *part_content = NULL;
cos_list_for_each_entry(cos_list_part_content_t, part_content, &list_upload_param->part_list, node) {
printf("part_number = %s, size = %s, last_modified = %s, etag = %s\n", part_content->part_number.data,
part_content->size.data, part_content->last_modified.data, part_content->etag.data);
}
} else {
printf("List upload part failed\n");
}
cos_pool_destroy(p);
}
void test_resumable() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t filepath;
cos_resumable_clt_params_t *clt_params;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, TEST_MULTIPART_OBJECT4);
cos_str_set(&filepath, TEST_DOWNLOAD_NAME4);
clt_params = cos_create_resumable_clt_params_content(p, 5 * 1024 * 1024, 3, COS_FALSE, NULL);
s = cos_resumable_download_file(options, &bucket, &object, &filepath, NULL, NULL, clt_params, NULL);
log_status(s);
cos_pool_destroy(p);
}
void test_resumable_upload_with_multi_threads() {
cos_pool_t *p = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t filename;
cos_status_t *s = NULL;
int is_cname = 0;
cos_table_t *headers = NULL;
cos_table_t *resp_headers = NULL;
cos_request_options_t *options = NULL;
cos_resumable_clt_params_t *clt_params;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
headers = cos_table_make(p, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, TEST_MULTIPART_OBJECT4);
cos_str_set(&filename, TEST_MULTIPART_FILE);
// upload
clt_params = cos_create_resumable_clt_params_content(p, 1024 * 1024, 8, COS_FALSE, NULL);
s = cos_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL, clt_params, NULL, &resp_headers,
NULL);
if (cos_status_is_ok(s)) {
printf("upload succeeded\n");
} else {
printf("upload failed\n");
}
cos_pool_destroy(p);
}
void test_delete_objects() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_string_t bucket;
cos_status_t *s = NULL;
cos_table_t *resp_headers = NULL;
cos_request_options_t *options = NULL;
char *object_name1 = TEST_OBJECT_NAME2;
char *object_name2 = TEST_OBJECT_NAME3;
cos_object_key_t *content1 = NULL;
cos_object_key_t *content2 = NULL;
cos_list_t object_list;
cos_list_t deleted_object_list;
int is_quiet = COS_TRUE;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_list_init(&object_list);
cos_list_init(&deleted_object_list);
content1 = cos_create_cos_object_key(p);
cos_str_set(&content1->key, object_name1);
cos_list_add_tail(&content1->node, &object_list);
content2 = cos_create_cos_object_key(p);
cos_str_set(&content2->key, object_name2);
cos_list_add_tail(&content2->node, &object_list);
s = cos_delete_objects(options, &bucket, &object_list, is_quiet, &resp_headers, &deleted_object_list);
log_status(s);
cos_pool_destroy(p);
if (cos_status_is_ok(s)) {
printf("delete objects succeeded\n");
} else {
printf("delete objects failed\n");
}
}
void test_delete_objects_by_prefix() {
cos_pool_t *p = NULL;
cos_request_options_t *options = NULL;
int is_cname = 0;
cos_string_t bucket;
cos_status_t *s = NULL;
cos_string_t prefix;
char *prefix_str = "";
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&prefix, prefix_str);
s = cos_delete_objects_by_prefix(options, &bucket, &prefix);
log_status(s);
cos_pool_destroy(p);
printf("test_delete_object_by_prefix ok\n");
}
void test_acl() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_acl_e cos_acl = COS_ACL_PRIVATE;
cos_string_t bucket;
cos_string_t object;
cos_table_t *resp_headers = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, "test.txt");
// put acl
cos_string_t read;
cos_str_set(&read, "id=\"qcs::cam::uin/12345:uin/12345\", id=\"qcs::cam::uin/45678:uin/45678\"");
s = cos_put_bucket_acl(options, &bucket, cos_acl, &read, NULL, NULL, &resp_headers);
log_status(s);
// get acl
cos_acl_params_t *acl_params = NULL;
acl_params = cos_create_acl_params(p);
s = cos_get_bucket_acl(options, &bucket, acl_params, &resp_headers);
log_status(s);
printf("acl owner id:%s, name:%s\n", acl_params->owner_id.data, acl_params->owner_name.data);
cos_acl_grantee_content_t *acl_content = NULL;
cos_list_for_each_entry(cos_acl_grantee_content_t, acl_content, &acl_params->grantee_list, node) {
printf("acl grantee type:%s, id:%s, name:%s, permission:%s\n", acl_content->type.data, acl_content->id.data,
acl_content->name.data, acl_content->permission.data);
}
// put acl
s = cos_put_object_acl(options, &bucket, &object, cos_acl, &read, NULL, NULL, &resp_headers);
log_status(s);
// get acl
cos_acl_params_t *acl_params2 = NULL;
acl_params2 = cos_create_acl_params(p);
s = cos_get_object_acl(options, &bucket, &object, acl_params2, &resp_headers);
log_status(s);
printf("acl owner id:%s, name:%s\n", acl_params2->owner_id.data, acl_params2->owner_name.data);
acl_content = NULL;
cos_list_for_each_entry(cos_acl_grantee_content_t, acl_content, &acl_params2->grantee_list, node) {
printf("acl grantee id:%s, name:%s, permission:%s\n", acl_content->id.data, acl_content->name.data,
acl_content->permission.data);
}
cos_pool_destroy(p);
}
void test_copy() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t src_bucket;
cos_string_t src_object;
cos_string_t src_endpoint;
cos_table_t *resp_headers = NULL;
//创建内存池
cos_pool_create(&p, NULL);
//初始化请求选项
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
//设置对象复制
cos_str_set(&object, TEST_OBJECT_NAME2);
cos_str_set(&src_bucket, TEST_BUCKET_NAME);
cos_str_set(&src_endpoint, TEST_COS_ENDPOINT);
cos_str_set(&src_object, TEST_OBJECT_NAME1);
cos_copy_object_params_t *params = NULL;
params = cos_create_copy_object_params(p);
s = cos_copy_object(options, &src_bucket, &src_object, &src_endpoint, &bucket, &object, NULL, params, &resp_headers);
if (cos_status_is_ok(s)) {
printf("put object copy succeeded\n");
} else {
printf("put object copy failed\n");
}
//销毁内存池
cos_pool_destroy(p);
}
void test_modify_storage_class() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t src_bucket;
cos_string_t src_object;
cos_string_t src_endpoint;
cos_table_t *resp_headers = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, TEST_OBJECT_NAME1);
cos_str_set(&src_bucket, TEST_BUCKET_NAME);
cos_str_set(&src_endpoint, TEST_COS_ENDPOINT);
cos_str_set(&src_object, TEST_OBJECT_NAME1);
// 设置x-cos-metadata-directive和x-cos-storage-class头域(替换为自己要更改的存储类型)
cos_table_t *headers = cos_table_make(p, 2);
apr_table_add(headers, "x-cos-metadata-directive", "Replaced");
// 存储类型包括NTELLIGENT_TIERING,MAZ_INTELLIGENT_TIERING,STANDARD_IA,ARCHIVE,DEEP_ARCHIVE
apr_table_add(headers, "x-cos-storage-class", "ARCHIVE");
cos_copy_object_params_t *params = NULL;
params = cos_create_copy_object_params(p);
s = cos_copy_object(options, &src_bucket, &src_object, &src_endpoint, &bucket, &object, headers, params,
&resp_headers);
log_status(s);
cos_pool_destroy(p);
}
void test_copy_mt() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t src_bucket;
cos_string_t src_object;
cos_string_t src_endpoint;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, "test_copy.txt");
cos_str_set(&src_bucket, "mybucket-1253685564");
cos_str_set(&src_endpoint, "cn-south.myqcloud.com");
cos_str_set(&src_object, "test.txt");
s = cos_upload_object_by_part_copy_mt(options, &src_bucket, &src_object, &src_endpoint, &bucket, &object, 1024 * 1024,
8, NULL);
log_status(s);
cos_pool_destroy(p);
}
void test_copy_with_part_copy() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t copy_source;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, "test_copy.txt");
cos_str_set(&copy_source, "mybucket-1253685564.cn-south.myqcloud.com/test.txt");
s = cos_upload_object_by_part_copy(options, &copy_source, &bucket, &object, 1024 * 1024);
log_status(s);
cos_pool_destroy(p);
}
void make_rand_string(cos_pool_t *p, int len, cos_string_t *data) {
char *str = NULL;
int i = 0;
str = (char *)cos_palloc(p, len + 1);
for (; i < len; i++) {
str[i] = 'a' + rand() % 32;
}
str[len] = '\0';
cos_str_set(data, str);
}
unsigned long get_file_size(const char *file_path) {
unsigned long filesize = -1;
struct stat statbuff;
if (stat(file_path, &statbuff) < 0) {
return filesize;
} else {
filesize = statbuff.st_size;
}
return filesize;
}
void test_part_copy() {
cos_pool_t *p = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t file;
int is_cname = 0;
cos_string_t upload_id;
cos_list_upload_part_params_t *list_upload_part_params = NULL;
cos_upload_part_copy_params_t *upload_part_copy_params1 = NULL;
cos_upload_part_copy_params_t *upload_part_copy_params2 = NULL;
cos_table_t *headers = NULL;
cos_table_t *query_params = NULL;
cos_table_t *resp_headers = NULL;
cos_table_t *list_part_resp_headers = NULL;
cos_list_t complete_part_list;
cos_list_part_content_t *part_content = NULL;
cos_complete_part_content_t *complete_content = NULL;
cos_table_t *complete_resp_headers = NULL;
cos_status_t *s = NULL;
int part1 = 1;
int part2 = 2;
char *local_filename = "test_upload_part_copy.file";
char *download_filename = "test_upload_part_copy.file.download";
char *source_object_name = "cos_test_upload_part_copy_source_object";
char *dest_object_name = "cos_test_upload_part_copy_dest_object";
FILE *fd = NULL;
cos_string_t download_file;
cos_string_t dest_bucket;
cos_string_t dest_object;
int64_t range_start1 = 0;
int64_t range_end1 = 6000000;
int64_t range_start2 = 6000001;
int64_t range_end2;
cos_string_t data;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
// create multipart upload local file
make_rand_string(p, 10 * 1024 * 1024, &data);
fd = fopen(local_filename, "w");
fwrite(data.data, sizeof(data.data[0]), data.len, fd);
fclose(fd);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, source_object_name);
cos_str_set(&file, local_filename);
s = cos_put_object_from_file(options, &bucket, &object, &file, NULL, &resp_headers);
log_status(s);
// init mulitipart
cos_str_set(&object, dest_object_name);
s = cos_init_multipart_upload(options, &bucket, &object, &upload_id, NULL, &resp_headers);
log_status(s);
// upload part copy 1
upload_part_copy_params1 = cos_create_upload_part_copy_params(p);
cos_str_set(&upload_part_copy_params1->copy_source,
"bucket-appid.cn-south.myqcloud.com/cos_test_upload_part_copy_source_object");
cos_str_set(&upload_part_copy_params1->dest_bucket, TEST_BUCKET_NAME);
cos_str_set(&upload_part_copy_params1->dest_object, dest_object_name);
cos_str_set(&upload_part_copy_params1->upload_id, upload_id.data);
upload_part_copy_params1->part_num = part1;
upload_part_copy_params1->range_start = range_start1;
upload_part_copy_params1->range_end = range_end1;
headers = cos_table_make(p, 0);
s = cos_upload_part_copy(options, upload_part_copy_params1, headers, &resp_headers);
log_status(s);
printf("last modified:%s, etag:%s\n", upload_part_copy_params1->rsp_content->last_modify.data,
upload_part_copy_params1->rsp_content->etag.data);
// upload part copy 2
resp_headers = NULL;
range_end2 = get_file_size(local_filename) - 1;
upload_part_copy_params2 = cos_create_upload_part_copy_params(p);
cos_str_set(&upload_part_copy_params2->copy_source,
"bucket-appid.cn-south.myqcloud.com/cos_test_upload_part_copy_source_object");
cos_str_set(&upload_part_copy_params2->dest_bucket, TEST_BUCKET_NAME);
cos_str_set(&upload_part_copy_params2->dest_object, dest_object_name);
cos_str_set(&upload_part_copy_params2->upload_id, upload_id.data);
upload_part_copy_params2->part_num = part2;
upload_part_copy_params2->range_start = range_start2;
upload_part_copy_params2->range_end = range_end2;
headers = cos_table_make(p, 0);
s = cos_upload_part_copy(options, upload_part_copy_params2, headers, &resp_headers);
log_status(s);
printf("last modified:%s, etag:%s\n", upload_part_copy_params1->rsp_content->last_modify.data,
upload_part_copy_params1->rsp_content->etag.data);
// list part
list_upload_part_params = cos_create_list_upload_part_params(p);
list_upload_part_params->max_ret = 10;
cos_list_init(&complete_part_list);
cos_str_set(&dest_bucket, TEST_BUCKET_NAME);
cos_str_set(&dest_object, dest_object_name);
s = cos_list_upload_part(options, &dest_bucket, &dest_object, &upload_id, list_upload_part_params,
&list_part_resp_headers);
log_status(s);
cos_list_for_each_entry(cos_list_part_content_t, part_content, &list_upload_part_params->part_list, node) {
complete_content = cos_create_complete_part_content(p);
cos_str_set(&complete_content->part_number, part_content->part_number.data);
cos_str_set(&complete_content->etag, part_content->etag.data);
cos_list_add_tail(&complete_content->node, &complete_part_list);
}
// complete multipart
headers = cos_table_make(p, 0);
s = cos_complete_multipart_upload(options, &dest_bucket, &dest_object, &upload_id, &complete_part_list, headers,
&complete_resp_headers);
log_status(s);
// check upload copy part content equal to local file
headers = cos_table_make(p, 0);
cos_str_set(&download_file, download_filename);
s = cos_get_object_to_file(options, &dest_bucket, &dest_object, headers, query_params, &download_file, &resp_headers);
log_status(s);
printf("local file len = %" APR_INT64_T_FMT ", download file len = %" APR_INT64_T_FMT, get_file_size(local_filename),
get_file_size(download_filename));
remove(download_filename);
remove(local_filename);
cos_pool_destroy(p);
printf("test part copy ok\n");
}
void test_cors() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_list_t rule_list;
cos_list_init(&rule_list);
cos_cors_rule_content_t *rule_content = NULL;
rule_content = cos_create_cors_rule_content(p);
cos_str_set(&rule_content->id, "testrule1");
cos_str_set(&rule_content->allowed_origin, "http://www.qq1.com");
cos_str_set(&rule_content->allowed_method, "GET");
cos_str_set(&rule_content->allowed_header, "*");
cos_str_set(&rule_content->expose_header, "xxx");
rule_content->max_age_seconds = 3600;
cos_list_add_tail(&rule_content->node, &rule_list);
rule_content = cos_create_cors_rule_content(p);
cos_str_set(&rule_content->id, "testrule2");
cos_str_set(&rule_content->allowed_origin, "http://www.qq2.com");
cos_str_set(&rule_content->allowed_method, "GET");
cos_str_set(&rule_content->allowed_header, "*");
cos_str_set(&rule_content->expose_header, "yyy");
rule_content->max_age_seconds = 7200;
cos_list_add_tail(&rule_content->node, &rule_list);
rule_content = cos_create_cors_rule_content(p);
cos_str_set(&rule_content->id, "testrule3");
cos_str_set(&rule_content->allowed_origin, "http://www.qq3.com");
cos_str_set(&rule_content->allowed_method, "GET");
cos_str_set(&rule_content->allowed_header, "*");
cos_str_set(&rule_content->expose_header, "zzz");
rule_content->max_age_seconds = 60;
cos_list_add_tail(&rule_content->node, &rule_list);
// put cors
s = cos_put_bucket_cors(options, &bucket, &rule_list, &resp_headers);
log_status(s);
// get cors
cos_list_t rule_list_ret;
cos_list_init(&rule_list_ret);
s = cos_get_bucket_cors(options, &bucket, &rule_list_ret, &resp_headers);
log_status(s);
cos_cors_rule_content_t *content = NULL;
cos_list_for_each_entry(cos_cors_rule_content_t, content, &rule_list_ret, node) {
printf(
"cors id:%s, allowed_origin:%s, allowed_method:%s, allowed_header:%s, expose_header:%s, max_age_seconds:%d\n",
content->id.data, content->allowed_origin.data, content->allowed_method.data, content->allowed_header.data,
content->expose_header.data, content->max_age_seconds);
}
// delete cors
cos_delete_bucket_cors(options, &bucket, &resp_headers);
log_status(s);
cos_pool_destroy(p);
}
void test_versioning() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_versioning_content_t *versioning = NULL;
versioning = cos_create_versioning_content(p);
cos_str_set(&versioning->status, "Suspended");
// put bucket versioning
s = cos_put_bucket_versioning(options, &bucket, versioning, &resp_headers);
log_status(s);
// get bucket versioning
cos_str_set(&versioning->status, "");
s = cos_get_bucket_versioning(options, &bucket, versioning, &resp_headers);
log_status(s);
printf("bucket versioning status: %s\n", versioning->status.data);
cos_pool_destroy(p);
}
void test_replication() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_request_options_t *dst_options = NULL;
cos_string_t bucket;
cos_string_t dst_bucket;
cos_table_t *resp_headers = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&dst_bucket, "replicationtest");
dst_options = cos_request_options_create(p);
init_test_request_options(dst_options, is_cname);
cos_str_set(&dst_options->config->endpoint, "cn-east.myqcloud.com");
// enable bucket versioning
cos_versioning_content_t *versioning = NULL;
versioning = cos_create_versioning_content(p);
cos_str_set(&versioning->status, "Enabled");
s = cos_put_bucket_versioning(options, &bucket, versioning, &resp_headers);
log_status(s);
s = cos_put_bucket_versioning(dst_options, &dst_bucket, versioning, &resp_headers);
log_status(s);
cos_replication_params_t *replication_param = NULL;
replication_param = cos_create_replication_params(p);
cos_str_set(&replication_param->role, "qcs::cam::uin/100000616666:uin/100000616666");
cos_replication_rule_content_t *rule = NULL;
rule = cos_create_replication_rule_content(p);
cos_str_set(&rule->id, "Rule_01");
cos_str_set(&rule->status, "Enabled");
cos_str_set(&rule->prefix, "test1");
cos_str_set(&rule->dst_bucket, "qcs:id/0:cos:cn-east:appid/1253686666:replicationtest");
cos_list_add_tail(&rule->node, &replication_param->rule_list);
rule = cos_create_replication_rule_content(p);
cos_str_set(&rule->id, "Rule_02");
cos_str_set(&rule->status, "Disabled");
cos_str_set(&rule->prefix, "test2");
cos_str_set(&rule->storage_class, "Standard_IA");
cos_str_set(&rule->dst_bucket, "qcs:id/0:cos:cn-east:appid/1253686666:replicationtest");
cos_list_add_tail(&rule->node, &replication_param->rule_list);
rule = cos_create_replication_rule_content(p);
cos_str_set(&rule->id, "Rule_03");
cos_str_set(&rule->status, "Enabled");
cos_str_set(&rule->prefix, "test3");
cos_str_set(&rule->storage_class, "Standard_IA");
cos_str_set(&rule->dst_bucket, "qcs:id/0:cos:cn-east:appid/1253686666:replicationtest");
cos_list_add_tail(&rule->node, &replication_param->rule_list);
// put bucket replication
s = cos_put_bucket_replication(options, &bucket, replication_param, &resp_headers);
log_status(s);
// get bucket replication
cos_replication_params_t *replication_param2 = NULL;
replication_param2 = cos_create_replication_params(p);
s = cos_get_bucket_replication(options, &bucket, replication_param2, &resp_headers);
log_status(s);
printf("ReplicationConfiguration role: %s\n", replication_param2->role.data);
cos_replication_rule_content_t *content = NULL;
cos_list_for_each_entry(cos_replication_rule_content_t, content, &replication_param2->rule_list, node) {
printf("ReplicationConfiguration rule, id:%s, status:%s, prefix:%s, dst_bucket:%s, storage_class:%s\n",
content->id.data, content->status.data, content->prefix.data, content->dst_bucket.data,
content->storage_class.data);
}
// delete bucket replication
s = cos_delete_bucket_replication(options, &bucket, &resp_headers);
log_status(s);
// disable bucket versioning
cos_str_set(&versioning->status, "Suspended");
s = cos_put_bucket_versioning(options, &bucket, versioning, &resp_headers);
log_status(s);
s = cos_put_bucket_versioning(dst_options, &dst_bucket, versioning, &resp_headers);
log_status(s);
cos_pool_destroy(p);
}
void test_presigned_url() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t presigned_url;
cos_table_t *params = NULL;
cos_table_t *headers = NULL;
int sign_host = 1;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, TEST_OBJECT_NAME1);
cos_gen_presigned_url(options, &bucket, &object, 300, HTTP_GET, &presigned_url);
printf("presigned_url: %s\n", presigned_url.data);
// 添加您自己的params和headers
params = cos_table_make(options->pool, 0);
// cos_table_add(params, "param1", "value");
headers = cos_table_make(options->pool, 0);
// cos_table_add(headers, "header1", "value");
// 强烈建议sign_host为1,这样强制把host头域加入签名列表,防止越权访问问题
cos_gen_presigned_url_safe(options, &bucket, &object, 300, HTTP_GET, headers, params, sign_host, &presigned_url);
printf("presigned_url_safe: %s\n", presigned_url.data);
cos_pool_destroy(p);
}
void test_head_bucket() {
cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers = NULL;
//创建内存池
cos_pool_create(&pool, NULL);
//初始化请求选项
options = cos_request_options_create(pool);
options->config = cos_config_create(options->pool);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
options->ctl = cos_http_controller_create(options->pool, 0);
status = cos_head_bucket(options, &bucket, &resp_headers);
log_status(status);
cos_pool_destroy(pool);
}
void test_check_bucket_exist() {
cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers = NULL;
cos_bucket_exist_status_e bucket_exist;
//创建内存池
cos_pool_create(&pool, NULL);
//初始化请求选项
options = cos_request_options_create(pool);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
// 检查桶是否存在
status = cos_check_bucket_exist(options, &bucket, &bucket_exist, &resp_headers);
if (bucket_exist == COS_BUCKET_NON_EXIST) {
printf("bucket: %.*s non exist.\n", bucket.len, bucket.data);
} else if (bucket_exist == COS_BUCKET_EXIST) {
printf("bucket: %.*s exist.\n", bucket.len, bucket.data);
} else {
printf("bucket: %.*s unknown status.\n", bucket.len, bucket.data);
log_status(status);
}
cos_pool_destroy(pool);
}
void test_get_service() {
cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_get_service_params_t *list_params = NULL;
cos_table_t *resp_headers = NULL;
//创建内存池
cos_pool_create(&pool, NULL);
//初始化请求选项
options = cos_request_options_create(pool);
options->config = cos_config_create(options->pool);
init_test_request_options(options, is_cname);
options->ctl = cos_http_controller_create(options->pool, 0);
//创建get service参数, 默认获取全部bucket
list_params = cos_create_get_service_params(options->pool);
//若将all_region设置为0,则只根据options->config->endpoint的区域进行查询
// list_params->all_region = 0;
status = cos_get_service(options, list_params, &resp_headers);
log_status(status);
if (!cos_status_is_ok(status)) {
cos_pool_destroy(pool);
return;
}
//查看结果
cos_get_service_content_t *content = NULL;
char *line = NULL;
cos_list_for_each_entry(cos_get_service_content_t, content, &list_params->bucket_list, node) {
line = apr_psprintf(options->pool, "%.*s\t%.*s\t%.*s\n", content->bucket_name.len, content->bucket_name.data,
content->location.len, content->location.data, content->creation_date.len,
content->creation_date.data);
printf("%s", line);
}
cos_pool_destroy(pool);
}
void test_website() {
cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_website_params_t *website_params = NULL;
cos_website_params_t *website_result = NULL;
cos_website_rule_content_t *website_content = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;
//创建内存池
cos_pool_create(&pool, NULL);
//初始化请求选项
options = cos_request_options_create(pool);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
//创建website参数
website_params = cos_create_website_params(options->pool);
cos_str_set(&website_params->index, "index.html");
cos_str_set(&website_params->redirect_protocol, "https");
cos_str_set(&website_params->error_document, "Error.html");
website_content = cos_create_website_rule_content(options->pool);
cos_str_set(&website_content->condition_errcode, "404");
cos_str_set(&website_content->redirect_protocol, "https");
cos_str_set(&website_content->redirect_replace_key, "404.html");
cos_list_add_tail(&website_content->node, &website_params->rule_list);
website_content = cos_create_website_rule_content(options->pool);
cos_str_set(&website_content->condition_prefix, "docs/");
cos_str_set(&website_content->redirect_protocol, "https");
cos_str_set(&website_content->redirect_replace_key_prefix, "documents/");
cos_list_add_tail(&website_content->node, &website_params->rule_list);
website_content = cos_create_website_rule_content(options->pool);
cos_str_set(&website_content->condition_prefix, "img/");
cos_str_set(&website_content->redirect_protocol, "https");
cos_str_set(&website_content->redirect_replace_key, "demo.jpg");
cos_list_add_tail(&website_content->node, &website_params->rule_list);
status = cos_put_bucket_website(options, &bucket, website_params, &resp_headers);
log_status(status);
website_result = cos_create_website_params(options->pool);
status = cos_get_bucket_website(options, &bucket, website_result, &resp_headers);
log_status(status);
if (!cos_status_is_ok(status)) {
cos_pool_destroy(pool);
return;
}
//查看结果
cos_website_rule_content_t *content = NULL;
char *line = NULL;
line = apr_psprintf(options->pool, "%.*s\n", website_result->index.len, website_result->index.data);
printf("index: %s", line);
line = apr_psprintf(options->pool, "%.*s\n", website_result->redirect_protocol.len,
website_result->redirect_protocol.data);
printf("redirect protocol: %s", line);
line = apr_psprintf(options->pool, "%.*s\n", website_result->error_document.len, website_result->error_document.data);
printf("error document: %s", line);
cos_list_for_each_entry(cos_website_rule_content_t, content, &website_result->rule_list, node) {
line = apr_psprintf(options->pool, "%.*s\t%.*s\t%.*s\t%.*s\t%.*s\n", content->condition_errcode.len,
content->condition_errcode.data, content->condition_prefix.len, content->condition_prefix.data,
content->redirect_protocol.len, content->redirect_protocol.data,
content->redirect_replace_key.len, content->redirect_replace_key.data,
content->redirect_replace_key_prefix.len, content->redirect_replace_key_prefix.data);
printf("%s", line);
}
status = cos_delete_bucket_website(options, &bucket, &resp_headers);
log_status(status);
cos_pool_destroy(pool);
}
void test_domain() {
cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_domain_params_t *domain_params = NULL;
cos_domain_params_t *domain_result = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;
//创建内存池
cos_pool_create(&pool, NULL);
//初始化请求选项
options = cos_request_options_create(pool);
options->config = cos_config_create(options->pool);
init_test_request_options(options, is_cname);
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);
//创建domain参数
domain_params = cos_create_domain_params(options->pool);
cos_str_set(&domain_params->status, "ENABLED");
cos_str_set(&domain_params->name, "www.abc.com");
cos_str_set(&domain_params->type, "REST");
cos_str_set(&domain_params->forced_replacement, "CNAME");
status = cos_put_bucket_domain(options, &bucket, domain_params, &resp_headers);
log_status(status);
domain_result = cos_create_domain_params(options->pool);
status = cos_get_bucket_domain(options, &bucket, domain_result, &resp_headers);
log_status(status);
if (!cos_status_is_ok(status)) {
cos_pool_destroy(pool);
return;
}
//查看结果
char *line = NULL;
line = apr_psprintf(options->pool, "%.*s\n", domain_result->status.len, domain_result->status.data);
printf("status: %s", line);
line = apr_psprintf(options->pool, "%.*s\n", domain_result->name.len, domain_result->name.data);
printf("name: %s", line);
line = apr_psprintf(options->pool, "%.*s\n", domain_result->type.len, domain_result->type.data);
printf("type: %s", line);
line = apr_psprintf(options->pool, "%.*s\n", domain_result->forced_replacement.len,
domain_result->forced_replacement.data);
printf("forced_replacement: %s", line);
cos_pool_destroy(pool);
}
void test_logging() {
cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_logging_params_t *params = NULL;
cos_logging_params_t *result = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;
//创建内存池
cos_pool_create(&pool, NULL);
//初始化请求选项
options = cos_request_options_create(pool);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
//创建logging参数
params = cos_create_logging_params(options->pool);
cos_str_set(&params->target_bucket, TEST_BUCKET_NAME);
cos_str_set(&params->target_prefix, "logging/");
status = cos_put_bucket_logging(options, &bucket, params, &resp_headers);
log_status(status);
result = cos_create_logging_params(options->pool);
status = cos_get_bucket_logging(options, &bucket, result, &resp_headers);
log_status(status);
if (!cos_status_is_ok(status)) {
cos_pool_destroy(pool);
return;
}
//查看结果
char *line = NULL;
line = apr_psprintf(options->pool, "%.*s\n", result->target_bucket.len, result->target_bucket.data);
printf("target bucket: %s", line);
line = apr_psprintf(options->pool, "%.*s\n", result->target_prefix.len, result->target_prefix.data);
printf("target prefix: %s", line);
cos_pool_destroy(pool);
}
void test_inventory() {
cos_pool_t *pool = NULL;
int is_cname = 0;
int inum = 3, i, len;
char buf[inum][32];
char dest_bucket[128];
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;
cos_inventory_params_t *get_params = NULL;
cos_inventory_optional_t *optional = NULL;
cos_list_inventory_params_t *list_params = NULL;
//创建内存池
cos_pool_create(&pool, NULL);
//初始化请求选项
options = cos_request_options_create(pool);
options->config = cos_config_create(options->pool);
init_test_request_options(options, is_cname);
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);
// put bucket inventory
len = snprintf(dest_bucket, 128, "qcs::cos:%s::%s", TEST_REGION, TEST_BUCKET_NAME);
dest_bucket[len] = 0;
for (i = 0; i < inum; i++) {
cos_inventory_params_t *params = cos_create_inventory_params(pool);
cos_inventory_optional_t *optional;
len = snprintf(buf[i], 32, "id%d", i);
buf[i][len] = 0;
cos_str_set(&params->id, buf[i]);
cos_str_set(&params->is_enabled, "true");
cos_str_set(&params->frequency, "Daily");
cos_str_set(&params->filter_prefix, "myPrefix");
cos_str_set(&params->included_object_versions, "All");
cos_str_set(&params->destination.format, "CSV");
cos_str_set(&params->destination.account_id, TEST_UIN);
cos_str_set(&params->destination.bucket, dest_bucket);
cos_str_set(&params->destination.prefix, "invent");
params->destination.encryption = 1;
optional = cos_create_inventory_optional(pool);
cos_str_set(&optional->field, "Size");
cos_list_add_tail(&optional->node, &params->fields);
optional = cos_create_inventory_optional(pool);
cos_str_set(&optional->field, "LastModifiedDate");
cos_list_add_tail(&optional->node, &params->fields);
optional = cos_create_inventory_optional(pool);
cos_str_set(&optional->field, "ETag");
cos_list_add_tail(&optional->node, &params->fields);
optional = cos_create_inventory_optional(pool);
cos_str_set(&optional->field, "StorageClass");
cos_list_add_tail(&optional->node, &params->fields);
optional = cos_create_inventory_optional(pool);
cos_str_set(&optional->field, "ReplicationStatus");
cos_list_add_tail(&optional->node, &params->fields);
status = cos_put_bucket_inventory(options, &bucket, params, &resp_headers);
log_status(status);
}
// get inventory
get_params = cos_create_inventory_params(pool);
cos_str_set(&get_params->id, buf[inum / 2]);
status = cos_get_bucket_inventory(options, &bucket, get_params, &resp_headers);
log_status(status);
printf("id: %s\nis_enabled: %s\nfrequency: %s\nfilter_prefix: %s\nincluded_object_versions: %s\n",
get_params->id.data, get_params->is_enabled.data, get_params->frequency.data, get_params->filter_prefix.data,
get_params->included_object_versions.data);
printf("destination:\n");
printf("\tencryption: %d\n", get_params->destination.encryption);
printf("\tformat: %s\n", get_params->destination.format.data);
printf("\taccount_id: %s\n", get_params->destination.account_id.data);
printf("\tbucket: %s\n", get_params->destination.bucket.data);
printf("\tprefix: %s\n", get_params->destination.prefix.data);
cos_list_for_each_entry(cos_inventory_optional_t, optional, &get_params->fields, node) {
printf("field: %s\n", optional->field.data);
}
// list inventory
list_params = cos_create_list_inventory_params(pool);
status = cos_list_bucket_inventory(options, &bucket, list_params, &resp_headers);
log_status(status);
get_params = NULL;
cos_list_for_each_entry(cos_inventory_params_t, get_params, &list_params->inventorys, node) {
printf("id: %s\nis_enabled: %s\nfrequency: %s\nfilter_prefix: %s\nincluded_object_versions: %s\n",
get_params->id.data, get_params->is_enabled.data, get_params->frequency.data, get_params->filter_prefix.data,
get_params->included_object_versions.data);
printf("destination:\n");
printf("\tencryption: %d\n", get_params->destination.encryption);
printf("\tformat: %s\n", get_params->destination.format.data);
printf("\taccount_id: %s\n", get_params->destination.account_id.data);
printf("\tbucket: %s\n", get_params->destination.bucket.data);
printf("\tprefix: %s\n", get_params->destination.prefix.data);
cos_list_for_each_entry(cos_inventory_optional_t, optional, &get_params->fields, node) {
printf("field: %s\n", optional->field.data);
}
}
// delete inventory
for (i = 0; i < inum; i++) {
cos_string_t id;
cos_str_set(&id, buf[i]);
status = cos_delete_bucket_inventory(options, &bucket, &id, &resp_headers);
log_status(status);
}
cos_pool_destroy(pool);
}
void test_bucket_tagging() {
cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;
cos_tagging_params_t *params = NULL;
cos_tagging_params_t *result = NULL;
cos_tagging_tag_t *tag = NULL;
//创建内存池
cos_pool_create(&pool, NULL);
//初始化请求选项
options = cos_request_options_create(pool);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
// put tagging
params = cos_create_tagging_params(pool);
tag = cos_create_tagging_tag(pool);
cos_str_set(&tag->key, "age");
cos_str_set(&tag->value, "18");
cos_list_add_tail(&tag->node, &params->node);
tag = cos_create_tagging_tag(pool);
cos_str_set(&tag->key, "name");
cos_str_set(&tag->value, "xiaoming");
cos_list_add_tail(&tag->node, &params->node);
status = cos_put_bucket_tagging(options, &bucket, params, &resp_headers);
log_status(status);
// get tagging
result = cos_create_tagging_params(pool);
status = cos_get_bucket_tagging(options, &bucket, result, &resp_headers);
log_status(status);
tag = NULL;
cos_list_for_each_entry(cos_tagging_tag_t, tag, &result->node, node) {
printf("taging key: %s\n", tag->key.data);
printf("taging value: %s\n", tag->value.data);
}
// delete tagging
status = cos_delete_bucket_tagging(options, &bucket, &resp_headers);
log_status(status);
cos_pool_destroy(pool);
}
void test_object_tagging() {
cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t version_id = cos_string("");
cos_tagging_params_t *params = NULL;
cos_tagging_params_t *result = NULL;
cos_tagging_tag_t *tag = NULL;
//创建内存池
cos_pool_create(&pool, NULL);
//初始化请求选项
options = cos_request_options_create(pool);
options->config = cos_config_create(options->pool);
init_test_request_options(options, is_cname);
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, TEST_OBJECT_NAME1);
// put object tagging
params = cos_create_tagging_params(pool);
tag = cos_create_tagging_tag(pool);
cos_str_set(&tag->key, "age");
cos_str_set(&tag->value, "18");
cos_list_add_tail(&tag->node, &params->node);
tag = cos_create_tagging_tag(pool);
cos_str_set(&tag->key, "name");
cos_str_set(&tag->value, "xiaoming");
cos_list_add_tail(&tag->node, &params->node);
status = cos_put_object_tagging(options, &bucket, &object, &version_id, NULL, params, &resp_headers);
log_status(status);
// get object tagging
result = cos_create_tagging_params(pool);
status = cos_get_object_tagging(options, &bucket, &object, &version_id, NULL, result, &resp_headers);
log_status(status);
tag = NULL;
cos_list_for_each_entry(cos_tagging_tag_t, tag, &result->node, node) {
printf("taging key: %s\n", tag->key.data);
printf("taging value: %s\n", tag->value.data);
}
// delete tagging
status = cos_delete_object_tagging(options, &bucket, &object, &version_id, NULL, &resp_headers);
log_status(status);
cos_pool_destroy(pool);
}
static void log_get_referer(cos_referer_params_t *result) {
int index = 0;
cos_referer_domain_t *domain;
cos_warn_log("status: %s", result->status.data);
cos_warn_log("referer_type: %s", result->referer_type.data);
cos_warn_log("empty_refer_config: %s", result->empty_refer_config.data);
cos_list_for_each_entry(cos_referer_domain_t, domain, &result->domain_list, node) {
cos_warn_log("domain index:%d", ++index);
cos_warn_log("domain: %s", domain->domain.data);
}
}
void test_referer() {
cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;
cos_referer_params_t *params = NULL;
cos_referer_domain_t *domain = NULL;
cos_referer_params_t *result = NULL;
//创建内存池
cos_pool_create(&pool, NULL);
//初始化请求选项
options = cos_request_options_create(pool);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
// 替换为您的配置信息,可参见文档 https://cloud.tencent.com/document/product/436/32492
params = cos_create_referer_params(pool);
cos_str_set(&params->status, "Enabled");
cos_str_set(&params->referer_type, "White-List");
cos_str_set(&params->empty_refer_config, "Allow");
domain = cos_create_referer_domain(pool);
cos_str_set(&domain->domain, "www.qq.com");
cos_list_add_tail(&domain->node, &params->domain_list);
domain = cos_create_referer_domain(pool);
cos_str_set(&domain->domain, "*.tencent.com");
cos_list_add_tail(&domain->node, &params->domain_list);
// put referer
status = cos_put_bucket_referer(options, &bucket, params, &resp_headers);
log_status(status);
// get referer
result = cos_create_referer_params(pool);
status = cos_get_bucket_referer(options, &bucket, result, &resp_headers);
log_status(status);
if (status->code == 200) {
log_get_referer(result);
}
cos_pool_destroy(pool);
}
void test_intelligenttiering() {
cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;
cos_intelligenttiering_params_t *params = NULL;
cos_intelligenttiering_params_t *result = NULL;
//创建内存池
cos_pool_create(&pool, NULL);
//初始化请求选项
options = cos_request_options_create(pool);
options->config = cos_config_create(options->pool);
init_test_request_options(options, is_cname);
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);
// put intelligenttiering
params = cos_create_intelligenttiering_params(pool);
cos_str_set(&params->status, "Enabled");
params->days = 30;
status = cos_put_bucket_intelligenttiering(options, &bucket, params, &resp_headers);
log_status(status);
// get intelligenttiering
result = cos_create_intelligenttiering_params(pool);
status = cos_get_bucket_intelligenttiering(options, &bucket, result, &resp_headers);
log_status(status);
printf("status: %s\n", result->status.data);
printf("days: %d\n", result->days);
cos_pool_destroy(pool);
}
void test_delete_directory() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers;
int is_truncated = 1;
cos_string_t marker;
cos_list_t deleted_object_list;
int is_quiet = COS_TRUE;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
// list object (get bucket)
cos_list_object_params_t *list_params = NULL;
list_params = cos_create_list_object_params(p);
cos_str_set(&list_params->prefix, "folder/");
cos_str_set(&marker, "");
while (is_truncated) {
list_params->marker = marker;
s = cos_list_object(options, &bucket, list_params, &resp_headers);
if (!cos_status_is_ok(s)) {
printf("list object failed, req_id:%s\n", s->req_id);
break;
}
s = cos_delete_objects(options, &bucket, &list_params->object_list, is_quiet, &resp_headers, &deleted_object_list);
log_status(s);
if (!cos_status_is_ok(s)) {
printf("delete objects failed, req_id:%s\n", s->req_id);
}
is_truncated = list_params->truncated;
marker = list_params->next_marker;
}
cos_pool_destroy(p);
}
void test_list_directory() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers;
int is_truncated = 1;
cos_string_t marker;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
// list object (get bucket)
cos_list_object_params_t *list_params = NULL;
list_params = cos_create_list_object_params(p);
// prefix表示列出的object的key以prefix开始
cos_str_set(&list_params->prefix, "folder/");
// deliter表示分隔符, 设置为/表示列出当前目录下的object, 设置为空表示列出所有的object
cos_str_set(&list_params->delimiter, "/");
// 设置最大遍历出多少个对象, 一次listobject最大支持1000
list_params->max_ret = 1000;
cos_str_set(&marker, "");
while (is_truncated) {
list_params->marker = marker;
s = cos_list_object(options, &bucket, list_params, &resp_headers);
if (!cos_status_is_ok(s)) {
printf("list object failed, req_id:%s\n", s->req_id);
break;
}
// list_params->object_list 返回列出的object对象。
cos_list_object_content_t *content = NULL;
cos_list_for_each_entry(cos_list_object_content_t, content, &list_params->object_list, node) {
printf("object: %s\n", content->key.data);
}
// list_params->common_prefix_list 表示被delimiter截断的路径, 如delimter设置为/, common prefix则表示所有子目录的路径
cos_list_object_common_prefix_t *common_prefix = NULL;
cos_list_for_each_entry(cos_list_object_common_prefix_t, common_prefix, &list_params->common_prefix_list, node) {
printf("common prefix: %s\n", common_prefix->prefix.data);
}
is_truncated = list_params->truncated;
marker = list_params->next_marker;
}
cos_pool_destroy(p);
}
void test_list_all_objects() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers;
int is_truncated = 1;
cos_string_t marker;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
// list object (get bucket)
cos_list_object_params_t *list_params = NULL;
list_params = cos_create_list_object_params(p);
// 设置最大遍历出多少个对象, 一次listobject最大支持1000
list_params->max_ret = 1000;
cos_str_set(&marker, "");
while (is_truncated) {
list_params->marker = marker;
cos_list_init(&list_params->object_list);
s = cos_list_object(options, &bucket, list_params, &resp_headers);
if (!cos_status_is_ok(s)) {
printf("list object failed, req_id:%s\n", s->req_id);
break;
}
// list_params->object_list 返回列出的object对象。
cos_list_object_content_t *content = NULL;
cos_list_for_each_entry(cos_list_object_content_t, content, &list_params->object_list, node) {
printf("object: %s\n", content->key.data);
}
is_truncated = list_params->truncated;
marker = list_params->next_marker;
}
cos_pool_destroy(p);
}
void test_download_directory() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t file_name;
cos_string_t suffix = cos_string("/");
cos_table_t *resp_headers;
cos_table_t *headers = NULL;
cos_table_t *params = NULL;
int is_truncated = 1;
cos_string_t marker;
apr_status_t status;
//初始化请求选项
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
// list object (get bucket)
cos_list_object_params_t *list_params = NULL;
list_params = cos_create_list_object_params(p);
cos_str_set(&list_params->prefix, "folder/"); //替换为您自己的目录名称
cos_str_set(&marker, "");
while (is_truncated) {
list_params->marker = marker;
s = cos_list_object(options, &bucket, list_params, &resp_headers);
log_status(s);
if (!cos_status_is_ok(s)) {
printf("list object failed, req_id:%s\n", s->req_id);
break;
}
cos_list_object_content_t *content = NULL;
cos_list_for_each_entry(cos_list_object_content_t, content, &list_params->object_list, node) {
cos_str_set(&file_name, content->key.data);
if (cos_ends_with(&content->key, &suffix)) {
//如果是目录需要先创建, 0x0755权限可以自己按需修改,参考apr_file_info.h中定义
status = apr_dir_make(content->key.data, 0x0755, options->pool);
if (status != APR_SUCCESS && !APR_STATUS_IS_EEXIST(status)) {
printf("mkdir: %s failed, status: %d\n", content->key.data, status);
}
} else {
//下载对象到本地目录,这里默认下载在程序运行的当前目录
s = cos_get_object_to_file(options, &bucket, &content->key, headers, params, &file_name, &resp_headers);
if (!cos_status_is_ok(s)) {
printf("get object[%s] failed, req_id:%s\n", content->key.data, s->req_id);
}
}
}
is_truncated = list_params->truncated;
marker = list_params->next_marker;
}
//销毁内存池
cos_pool_destroy(p);
}
void test_move() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t src_object;
cos_string_t src_endpoint;
cos_table_t *resp_headers = NULL;
//创建内存池
cos_pool_create(&p, NULL);
//初始化请求选项
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
//设置对象复制
cos_str_set(&object, TEST_OBJECT_NAME1);
cos_str_set(&src_endpoint, TEST_COS_ENDPOINT);
cos_str_set(&src_object, TEST_OBJECT_NAME2);
cos_copy_object_params_t *params = NULL;
params = cos_create_copy_object_params(p);
s = cos_copy_object(options, &bucket, &src_object, &src_endpoint, &bucket, &object, NULL, params, &resp_headers);
log_status(s);
if (cos_status_is_ok(s)) {
s = cos_delete_object(options, &bucket, &src_object, &resp_headers);
log_status(s);
printf("move object succeeded\n");
} else {
printf("move object failed\n");
}
//销毁内存池
cos_pool_destroy(p);
}
// 基础图片处理
void test_ci_base_image_process() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t file;
cos_table_t *resp_headers;
cos_table_t *params = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
options->config = cos_config_create(options->pool);
cos_str_set(&options->config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&options->config->appid, TEST_APPID);
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);
params = cos_table_make(p, 1);
apr_table_addn(params, "imageMogr2/thumbnail/!50p", "");
cos_str_set(&file, "test.jpg");
cos_str_set(&object, "test.jpg");
s = cos_get_object_to_file(options, &bucket, &object, NULL, params, &file, &resp_headers);
log_status(s);
if (!cos_status_is_ok(s)) {
printf("cos_get_object_to_file fail, req_id:%s\n", s->req_id);
}
cos_pool_destroy(p);
}
// 持久化处理
void test_ci_image_process() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t file;
cos_table_t *resp_headers;
cos_table_t *headers = NULL;
ci_operation_result_t *results = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, "test.jpg");
// 云上数据处理
headers = cos_table_make(p, 1);
apr_table_addn(headers, "pic-operations",
"{\"is_pic_info\":1,\"rules\":[{\"fileid\":\"test.png\",\"rule\":\"imageView2/format/png\"}]}");
s = ci_image_process(options, &bucket, &object, headers, &resp_headers, &results);
log_status(s);
printf("origin key: %s\n", results->origin.key.data);
printf("process key: %s\n", results->object.key.data);
// 上传时处理
headers = cos_table_make(p, 1);
apr_table_addn(headers, "pic-operations",
"{\"is_pic_info\":1,\"rules\":[{\"fileid\":\"test.png\",\"rule\":\"imageView2/format/png\"}]}");
cos_str_set(&file, "test.jpg");
cos_str_set(&object, "test.jpg");
s = ci_put_object_from_file(options, &bucket, &object, &file, headers, &resp_headers, &results);
log_status(s);
printf("origin key: %s\n", results->origin.key.data);
printf("process key: %s\n", results->object.key.data);
cos_pool_destroy(p);
}
// 二维码识别
void test_ci_image_qrcode() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t file;
cos_table_t *resp_headers;
cos_table_t *headers = NULL;
ci_operation_result_t *results = NULL;
ci_qrcode_info_t *content = NULL;
ci_qrcode_result_t *result2 = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
init_test_request_options(options, is_cname);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, "test.jpg");
headers = cos_table_make(p, 1);
apr_table_addn(headers, "pic-operations",
"{\"is_pic_info\":1,\"rules\":[{\"fileid\":\"test.png\",\"rule\":\"QRcode/cover/1\"}]}");
// 上传时识别
cos_str_set(&file, "test.jpg");
cos_str_set(&object, "test.jpg");
s = ci_put_object_from_file(options, &bucket, &object, &file, headers, &resp_headers, &results);
log_status(s);
if (!cos_status_is_ok(s)) {
printf("put object failed\n");
}
printf("CodeStatus: %d\n", results->object.code_status);
cos_list_for_each_entry(ci_qrcode_info_t, content, &results->object.qrcode_info, node) {
printf("CodeUrl: %s\n", content->code_url.data);
printf("Point: %s\n", content->point[0].data);
printf("Point: %s\n", content->point[1].data);
printf("Point: %s\n", content->point[2].data);
printf("Point: %s\n", content->point[3].data);
}
// 下载时识别
s = ci_get_qrcode(options, &bucket, &object, 1, NULL, NULL, &resp_headers, &result2);
log_status(s);
if (!cos_status_is_ok(s)) {
printf("get object failed\n");
}
printf("CodeStatus: %d\n", result2->code_status);
cos_list_for_each_entry(ci_qrcode_info_t, content, &result2->qrcode_info, node) {
printf("CodeUrl: %s\n", content->code_url.data);
printf("Point: %s\n", content->point[0].data);
printf("Point: %s\n", content->point[1].data);
printf("Point: %s\n", content->point[2].data);
printf("Point: %s\n", content->point[3].data);
}
printf("ImageResult: %s\n", result2->result_image.data);
//销毁内存池
cos_pool_destroy(p);
}
// 图片压缩
void test_ci_image_compression() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t file;
cos_table_t *resp_headers;
cos_table_t *params = NULL;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
options->config = cos_config_create(options->pool);
cos_str_set(&options->config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&options->config->appid, TEST_APPID);
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);
params = cos_table_make(p, 1);
apr_table_addn(params, "imageMogr2/format/tpg", "");
cos_str_set(&object, "test.jpg");
cos_str_set(&file, "test.tpg");
s = cos_get_object_to_file(options, &bucket, &object, NULL, params, &file, &resp_headers);
log_status(s);
if (!cos_status_is_ok(s)) {
printf("cos_get_object_to_file fail, req_id:%s\n", s->req_id);
}
params = cos_table_make(p, 1);
apr_table_addn(params, "imageMogr2/format/heif", "");
cos_str_set(&file, "test.heif");
s = cos_get_object_to_file(options, &bucket, &object, NULL, params, &file, &resp_headers);
log_status(s);
if (!cos_status_is_ok(s)) {
printf("cos_get_object_to_file fail, req_id:%s\n", s->req_id);
}
}
static void log_video_auditing_result(ci_video_auditing_job_result_t *result) {
cos_warn_log("jobid: %s", result->jobs_detail.job_id.data);
cos_warn_log("state: %s", result->jobs_detail.state.data);
cos_warn_log("creation_time: %s", result->jobs_detail.creation_time.data);
}
static void log_get_auditing_result(ci_auditing_job_result_t *result) {
int index = 0;
ci_auditing_snapshot_result_t *snapshot_info;
ci_auditing_audio_section_result_t *audio_section_info;
cos_warn_log("nonexist_job_ids: %s", result->nonexist_job_ids.data);
cos_warn_log("code: %s", result->jobs_detail.code.data);
cos_warn_log("message: %s", result->jobs_detail.message.data);
cos_warn_log("state: %s", result->jobs_detail.state.data);
cos_warn_log("creation_time: %s", result->jobs_detail.creation_time.data);
cos_warn_log("object: %s", result->jobs_detail.object.data);
cos_warn_log("snapshot_count: %s", result->jobs_detail.snapshot_count.data);
cos_warn_log("result: %d", result->jobs_detail.result);
cos_warn_log("porn_info.hit_flag: %d", result->jobs_detail.porn_info.hit_flag);
cos_warn_log("porn_info.count: %d", result->jobs_detail.porn_info.count);
cos_warn_log("terrorism_info.hit_flag: %d", result->jobs_detail.terrorism_info.hit_flag);
cos_warn_log("terrorism_info.count: %d", result->jobs_detail.terrorism_info.count);
cos_warn_log("politics_info.hit_flag: %d", result->jobs_detail.politics_info.hit_flag);
cos_warn_log("politics_info.count: %d", result->jobs_detail.politics_info.count);
cos_warn_log("ads_info.hit_flag: %d", result->jobs_detail.ads_info.hit_flag);
cos_warn_log("ads_info.count: %d", result->jobs_detail.ads_info.count);
cos_list_for_each_entry(ci_auditing_snapshot_result_t, snapshot_info, &result->jobs_detail.snapshot_info_list, node) {
cos_warn_log("snapshot index:%d", ++index);
cos_warn_log("snapshot_info->url: %s", snapshot_info->url.data);
cos_warn_log("snapshot_info->snapshot_time: %d", snapshot_info->snapshot_time);
cos_warn_log("snapshot_info->text: %s", snapshot_info->text.data);
cos_warn_log("snapshot_info->porn_info.hit_flag: %d", snapshot_info->porn_info.hit_flag);
cos_warn_log("snapshot_info->porn_info.score: %d", snapshot_info->porn_info.score);
cos_warn_log("snapshot_info->porn_info.label: %s", snapshot_info->porn_info.label.data);
cos_warn_log("snapshot_info->porn_info.sub_lable: %s", snapshot_info->porn_info.sub_lable.data);
cos_warn_log("snapshot_info->terrorism_info.hit_flag: %d", snapshot_info->terrorism_info.hit_flag);
cos_warn_log("snapshot_info->terrorism_info.score: %d", snapshot_info->terrorism_info.score);
cos_warn_log("snapshot_info->terrorism_info.label: %s", snapshot_info->terrorism_info.label.data);
cos_warn_log("snapshot_info->terrorism_info.sub_lable: %s", snapshot_info->terrorism_info.sub_lable.data);
cos_warn_log("snapshot_info->politics_info.hit_flag: %d", snapshot_info->politics_info.hit_flag);
cos_warn_log("snapshot_info->politics_info.score: %d", snapshot_info->politics_info.score);
cos_warn_log("snapshot_info->politics_info.label: %s", snapshot_info->politics_info.label.data);
cos_warn_log("snapshot_info->politics_info.sub_lable: %s", snapshot_info->politics_info.sub_lable.data);
cos_warn_log("snapshot_info->ads_info.hit_flag: %d", snapshot_info->ads_info.hit_flag);
cos_warn_log("snapshot_info->ads_info.score: %d", snapshot_info->ads_info.score);
cos_warn_log("snapshot_info->ads_info.label: %s", snapshot_info->ads_info.label.data);
cos_warn_log("snapshot_info->ads_info.sub_lable: %s", snapshot_info->ads_info.sub_lable.data);
}
index = 0;
cos_list_for_each_entry(ci_auditing_audio_section_result_t, audio_section_info,
&result->jobs_detail.audio_section_info_list, node) {
cos_warn_log("audio_section index:%d", ++index);
cos_warn_log("audio_section_info->url: %s", audio_section_info->url.data);
cos_warn_log("audio_section_info->text: %s", audio_section_info->text.data);
cos_warn_log("audio_section_info->offset_time: %d", audio_section_info->offset_time);
cos_warn_log("audio_section_info->duration: %d", audio_section_info->duration);
cos_warn_log("audio_section_info->porn_info.hit_flag: %d", audio_section_info->porn_info.hit_flag);
cos_warn_log("audio_section_info->porn_info.score: %d", audio_section_info->porn_info.score);
cos_warn_log("audio_section_info->porn_info.key_words: %s", audio_section_info->porn_info.key_words.data);
cos_warn_log("audio_section_info->terrorism_info.hit_flag: %d", audio_section_info->terrorism_info.hit_flag);
cos_warn_log("audio_section_info->terrorism_info.score: %d", audio_section_info->terrorism_info.score);
cos_warn_log("audio_section_info->terrorism_info.key_words: %s", audio_section_info->terrorism_info.key_words.data);
cos_warn_log("audio_section_info->politics_info.hit_flag: %d", audio_section_info->politics_info.hit_flag);
cos_warn_log("audio_section_info->politics_info.score: %d", audio_section_info->politics_info.score);
cos_warn_log("audio_section_info->politics_info.key_words: %s", audio_section_info->politics_info.key_words.data);
cos_warn_log("audio_section_info->ads_info.hit_flag: %d", audio_section_info->ads_info.hit_flag);
cos_warn_log("audio_section_info->ads_info.score: %d", audio_section_info->ads_info.score);
cos_warn_log("audio_section_info->ads_info.key_words: %s", audio_section_info->ads_info.key_words.data);
}
}
static void log_media_buckets_result(ci_media_buckets_result_t *result) {
int index = 0;
ci_media_bucket_list_t *media_bucket;
cos_warn_log("total_count: %d", result->total_count);
cos_warn_log("page_number: %d", result->page_number);
cos_warn_log("page_size: %d", result->page_size);
cos_list_for_each_entry(ci_media_bucket_list_t, media_bucket, &result->media_bucket_list, node) {
cos_warn_log("media_bucket index:%d", ++index);
cos_warn_log("media_bucket->bucket_id: %s", media_bucket->bucket_id.data);
cos_warn_log("media_bucket->name: %s", media_bucket->name.data);
cos_warn_log("media_bucket->region: %s", media_bucket->region.data);
cos_warn_log("media_bucket->create_time: %s", media_bucket->create_time.data);
}
}
static void log_media_info_result(ci_media_info_result_t *result) {
// format
cos_warn_log("format.num_stream: %d", result->format.num_stream);
cos_warn_log("format.num_program: %d", result->format.num_program);
cos_warn_log("format.format_name: %s", result->format.format_name.data);
cos_warn_log("format.format_long_name: %s", result->format.format_long_name.data);
cos_warn_log("format.start_time: %f", result->format.start_time);
cos_warn_log("format.duration: %f", result->format.duration);
cos_warn_log("format.bit_rate: %d", result->format.bit_rate);
cos_warn_log("format.size: %d", result->format.size);
// stream.video
cos_warn_log("stream.video.index: %d", result->stream.video.index);
cos_warn_log("stream.video.codec_name: %s", result->stream.video.codec_name.data);
cos_warn_log("stream.video.codec_long_name: %s", result->stream.video.codec_long_name.data);
cos_warn_log("stream.video.codec_time_base: %s", result->stream.video.codec_time_base.data);
cos_warn_log("stream.video.codec_tag_string: %s", result->stream.video.codec_tag_string.data);
cos_warn_log("stream.video.codec_tag: %s", result->stream.video.codec_tag.data);
cos_warn_log("stream.video.profile: %s", result->stream.video.profile.data);
cos_warn_log("stream.video.height: %d", result->stream.video.height);
cos_warn_log("stream.video.width: %d", result->stream.video.width);
cos_warn_log("stream.video.has_b_frame: %d", result->stream.video.has_b_frame);
cos_warn_log("stream.video.ref_frames: %d", result->stream.video.ref_frames);
cos_warn_log("stream.video.sar: %s", result->stream.video.sar.data);
cos_warn_log("stream.video.dar: %s", result->stream.video.dar.data);
cos_warn_log("stream.video.pix_format: %s", result->stream.video.pix_format.data);
cos_warn_log("stream.video.field_order: %s", result->stream.video.field_order.data);
cos_warn_log("stream.video.level: %d", result->stream.video.level);
cos_warn_log("stream.video.fps: %d", result->stream.video.fps);
cos_warn_log("stream.video.avg_fps: %s", result->stream.video.avg_fps.data);
cos_warn_log("stream.video.timebase: %s", result->stream.video.timebase.data);
cos_warn_log("stream.video.start_time: %f", result->stream.video.start_time);
cos_warn_log("stream.video.duration: %f", result->stream.video.duration);
cos_warn_log("stream.video.bit_rate: %f", result->stream.video.bit_rate);
cos_warn_log("stream.video.num_frames: %d", result->stream.video.num_frames);
cos_warn_log("stream.video.language: %s", result->stream.video.language.data);
// stream.audio
cos_warn_log("stream.audio.index: %d", result->stream.audio.index);
cos_warn_log("stream.audio.codec_name: %s", result->stream.audio.codec_name.data);
cos_warn_log("stream.audio.codec_long_name: %s", result->stream.audio.codec_long_name.data);
cos_warn_log("stream.audio.codec_time_base: %s", result->stream.audio.codec_time_base.data);
cos_warn_log("stream.audio.codec_tag_string: %s", result->stream.audio.codec_tag_string.data);
cos_warn_log("stream.audio.codec_tag: %s", result->stream.audio.codec_tag.data);
cos_warn_log("stream.audio.sample_fmt: %s", result->stream.audio.sample_fmt.data);
cos_warn_log("stream.audio.sample_rate: %d", result->stream.audio.sample_rate);
cos_warn_log("stream.audio.channel: %d", result->stream.audio.channel);
cos_warn_log("stream.audio.channel_layout: %s", result->stream.audio.channel_layout.data);
cos_warn_log("stream.audio.timebase: %s", result->stream.audio.timebase.data);
cos_warn_log("stream.audio.start_time: %f", result->stream.audio.start_time);
cos_warn_log("stream.audio.duration: %f", result->stream.audio.duration);
cos_warn_log("stream.audio.bit_rate: %f", result->stream.audio.bit_rate);
cos_warn_log("stream.audio.language: %s", result->stream.audio.language.data);
// stream.subtitle
cos_warn_log("stream.subtitle.index: %d", result->stream.subtitle.index);
cos_warn_log("stream.subtitle.language: %s", result->stream.subtitle.language.data);
}
void test_ci_video_auditing() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers;
ci_video_auditing_job_options_t *job_options;
ci_video_auditing_job_result_t *job_result;
ci_auditing_job_result_t *auditing_result;
// 基本配置
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
options->config = cos_config_create(options->pool);
cos_str_set(&options->config->endpoint, TEST_CI_ENDPOINT); // https://ci.<Region>.myqcloud.com
cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&options->config->appid, TEST_APPID);
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);
// 替换为您的配置信息,可参见文档 https://cloud.tencent.com/document/product/436/47316
job_options = ci_video_auditing_job_options_create(p);
cos_str_set(&job_options->input_object, "test.mp4");
cos_str_set(&job_options->job_conf.detect_type, "Porn,Terrorism,Politics,Ads");
cos_str_set(&job_options->job_conf.callback_version, "Detail");
job_options->job_conf.detect_content = 1;
cos_str_set(&job_options->job_conf.snapshot.mode, "Interval");
job_options->job_conf.snapshot.time_interval = 1.5;
job_options->job_conf.snapshot.count = 10;
// 提交一个视频审核任务
s = ci_create_video_auditing_job(options, &bucket, job_options, NULL, &resp_headers, &job_result);
log_status(s);
if (s->code == 200) {
log_video_auditing_result(job_result);
}
// 等待视频审核任务完成,此处可修改您的等待时间
sleep(300);
// 获取审核任务结果
s = ci_get_auditing_job(options, &bucket, &job_result->jobs_detail.job_id, NULL, &resp_headers, &auditing_result);
log_status(s);
if (s->code == 200) {
log_get_auditing_result(auditing_result);
}
// 销毁内存池
cos_pool_destroy(p);
}
void test_ci_media_process_media_bucket() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_table_t *resp_headers;
ci_media_buckets_request_t *media_buckets_request;
ci_media_buckets_result_t *media_buckets_result;
// 基本配置
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
options->config = cos_config_create(options->pool);
cos_str_set(&options->config->endpoint, TEST_CI_ENDPOINT); // https://ci.<Region>.myqcloud.com
cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&options->config->appid, TEST_APPID);
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
// 替换为您的配置信息,可参见文档 https://cloud.tencent.com/document/product/436/48988
media_buckets_request = ci_media_buckets_request_create(p);
cos_str_set(&media_buckets_request->regions, "");
cos_str_set(&media_buckets_request->bucket_names, "");
cos_str_set(&media_buckets_request->bucket_name, "");
cos_str_set(&media_buckets_request->page_number, "1");
cos_str_set(&media_buckets_request->page_size, "10");
s = ci_describe_media_buckets(options, media_buckets_request, NULL, &resp_headers, &media_buckets_result);
log_status(s);
if (s->code == 200) {
log_media_buckets_result(media_buckets_result);
}
// 销毁内存池
cos_pool_destroy(p);
}
void test_ci_media_process_snapshot() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers;
cos_list_t download_buffer;
cos_string_t object;
ci_get_snapshot_request_t *snapshot_request;
cos_buf_t *content = NULL;
cos_string_t pic_file = cos_string("snapshot.jpg");
// 基本配置
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
options->config = cos_config_create(options->pool);
cos_str_set(&options->config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&options->config->appid, TEST_APPID);
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, "test.mp4");
// 替换为您的配置信息,可参见文档 https://cloud.tencent.com/document/product/436/55671
snapshot_request = ci_snapshot_request_create(p);
snapshot_request->time = 7.5;
snapshot_request->width = 0;
snapshot_request->height = 0;
cos_str_set(&snapshot_request->format, "jpg");
cos_str_set(&snapshot_request->rotate, "auto");
cos_str_set(&snapshot_request->mode, "exactframe");
cos_list_init(&download_buffer);
s = ci_get_snapshot_to_buffer(options, &bucket, &object, snapshot_request, NULL, &download_buffer, &resp_headers);
log_status(s);
int64_t len = 0;
int64_t size = 0;
int64_t pos = 0;
cos_list_for_each_entry(cos_buf_t, content, &download_buffer, node) { len += cos_buf_size(content); }
char *buf = cos_pcalloc(p, (apr_size_t)(len + 1));
buf[len] = '\0';
cos_list_for_each_entry(cos_buf_t, content, &download_buffer, node) {
size = cos_buf_size(content);
memcpy(buf + pos, content->pos, (size_t)size);
pos += size;
}
cos_warn_log("Download len:%ld data=%s", len, buf);
s = ci_get_snapshot_to_file(options, &bucket, &object, snapshot_request, NULL, &pic_file, &resp_headers);
log_status(s);
// 销毁内存池
cos_pool_destroy(p);
}
void test_ci_media_process_media_info() {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_table_t *resp_headers;
ci_media_info_result_t *media_info;
cos_string_t object;
// 基本配置
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
options->config = cos_config_create(options->pool);
cos_str_set(&options->config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&options->config->appid, TEST_APPID);
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);
cos_str_set(&object, "test.mp4");
// 替换为您的配置信息,可参见文档 https://cloud.tencent.com/document/product/436/55672
s = ci_get_media_info(options, &bucket, &object, NULL, &resp_headers, &media_info);
log_status(s);
if (s->code == 200) {
log_media_info_result(media_info);
}
// 销毁内存池
cos_pool_destroy(p);
}
int main(int argc, char *argv[]) {
// 通过环境变量获取 SECRETID 和 SECRETKEY
// TEST_ACCESS_KEY_ID = getenv("COS_SECRETID");
// TEST_ACCESS_KEY_SECRET = getenv("COS_SECRETKEY");
if (cos_http_io_initialize(NULL, 0) != COSE_OK) {
exit(1);
}
// set log level, default COS_LOG_WARN
cos_log_set_level(COS_LOG_WARN);
// set log output, default stderr
cos_log_set_output(NULL);
// test_intelligenttiering();
// test_bucket_tagging();
// test_object_tagging();
// test_referer();
// test_logging();
// test_inventory();
// test_put_object_from_file_with_sse();
// test_get_object_to_file_with_sse();
// test_head_bucket();
// test_check_bucket_exist();
// test_get_service();
// test_website();
// test_domain();
// test_delete_objects();
// test_delete_objects_by_prefix();
// test_bucket();
// test_bucket_lifecycle();
// test_object_restore();
test_put_object_from_file();
// test_sign();
// test_object();
// test_put_object_with_limit();
// test_get_object_with_limit();
test_head_object();
// test_gen_object_url();
// test_list_objects();
// test_list_directory();
// test_list_all_objects();
// test_create_dir();
// test_append_object();
// test_check_object_exist();
// multipart_upload_file_from_file();
// multipart_upload_file_from_buffer();
// abort_multipart_upload();
// list_multipart();
// pthread_t tid[20];
// test_resumable_upload_with_multi_threads();
// test_resumable();
// test_bucket();
// test_acl();
// test_copy();
// test_modify_storage_class();
// test_cors();
// test_versioning();
// test_replication();
// test_part_copy();
// test_copy_with_part_copy();
// test_move();
// test_delete_directory();
// test_download_directory();
// test_presigned_url();
// test_ci_base_image_process();
// test_ci_image_process();
// test_ci_image_qrcode();
// test_ci_image_compression();
// test_ci_video_auditing();
// test_ci_media_process_media_bucket();
// test_ci_media_process_snapshot();
// test_ci_media_process_media_info();
// cos_http_io_deinitialize last
cos_http_io_deinitialize();
return 0;
}
...@@ -76,7 +76,7 @@ int32_t taosUnLockFile(TdFilePtr pFile); ...@@ -76,7 +76,7 @@ int32_t taosUnLockFile(TdFilePtr pFile);
int32_t taosUmaskFile(int32_t maskVal); int32_t taosUmaskFile(int32_t maskVal);
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime); int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime, int32_t *atime);
int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno); int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno);
int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime); int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime);
bool taosCheckExistFile(const char *pathname); bool taosCheckExistFile(const char *pathname);
......
...@@ -16,6 +16,14 @@ ENDIF () ...@@ -16,6 +16,14 @@ ENDIF ()
IF (TD_STORAGE) IF (TD_STORAGE)
ADD_DEFINITIONS(-D_STORAGE) ADD_DEFINITIONS(-D_STORAGE)
TARGET_LINK_LIBRARIES(common PRIVATE storage) TARGET_LINK_LIBRARIES(common PRIVATE storage)
IF(${TD_LINUX})
IF(${BUILD_WITH_COS})
add_definitions(-DUSE_COS)
ENDIF(${BUILD_WITH_COS})
ENDIF(${TD_LINUX})
ENDIF () ENDIF ()
target_include_directories( target_include_directories(
......
...@@ -237,6 +237,14 @@ int64_t tsCheckpointInterval = 3 * 60 * 60 * 1000; ...@@ -237,6 +237,14 @@ int64_t tsCheckpointInterval = 3 * 60 * 60 * 1000;
bool tsFilterScalarMode = false; bool tsFilterScalarMode = false;
int32_t tsKeepTimeOffset = 0; // latency of data migration int32_t tsKeepTimeOffset = 0; // latency of data migration
char tsS3Endpoint[TSDB_FQDN_LEN] = "<endpoint>";
char tsS3AccessKey[TSDB_FQDN_LEN] = "<accesskey>";
char tsS3AccessKeyId[TSDB_FQDN_LEN] = "<accesskeyid>";
char tsS3AccessKeySecret[TSDB_FQDN_LEN] = "<accesskeysecrect>";
char tsS3BucketName[TSDB_FQDN_LEN] = "<bucketname>";
char tsS3AppId[TSDB_FQDN_LEN] = "<appid>";
int8_t tsS3Enabled = false;
#ifndef _STORAGE #ifndef _STORAGE
int32_t taosSetTfsCfg(SConfig *pCfg) { int32_t taosSetTfsCfg(SConfig *pCfg) {
SConfigItem *pItem = cfgGetItem(pCfg, "dataDir"); SConfigItem *pItem = cfgGetItem(pCfg, "dataDir");
...@@ -258,7 +266,43 @@ int32_t taosSetTfsCfg(SConfig *pCfg) { ...@@ -258,7 +266,43 @@ int32_t taosSetTfsCfg(SConfig *pCfg) {
int32_t taosSetTfsCfg(SConfig *pCfg); int32_t taosSetTfsCfg(SConfig *pCfg);
#endif #endif
struct SConfig *taosGetCfg() { return tsCfg; } int32_t taosSetS3Cfg(SConfig *pCfg) {
tstrncpy(tsS3AccessKey, cfgGetItem(pCfg, "s3Accesskey")->str, TSDB_FQDN_LEN);
if (tsS3AccessKey[0] == '<') {
return 0;
}
char *colon = strchr(tsS3AccessKey, ':');
if (!colon) {
uError("invalid access key:%s", tsS3AccessKey);
return -1;
}
*colon = '\0';
tstrncpy(tsS3AccessKeyId, tsS3AccessKey, TSDB_FQDN_LEN);
tstrncpy(tsS3AccessKeySecret, colon + 1, TSDB_FQDN_LEN);
tstrncpy(tsS3Endpoint, cfgGetItem(pCfg, "s3Endpoint")->str, TSDB_FQDN_LEN);
tstrncpy(tsS3BucketName, cfgGetItem(pCfg, "s3BucketName")->str, TSDB_FQDN_LEN);
char *cos = strstr(tsS3Endpoint, "cos.");
if (cos) {
char *appid = strrchr(tsS3BucketName, '-');
if (!appid) {
uError("failed to locate appid in bucket:%s", tsS3BucketName);
return -1;
} else {
tstrncpy(tsS3AppId, appid + 1, TSDB_FQDN_LEN);
}
}
if (tsS3BucketName[0] != '<' && tsDiskCfgNum > 1) {
#ifdef USE_COS
tsS3Enabled = true;
#endif
}
return 0;
}
struct SConfig *taosGetCfg() {
return tsCfg;
}
static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile, static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile,
char *apolloUrl) { char *apolloUrl) {
...@@ -581,6 +625,10 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { ...@@ -581,6 +625,10 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
if (cfgAddInt32(pCfg, "maxStreamBackendCache", tsMaxStreamBackendCache, 16, 1024, CFG_SCOPE_SERVER) != 0) return -1; if (cfgAddInt32(pCfg, "maxStreamBackendCache", tsMaxStreamBackendCache, 16, 1024, CFG_SCOPE_SERVER) != 0) return -1;
if (cfgAddInt32(pCfg, "pqSortMemThreshold", tsPQSortMemThreshold, 1, 10240, CFG_SCOPE_SERVER) != 0) return -1; if (cfgAddInt32(pCfg, "pqSortMemThreshold", tsPQSortMemThreshold, 1, 10240, CFG_SCOPE_SERVER) != 0) return -1;
if (cfgAddString(pCfg, "s3Accesskey", tsS3AccessKey, CFG_SCOPE_SERVER) != 0) return -1;
if (cfgAddString(pCfg, "s3Endpoint", tsS3Endpoint, CFG_SCOPE_SERVER) != 0) return -1;
if (cfgAddString(pCfg, "s3BucketName", tsS3BucketName, CFG_SCOPE_SERVER) != 0) return -1;
GRANT_CFG_ADD; GRANT_CFG_ADD;
return 0; return 0;
} }
...@@ -1502,6 +1550,7 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile ...@@ -1502,6 +1550,7 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile
if (taosSetServerCfg(tsCfg)) return -1; if (taosSetServerCfg(tsCfg)) return -1;
if (taosSetReleaseCfg(tsCfg)) return -1; if (taosSetReleaseCfg(tsCfg)) return -1;
if (taosSetTfsCfg(tsCfg) != 0) return -1; if (taosSetTfsCfg(tsCfg) != 0) return -1;
if (taosSetS3Cfg(tsCfg) != 0) return -1;
} }
taosSetSystemCfg(tsCfg); taosSetSystemCfg(tsCfg);
......
...@@ -46,7 +46,7 @@ static int32_t mmDecodeOption(SJson *pJson, SMnodeOpt *pOption) { ...@@ -46,7 +46,7 @@ static int32_t mmDecodeOption(SJson *pJson, SMnodeOpt *pOption) {
if (code < 0) return -1; if (code < 0) return -1;
tjsonGetInt32ValueFromDouble(replica, "role", pOption->nodeRoles[i], code); tjsonGetInt32ValueFromDouble(replica, "role", pOption->nodeRoles[i], code);
if (code < 0) return -1; if (code < 0) return -1;
if(pOption->nodeRoles[i] == TAOS_SYNC_ROLE_VOTER){ if (pOption->nodeRoles[i] == TAOS_SYNC_ROLE_VOTER) {
pOption->numOfReplicas++; pOption->numOfReplicas++;
} }
} }
...@@ -65,7 +65,7 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) { ...@@ -65,7 +65,7 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
char file[PATH_MAX] = {0}; char file[PATH_MAX] = {0};
snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP); snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP);
if (taosStatFile(file, NULL, NULL) < 0) { if (taosStatFile(file, NULL, NULL, NULL) < 0) {
dInfo("mnode file:%s not exist", file); dInfo("mnode file:%s not exist", file);
return 0; return 0;
} }
......
...@@ -97,7 +97,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t ...@@ -97,7 +97,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
SWrapperCfg *pCfgs = NULL; SWrapperCfg *pCfgs = NULL;
snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP); snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
if (taosStatFile(file, NULL, NULL) < 0) { if (taosStatFile(file, NULL, NULL, NULL) < 0) {
dInfo("vnode file:%s not exist", file); dInfo("vnode file:%s not exist", file);
return 0; return 0;
} }
......
...@@ -100,7 +100,7 @@ int32_t dmReadEps(SDnodeData *pData) { ...@@ -100,7 +100,7 @@ int32_t dmReadEps(SDnodeData *pData) {
goto _OVER; goto _OVER;
} }
if (taosStatFile(file, NULL, NULL) < 0) { if (taosStatFile(file, NULL, NULL, NULL) < 0) {
dInfo("dnode file:%s not exist", file); dInfo("dnode file:%s not exist", file);
code = 0; code = 0;
goto _OVER; goto _OVER;
...@@ -350,7 +350,7 @@ void dmRotateMnodeEpSet(SDnodeData *pData) { ...@@ -350,7 +350,7 @@ void dmRotateMnodeEpSet(SDnodeData *pData) {
} }
void dmGetMnodeEpSetForRedirect(SDnodeData *pData, SRpcMsg *pMsg, SEpSet *pEpSet) { void dmGetMnodeEpSetForRedirect(SDnodeData *pData, SRpcMsg *pMsg, SEpSet *pEpSet) {
if(!pData->validMnodeEps) return; if (!pData->validMnodeEps) return;
dmGetMnodeEpSet(pData, pEpSet); dmGetMnodeEpSet(pData, pEpSet);
dTrace("msg is redirected, handle:%p num:%d use:%d", pMsg->info.handle, pEpSet->numOfEps, pEpSet->inUse); dTrace("msg is redirected, handle:%p num:%d use:%d", pMsg->info.handle, pEpSet->numOfEps, pEpSet->inUse);
for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { for (int32_t i = 0; i < pEpSet->numOfEps; ++i) {
...@@ -469,7 +469,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) { ...@@ -469,7 +469,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
char file[PATH_MAX] = {0}; char file[PATH_MAX] = {0};
snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP); snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
if (taosStatFile(file, NULL, NULL) < 0) { if (taosStatFile(file, NULL, NULL, NULL) < 0) {
dDebug("dnode file:%s not exist", file); dDebug("dnode file:%s not exist", file);
code = 0; code = 0;
goto _OVER; goto _OVER;
......
...@@ -38,7 +38,7 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) { ...@@ -38,7 +38,7 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
char file[PATH_MAX] = {0}; char file[PATH_MAX] = {0};
snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name); snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
if (taosStatFile(file, NULL, NULL) < 0) { if (taosStatFile(file, NULL, NULL, NULL) < 0) {
dInfo("file:%s not exist", file); dInfo("file:%s not exist", file);
code = 0; code = 0;
goto _OVER; goto _OVER;
......
...@@ -8,6 +8,7 @@ set( ...@@ -8,6 +8,7 @@ set(
"src/vnd/vnodeCommit.c" "src/vnd/vnodeCommit.c"
"src/vnd/vnodeQuery.c" "src/vnd/vnodeQuery.c"
"src/vnd/vnodeModule.c" "src/vnd/vnodeModule.c"
"src/vnd/vnodeCos.c"
"src/vnd/vnodeSvr.c" "src/vnd/vnodeSvr.c"
"src/vnd/vnodeSync.c" "src/vnd/vnodeSync.c"
"src/vnd/vnodeSnapshot.c" "src/vnd/vnodeSnapshot.c"
...@@ -155,6 +156,45 @@ target_link_libraries( ...@@ -155,6 +156,45 @@ target_link_libraries(
PUBLIC index PUBLIC index
) )
if(${TD_LINUX})
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"
)
if(${BUILD_WITH_COS})
add_definitions(-DUSE_COS)
endif(${BUILD_WITH_COS})
endif(${TD_LINUX})
IF (TD_GRANT) IF (TD_GRANT)
TARGET_LINK_LIBRARIES(vnode PUBLIC grant) TARGET_LINK_LIBRARIES(vnode PUBLIC grant)
ENDIF () ENDIF ()
...@@ -169,8 +209,6 @@ if(${BUILD_WITH_ROCKSDB}) ...@@ -169,8 +209,6 @@ if(${BUILD_WITH_ROCKSDB})
add_definitions(-DUSE_ROCKSDB) add_definitions(-DUSE_ROCKSDB)
endif(${BUILD_WITH_ROCKSDB}) endif(${BUILD_WITH_ROCKSDB})
if(${BUILD_TEST}) if(${BUILD_TEST})
add_subdirectory(test) add_subdirectory(test)
endif(${BUILD_TEST}) endif(${BUILD_TEST})
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_VND_COS_H_
#define _TD_VND_COS_H_
#include "vnd.h"
#ifdef __cplusplus
extern "C" {
#endif
extern int8_t tsS3Enabled;
int32_t s3Init();
void s3CleanUp();
int32_t s3PutObjectFromFile(const char *file, const char *object);
void s3DeleteObjects(const char *object_name[], int nobject);
bool s3Exists(const char *object_name);
bool s3Get(const char *object_name, const char *path);
void s3EvictCache(const char *path, long object_size);
long s3Size(const char *object_name);
#ifdef __cplusplus
}
#endif
#endif /*_TD_VND_COS_H_*/
...@@ -60,7 +60,7 @@ int32_t tqOffsetSnapRead(STqOffsetReader* pReader, uint8_t** ppData) { ...@@ -60,7 +60,7 @@ int32_t tqOffsetSnapRead(STqOffsetReader* pReader, uint8_t** ppData) {
} }
int64_t sz = 0; int64_t sz = 0;
if (taosStatFile(fname, &sz, NULL) < 0) { if (taosStatFile(fname, &sz, NULL, NULL) < 0) {
taosCloseFile(&pFile); taosCloseFile(&pFile);
taosMemoryFree(fname); taosMemoryFree(fname);
return -1; return -1;
......
...@@ -176,7 +176,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { ...@@ -176,7 +176,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
// SDelFile // SDelFile
if (pTsdb->fs.pDelFile) { if (pTsdb->fs.pDelFile) {
tsdbDelFileName(pTsdb, pTsdb->fs.pDelFile, fname); tsdbDelFileName(pTsdb, pTsdb->fs.pDelFile, fname);
if (taosStatFile(fname, &size, NULL)) { if (taosStatFile(fname, &size, NULL, NULL)) {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
...@@ -195,7 +195,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { ...@@ -195,7 +195,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
// head ========= // head =========
tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname); tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname);
if (taosStatFile(fname, &size, NULL)) { if (taosStatFile(fname, &size, NULL, NULL)) {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
...@@ -206,7 +206,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { ...@@ -206,7 +206,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
// data ========= // data =========
tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname); tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname);
if (taosStatFile(fname, &size, NULL)) { if (taosStatFile(fname, &size, NULL, NULL)) {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
...@@ -221,7 +221,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { ...@@ -221,7 +221,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
// sma ============= // sma =============
tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname); tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname);
if (taosStatFile(fname, &size, NULL)) { if (taosStatFile(fname, &size, NULL, NULL)) {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
...@@ -237,7 +237,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { ...@@ -237,7 +237,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
// stt =========== // stt ===========
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) { for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname); tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname);
if (taosStatFile(fname, &size, NULL)) { if (taosStatFile(fname, &size, NULL, NULL)) {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#include "tsdb.h" #include "tsdb.h"
#include "vndCos.h"
// =============== PAGE-WISE FILE =============== // =============== PAGE-WISE FILE ===============
int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsdbFD **ppFD) { int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsdbFD **ppFD) {
...@@ -34,10 +35,25 @@ int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsdbFD **p ...@@ -34,10 +35,25 @@ int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsdbFD **p
pFD->flag = flag; pFD->flag = flag;
pFD->pFD = taosOpenFile(path, flag); pFD->pFD = taosOpenFile(path, flag);
if (pFD->pFD == NULL) { if (pFD->pFD == NULL) {
const char *object_name = taosDirEntryBaseName((char *)path);
long s3_size = s3Size(object_name);
if (!strncmp(path + strlen(path) - 5, ".data", 5) && s3_size > 0) {
s3EvictCache(path, s3_size);
s3Get(object_name, path);
pFD->pFD = taosOpenFile(path, flag);
if (pFD->pFD == NULL) {
code = TAOS_SYSTEM_ERROR(errno);
taosMemoryFree(pFD);
goto _exit;
}
} else {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
taosMemoryFree(pFD); taosMemoryFree(pFD);
goto _exit; goto _exit;
} }
}
pFD->szPage = szPage; pFD->szPage = szPage;
pFD->pgno = 0; pFD->pgno = 0;
pFD->pBuf = taosMemoryCalloc(1, szPage); pFD->pBuf = taosMemoryCalloc(1, szPage);
...@@ -50,7 +66,7 @@ int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsdbFD **p ...@@ -50,7 +66,7 @@ int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsdbFD **p
// not check file size when reading data files. // not check file size when reading data files.
if (flag != TD_FILE_READ) { if (flag != TD_FILE_READ) {
if (taosStatFile(path, &pFD->szFile, NULL) < 0) { if (taosStatFile(path, &pFD->szFile, NULL, NULL) < 0) {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
taosMemoryFree(pFD->pBuf); taosMemoryFree(pFD->pBuf);
taosCloseFile(&pFD->pFD); taosCloseFile(&pFD->pFD);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "tsdb.h" #include "tsdb.h"
#include "tsdbFS2.h" #include "tsdbFS2.h"
#include "vndCos.h"
typedef struct { typedef struct {
STsdb *tsdb; STsdb *tsdb;
...@@ -41,6 +42,28 @@ static int32_t tsdbDoRemoveFileObject(SRTNer *rtner, const STFileObj *fobj) { ...@@ -41,6 +42,28 @@ static int32_t tsdbDoRemoveFileObject(SRTNer *rtner, const STFileObj *fobj) {
return TARRAY2_APPEND(rtner->fopArr, op); return TARRAY2_APPEND(rtner->fopArr, op);
} }
static int32_t tsdbRemoveFileObjectS3(SRTNer *rtner, const STFileObj *fobj) {
int32_t code = 0, lino = 0;
STFileOp op = {
.optype = TSDB_FOP_REMOVE,
.fid = fobj->f->fid,
.of = fobj->f[0],
};
code = TARRAY2_APPEND(rtner->fopArr, op);
TSDB_CHECK_CODE(code, lino, _exit);
const char *object_name = taosDirEntryBaseName((char *)fobj->fname);
s3DeleteObjects(&object_name, 1);
_exit:
if (code) {
TSDB_ERROR_LOG(TD_VID(rtner->tsdb->pVnode), lino, code);
}
return code;
}
static int32_t tsdbDoCopyFile(SRTNer *rtner, const STFileObj *from, const STFile *to) { static int32_t tsdbDoCopyFile(SRTNer *rtner, const STFileObj *from, const STFile *to) {
int32_t code = 0; int32_t code = 0;
int32_t lino = 0; int32_t lino = 0;
...@@ -76,6 +99,34 @@ _exit: ...@@ -76,6 +99,34 @@ _exit:
return code; return code;
} }
static int32_t tsdbCopyFileS3(SRTNer *rtner, const STFileObj *from, const STFile *to) {
int32_t code = 0;
int32_t lino = 0;
char fname[TSDB_FILENAME_LEN];
TdFilePtr fdFrom = NULL;
TdFilePtr fdTo = NULL;
tsdbTFileName(rtner->tsdb, to, fname);
fdFrom = taosOpenFile(from->fname, TD_FILE_READ);
if (fdFrom == NULL) code = terrno;
TSDB_CHECK_CODE(code, lino, _exit);
char *object_name = taosDirEntryBaseName(fname);
code = s3PutObjectFromFile(from->fname, object_name);
TSDB_CHECK_CODE(code, lino, _exit);
taosCloseFile(&fdFrom);
_exit:
if (code) {
TSDB_ERROR_LOG(TD_VID(rtner->tsdb->pVnode), lino, code);
taosCloseFile(&fdFrom);
}
return code;
}
static int32_t tsdbDoMigrateFileObj(SRTNer *rtner, const STFileObj *fobj, const SDiskID *did) { static int32_t tsdbDoMigrateFileObj(SRTNer *rtner, const STFileObj *fobj, const SDiskID *did) {
int32_t code = 0; int32_t code = 0;
int32_t lino = 0; int32_t lino = 0;
...@@ -123,6 +174,53 @@ _exit: ...@@ -123,6 +174,53 @@ _exit:
return code; return code;
} }
static int32_t tsdbMigrateDataFileS3(SRTNer *rtner, const STFileObj *fobj, const SDiskID *did) {
int32_t code = 0;
int32_t lino = 0;
STFileOp op = {0};
// remove old
op = (STFileOp){
.optype = TSDB_FOP_REMOVE,
.fid = fobj->f->fid,
.of = fobj->f[0],
};
code = TARRAY2_APPEND(rtner->fopArr, op);
TSDB_CHECK_CODE(code, lino, _exit);
// create new
op = (STFileOp){
.optype = TSDB_FOP_CREATE,
.fid = fobj->f->fid,
.nf =
{
.type = fobj->f->type,
.did = did[0],
.fid = fobj->f->fid,
.cid = fobj->f->cid,
.size = fobj->f->size,
.stt[0] =
{
.level = fobj->f->stt[0].level,
},
},
};
code = TARRAY2_APPEND(rtner->fopArr, op);
TSDB_CHECK_CODE(code, lino, _exit);
// do copy the file
code = tsdbCopyFileS3(rtner, fobj, &op.nf);
TSDB_CHECK_CODE(code, lino, _exit);
_exit:
if (code) {
TSDB_ERROR_LOG(TD_VID(rtner->tsdb->pVnode), lino, code);
}
return code;
}
typedef struct { typedef struct {
STsdb *tsdb; STsdb *tsdb;
int32_t sync; int32_t sync;
...@@ -201,9 +299,15 @@ static int32_t tsdbDoRetention2(void *arg) { ...@@ -201,9 +299,15 @@ static int32_t tsdbDoRetention2(void *arg) {
for (int32_t ftype = 0; (ftype < TSDB_FTYPE_MAX) && (fobj = rtner->ctx->fset->farr[ftype], 1); ++ftype) { for (int32_t ftype = 0; (ftype < TSDB_FTYPE_MAX) && (fobj = rtner->ctx->fset->farr[ftype], 1); ++ftype) {
if (fobj == NULL) continue; if (fobj == NULL) continue;
int32_t nlevel = tfsGetLevel(rtner->tsdb->pVnode->pTfs);
if (tsS3Enabled && nlevel > 1 && TSDB_FTYPE_DATA == ftype && fobj->f->did.level == nlevel - 1) {
code = tsdbRemoveFileObjectS3(rtner, fobj);
TSDB_CHECK_CODE(code, lino, _exit);
} else {
code = tsdbDoRemoveFileObject(rtner, fobj); code = tsdbDoRemoveFileObject(rtner, fobj);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
}
SSttLvl *lvl; SSttLvl *lvl;
TARRAY2_FOREACH(rtner->ctx->fset->lvlArr, lvl) { TARRAY2_FOREACH(rtner->ctx->fset->lvlArr, lvl) {
...@@ -228,9 +332,16 @@ static int32_t tsdbDoRetention2(void *arg) { ...@@ -228,9 +332,16 @@ static int32_t tsdbDoRetention2(void *arg) {
if (fobj == NULL) continue; if (fobj == NULL) continue;
if (fobj->f->did.level == did.level) continue; if (fobj->f->did.level == did.level) continue;
int32_t nlevel = tfsGetLevel(rtner->tsdb->pVnode->pTfs);
if (tsS3Enabled && nlevel > 1 && TSDB_FTYPE_DATA == ftype && did.level == nlevel - 1) {
code = tsdbMigrateDataFileS3(rtner, fobj, &did);
TSDB_CHECK_CODE(code, lino, _exit);
} else {
code = tsdbDoMigrateFileObj(rtner, fobj, &did); code = tsdbDoMigrateFileObj(rtner, fobj, &did);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
}
// stt // stt
SSttLvl *lvl; SSttLvl *lvl;
......
...@@ -76,7 +76,7 @@ int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq2 *pMsg) { ...@@ -76,7 +76,7 @@ int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq2 *pMsg) {
int32_t code = 0; int32_t code = 0;
STsdbKeepCfg *pCfg = &pTsdb->keepCfg; STsdbKeepCfg *pCfg = &pTsdb->keepCfg;
TSKEY now = taosGetTimestamp(pCfg->precision); TSKEY now = taosGetTimestamp(pCfg->precision);
TSKEY minKey = now - tsTickPerMin[pCfg->precision] * pCfg->keep2; TSKEY minKey = now - tsTickPerMin[pCfg->precision] * pCfg->keep1;
TSKEY maxKey = tsMaxKeyByPrecision[pCfg->precision]; TSKEY maxKey = tsMaxKeyByPrecision[pCfg->precision];
int32_t size = taosArrayGetSize(pMsg->aSubmitTbData); int32_t size = taosArrayGetSize(pMsg->aSubmitTbData);
......
#define ALLOW_FORBID_FUNC
#include "vndCos.h"
extern char tsS3Endpoint[];
extern char tsS3AccessKeyId[];
extern char tsS3AccessKeySecret[];
extern char tsS3BucketName[];
extern char tsS3AppId[];
#ifdef USE_COS
#include "cos_api.h"
#include "cos_http_io.h"
#include "cos_log.h"
int32_t s3Init() {
if (cos_http_io_initialize(NULL, 0) != COSE_OK) {
return -1;
}
// set log level, default COS_LOG_WARN
cos_log_set_level(COS_LOG_WARN);
// set log output, default stderr
cos_log_set_output(NULL);
return 0;
}
void s3CleanUp() { cos_http_io_deinitialize(); }
static void log_status(cos_status_t *s) {
cos_warn_log("status->code: %d", s->code);
if (s->error_code) cos_warn_log("status->error_code: %s", s->error_code);
if (s->error_msg) cos_warn_log("status->error_msg: %s", s->error_msg);
if (s->req_id) cos_warn_log("status->req_id: %s", s->req_id);
}
static void s3InitRequestOptions(cos_request_options_t *options, int is_cname) {
options->config = cos_config_create(options->pool);
cos_config_t *config = options->config;
cos_str_set(&config->endpoint, tsS3Endpoint);
cos_str_set(&config->access_key_id, tsS3AccessKeyId);
cos_str_set(&config->access_key_secret, tsS3AccessKeySecret);
cos_str_set(&config->appid, tsS3AppId);
config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
}
int32_t s3PutObjectFromFile(const char *file_str, const char *object_str) {
int32_t code = 0;
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket, object, file;
cos_table_t *resp_headers;
int traffic_limit = 0;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
s3InitRequestOptions(options, is_cname);
cos_table_t *headers = NULL;
if (traffic_limit) {
// 限速值设置范围为819200 - 838860800,即100KB/s - 100MB/s,如果超出该范围将返回400错误
headers = cos_table_make(p, 1);
cos_table_add_int(headers, "x-cos-traffic-limit", 819200);
}
cos_str_set(&bucket, tsS3BucketName);
cos_str_set(&file, file_str);
cos_str_set(&object, object_str);
s = cos_put_object_from_file(options, &bucket, &object, &file, headers, &resp_headers);
log_status(s);
cos_pool_destroy(p);
if (s->code != 200) {
return code = s->code;
}
return code;
}
void s3DeleteObjects(const char *object_name[], int nobject) {
cos_pool_t *p = NULL;
int is_cname = 0;
cos_string_t bucket;
cos_table_t *resp_headers = NULL;
cos_request_options_t *options = NULL;
cos_list_t object_list;
cos_list_t deleted_object_list;
int is_quiet = COS_TRUE;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
s3InitRequestOptions(options, is_cname);
cos_str_set(&bucket, tsS3BucketName);
cos_list_init(&object_list);
cos_list_init(&deleted_object_list);
for (int i = 0; i < nobject; ++i) {
cos_object_key_t *content = cos_create_cos_object_key(p);
cos_str_set(&content->key, object_name[i]);
cos_list_add_tail(&content->node, &object_list);
}
cos_status_t *s = cos_delete_objects(options, &bucket, &object_list, is_quiet, &resp_headers, &deleted_object_list);
log_status(s);
cos_pool_destroy(p);
if (cos_status_is_ok(s)) {
cos_warn_log("delete objects succeeded\n");
} else {
cos_warn_log("delete objects failed\n");
}
}
bool s3Exists(const char *object_name) {
bool ret = false;
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_table_t *resp_headers;
cos_table_t *headers = NULL;
cos_object_exist_status_e object_exist;
cos_pool_create(&p, NULL);
options = cos_request_options_create(p);
s3InitRequestOptions(options, is_cname);
cos_str_set(&bucket, tsS3BucketName);
cos_str_set(&object, object_name);
s = cos_check_object_exist(options, &bucket, &object, headers, &object_exist, &resp_headers);
if (object_exist == COS_OBJECT_NON_EXIST) {
cos_warn_log("object: %.*s non exist.\n", object.len, object.data);
} else if (object_exist == COS_OBJECT_EXIST) {
ret = true;
cos_warn_log("object: %.*s exist.\n", object.len, object.data);
} else {
cos_warn_log("object: %.*s unknown status.\n", object.len, object.data);
log_status(s);
}
cos_pool_destroy(p);
return ret;
}
bool s3Get(const char *object_name, const char *path) {
bool ret = false;
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_string_t file;
cos_table_t *resp_headers = NULL;
cos_table_t *headers = NULL;
int traffic_limit = 0;
//创建内存池
cos_pool_create(&p, NULL);
//初始化请求选项
options = cos_request_options_create(p);
s3InitRequestOptions(options, is_cname);
cos_str_set(&bucket, tsS3BucketName);
if (traffic_limit) {
//限速值设置范围为819200 - 838860800,即100KB/s - 100MB/s,如果超出该范围将返回400错误
headers = cos_table_make(p, 1);
cos_table_add_int(headers, "x-cos-traffic-limit", 819200);
}
//下载对象
cos_str_set(&file, path);
cos_str_set(&object, object_name);
s = cos_get_object_to_file(options, &bucket, &object, headers, NULL, &file, &resp_headers);
if (cos_status_is_ok(s)) {
ret = true;
cos_warn_log("get object succeeded\n");
} else {
cos_warn_log("get object failed\n");
}
//销毁内存池
cos_pool_destroy(p);
return ret;
}
typedef struct {
int64_t size;
int32_t atime;
char name[TSDB_FILENAME_LEN];
} SEvictFile;
static int32_t evictFileCompareAsce(const void *pLeft, const void *pRight) {
SEvictFile *lhs = (SEvictFile *)pLeft;
SEvictFile *rhs = (SEvictFile *)pRight;
return lhs->atime < rhs->atime ? -1 : 1;
}
void s3EvictCache(const char *path, long object_size) {
SDiskSize disk_size = {0};
char dir_name[TSDB_FILENAME_LEN] = "\0";
tstrncpy(dir_name, path, TSDB_FILENAME_LEN);
taosDirName(dir_name);
if (taosGetDiskSize((char *)dir_name, &disk_size) < 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
vError("failed to get disk:%s size since %s", path, terrstr());
return;
}
if (object_size >= disk_size.avail - (1 << 30)) {
// evict too old files
// 1, list data files' atime under dir(path)
tdbDirPtr pDir = taosOpenDir(dir_name);
if (pDir == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
vError("failed to open %s since %s", dir_name, terrstr());
}
SArray *evict_files = taosArrayInit(16, sizeof(SEvictFile));
tdbDirEntryPtr pDirEntry;
while ((pDirEntry = taosReadDir(pDir)) != NULL) {
char *name = taosGetDirEntryName(pDirEntry);
if (!strncmp(name + strlen(name) - 5, ".data", 5)) {
SEvictFile e_file = {0};
char entry_name[TSDB_FILENAME_LEN] = "\0";
int dir_len = strlen(dir_name);
memcpy(e_file.name, dir_name, dir_len);
e_file.name[dir_len] = '/';
memcpy(e_file.name + dir_len + 1, name, strlen(name));
taosStatFile(e_file.name, &e_file.size, NULL, &e_file.atime);
taosArrayPush(evict_files, &e_file);
}
}
taosCloseDir(&pDir);
// 2, sort by atime
taosArraySort(evict_files, evictFileCompareAsce);
// 3, remove files ascendingly until we get enough object_size space
long evict_size = 0;
size_t ef_size = TARRAY_SIZE(evict_files);
for (size_t i = 0; i < ef_size; ++i) {
SEvictFile *evict_file = taosArrayGet(evict_files, i);
taosRemoveFile(evict_file->name);
evict_size += evict_file->size;
if (evict_size >= object_size) {
break;
}
}
taosArrayDestroy(evict_files);
}
}
long s3Size(const char *object_name) {
long size = 0;
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_table_t *resp_headers = NULL;
//创建内存池
cos_pool_create(&p, NULL);
//初始化请求选项
options = cos_request_options_create(p);
s3InitRequestOptions(options, is_cname);
cos_str_set(&bucket, tsS3BucketName);
//获取对象元数据
cos_str_set(&object, object_name);
s = cos_head_object(options, &bucket, &object, NULL, &resp_headers);
// print_headers(resp_headers);
if (cos_status_is_ok(s)) {
char *content_length_str = (char *)apr_table_get(resp_headers, COS_CONTENT_LENGTH);
if (content_length_str != NULL) {
size = atol(content_length_str);
}
cos_warn_log("head object succeeded: %ld\n", size);
} else {
cos_warn_log("head object failed\n");
}
//销毁内存池
cos_pool_destroy(p);
return size;
}
#else
int32_t s3Init() { return 0; }
void s3CleanUp() {}
int32_t s3PutObjectFromFile(const char *file, const char *object) { return 0; }
void s3DeleteObjects(const char *object_name[], int nobject) {}
bool s3Exists(const char *object_name) { return false; }
bool s3Get(const char *object_name, const char *path) { return false; }
void s3EvictCache(const char *path, long object_size) {}
long s3Size(const char *object_name) { return 0; }
#endif
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#include "vnd.h" #include "vnd.h"
#include "vndCos.h"
typedef struct SVnodeTask SVnodeTask; typedef struct SVnodeTask SVnodeTask;
struct SVnodeTask { struct SVnodeTask {
...@@ -81,6 +82,9 @@ int vnodeInit(int nthreads) { ...@@ -81,6 +82,9 @@ int vnodeInit(int nthreads) {
if (tqInit() < 0) { if (tqInit() < 0) {
return -1; return -1;
} }
if (s3Init() < 0) {
return -1;
}
return 0; return 0;
} }
...@@ -112,6 +116,7 @@ void vnodeCleanup() { ...@@ -112,6 +116,7 @@ void vnodeCleanup() {
walCleanUp(); walCleanUp();
tqCleanUp(); tqCleanUp();
smaCleanUp(); smaCleanUp();
s3CleanUp();
} }
int vnodeScheduleTaskEx(int tpid, int (*execute)(void*), void* arg) { int vnodeScheduleTaskEx(int tpid, int (*execute)(void*), void* arg) {
......
...@@ -848,7 +848,7 @@ int32_t udfdSaveFuncBodyToFile(SFuncInfo *pFuncInfo, SUdf *udf) { ...@@ -848,7 +848,7 @@ int32_t udfdSaveFuncBodyToFile(SFuncInfo *pFuncInfo, SUdf *udf) {
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
udfdGetFuncBodyPath(udf, path); udfdGetFuncBodyPath(udf, path);
bool fileExist = !(taosStatFile(path, NULL, NULL) < 0); bool fileExist = !(taosStatFile(path, NULL, NULL, NULL) < 0);
if (fileExist) { if (fileExist) {
strncpy(udf->path, path, PATH_MAX); strncpy(udf->path, path, PATH_MAX);
fnInfo("udfd func body file. reuse existing file %s", path); fnInfo("udfd func body file. reuse existing file %s", path);
......
...@@ -162,7 +162,7 @@ static FORCE_INLINE int idxFileCtxGetSize(IFileCtx* ctx) { ...@@ -162,7 +162,7 @@ static FORCE_INLINE int idxFileCtxGetSize(IFileCtx* ctx) {
return ctx->offset; return ctx->offset;
} else { } else {
int64_t file_size = 0; int64_t file_size = 0;
taosStatFile(ctx->file.buf, &file_size, NULL); taosStatFile(ctx->file.buf, &file_size, NULL, NULL);
return (int)file_size; return (int)file_size;
} }
} }
...@@ -199,7 +199,7 @@ IFileCtx* idxFileCtxCreate(WriterType type, const char* path, bool readOnly, int ...@@ -199,7 +199,7 @@ IFileCtx* idxFileCtxCreate(WriterType type, const char* path, bool readOnly, int
code = taosFtruncateFile(ctx->file.pFile, 0); code = taosFtruncateFile(ctx->file.pFile, 0);
UNUSED(code); UNUSED(code);
code = taosStatFile(path, &ctx->file.size, NULL); code = taosStatFile(path, &ctx->file.size, NULL, NULL);
UNUSED(code); UNUSED(code);
ctx->file.wBufOffset = 0; ctx->file.wBufOffset = 0;
......
...@@ -280,7 +280,8 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = { ...@@ -280,7 +280,8 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = {
static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode); static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode);
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode); static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode);
static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal); static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal);
static int32_t createSimpleSelectStmtFromProjList(const char* pDb, const char* pTable, SNodeList* pProjectionList, SSelectStmt** pStmt); static int32_t createSimpleSelectStmtFromProjList(const char* pDb, const char* pTable, SNodeList* pProjectionList,
SSelectStmt** pStmt);
static int32_t createLastTsSelectStmt(char* pDb, char* pTable, STableMeta* pMeta, SNode** pQuery); static int32_t createLastTsSelectStmt(char* pDb, char* pTable, STableMeta* pMeta, SNode** pQuery);
static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery); static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery);
static int32_t setRefreshMate(STranslateContext* pCxt, SQuery* pQuery); static int32_t setRefreshMate(STranslateContext* pCxt, SQuery* pQuery);
...@@ -774,7 +775,8 @@ static SNodeList* getProjectList(const SNode* pNode) { ...@@ -774,7 +775,8 @@ static SNodeList* getProjectList(const SNode* pNode) {
static bool isTimeLineQuery(SNode* pStmt) { static bool isTimeLineQuery(SNode* pStmt) {
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) { if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
return (TIME_LINE_MULTI == ((SSelectStmt*)pStmt)->timeLineResMode) || (TIME_LINE_GLOBAL == ((SSelectStmt*)pStmt)->timeLineResMode); return (TIME_LINE_MULTI == ((SSelectStmt*)pStmt)->timeLineResMode) ||
(TIME_LINE_GLOBAL == ((SSelectStmt*)pStmt)->timeLineResMode);
} else if (QUERY_NODE_SET_OPERATOR == nodeType(pStmt)) { } else if (QUERY_NODE_SET_OPERATOR == nodeType(pStmt)) {
return TIME_LINE_GLOBAL == ((SSetOperator*)pStmt)->timeLineResMode; return TIME_LINE_GLOBAL == ((SSetOperator*)pStmt)->timeLineResMode;
} else { } else {
...@@ -793,7 +795,7 @@ static bool isGlobalTimeLineQuery(SNode* pStmt) { ...@@ -793,7 +795,7 @@ static bool isGlobalTimeLineQuery(SNode* pStmt) {
} }
static bool isTimeLineAlignedQuery(SNode* pStmt) { static bool isTimeLineAlignedQuery(SNode* pStmt) {
SSelectStmt *pSelect = (SSelectStmt *)pStmt; SSelectStmt* pSelect = (SSelectStmt*)pStmt;
if (isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery)) { if (isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery)) {
return true; return true;
} }
...@@ -803,7 +805,7 @@ static bool isTimeLineAlignedQuery(SNode* pStmt) { ...@@ -803,7 +805,7 @@ static bool isTimeLineAlignedQuery(SNode* pStmt) {
if (QUERY_NODE_SELECT_STMT != nodeType(((STempTableNode*)pSelect->pFromTable)->pSubquery)) { if (QUERY_NODE_SELECT_STMT != nodeType(((STempTableNode*)pSelect->pFromTable)->pSubquery)) {
return false; return false;
} }
SSelectStmt *pSub = (SSelectStmt *)((STempTableNode*)pSelect->pFromTable)->pSubquery; SSelectStmt* pSub = (SSelectStmt*)((STempTableNode*)pSelect->pFromTable)->pSubquery;
if (nodesListMatch(pSelect->pPartitionByList, pSub->pPartitionByList)) { if (nodesListMatch(pSelect->pPartitionByList, pSub->pPartitionByList)) {
return true; return true;
} }
...@@ -1610,9 +1612,11 @@ static int32_t translateInterpFunc(STranslateContext* pCxt, SFunctionNode* pFunc ...@@ -1610,9 +1612,11 @@ static int32_t translateInterpFunc(STranslateContext* pCxt, SFunctionNode* pFunc
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
} }
if (pSelect->hasInterpFunc && (FUNC_RETURN_ROWS_INDEFINITE == pSelect->returnRows || pSelect->returnRows != fmGetFuncReturnRows(pFunc))) { if (pSelect->hasInterpFunc &&
(FUNC_RETURN_ROWS_INDEFINITE == pSelect->returnRows || pSelect->returnRows != fmGetFuncReturnRows(pFunc))) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC, return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC,
"%s ignoring null value options cannot be used when applying to multiple columns", pFunc->functionName); "%s ignoring null value options cannot be used when applying to multiple columns",
pFunc->functionName);
} }
if (NULL != pSelect->pWindow || NULL != pSelect->pGroupByList) { if (NULL != pSelect->pWindow || NULL != pSelect->pGroupByList) {
...@@ -1650,7 +1654,8 @@ static int32_t translateTimelineFunc(STranslateContext* pCxt, SFunctionNode* pFu ...@@ -1650,7 +1654,8 @@ static int32_t translateTimelineFunc(STranslateContext* pCxt, SFunctionNode* pFu
} }
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt; SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt;
if (NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) && if (NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) &&
!isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) && !isTimeLineAlignedQuery(pCxt->pCurrStmt)) { !isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) &&
!isTimeLineAlignedQuery(pCxt->pCurrStmt)) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC, return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC,
"%s function requires valid time series input", pFunc->functionName); "%s function requires valid time series input", pFunc->functionName);
} }
...@@ -2310,7 +2315,8 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) { ...@@ -2310,7 +2315,8 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
} }
} }
if (isScanPseudoColumnFunc(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) { if (isScanPseudoColumnFunc(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) {
if (pSelect->selectFuncNum > 1 || pSelect->hasOtherVectorFunc || !pSelect->hasSelectFunc || (isDistinctOrderBy(pCxt) && pCxt->currClause == SQL_CLAUSE_ORDER_BY)) { if (pSelect->selectFuncNum > 1 || pSelect->hasOtherVectorFunc || !pSelect->hasSelectFunc ||
(isDistinctOrderBy(pCxt) && pCxt->currClause == SQL_CLAUSE_ORDER_BY)) {
return generateDealNodeErrMsg(pCxt, getGroupByErrorCode(pCxt), ((SExprNode*)(*pNode))->userAlias); return generateDealNodeErrMsg(pCxt, getGroupByErrorCode(pCxt), ((SExprNode*)(*pNode))->userAlias);
} else { } else {
return rewriteColToSelectValFunc(pCxt, pNode); return rewriteColToSelectValFunc(pCxt, pNode);
...@@ -2405,14 +2411,14 @@ static int32_t checkHavingGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect) ...@@ -2405,14 +2411,14 @@ static int32_t checkHavingGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect)
if (NULL != pSelect->pHaving) { if (NULL != pSelect->pHaving) {
code = checkExprForGroupBy(pCxt, &pSelect->pHaving); code = checkExprForGroupBy(pCxt, &pSelect->pHaving);
} }
/* /*
if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pProjectionList) { if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pProjectionList) {
code = checkExprListForGroupBy(pCxt, pSelect, pSelect->pProjectionList); code = checkExprListForGroupBy(pCxt, pSelect, pSelect->pProjectionList);
} }
if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pOrderByList) { if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pOrderByList) {
code = checkExprListForGroupBy(pCxt, pSelect, pSelect->pOrderByList); code = checkExprListForGroupBy(pCxt, pSelect, pSelect->pOrderByList);
} }
*/ */
return code; return code;
} }
...@@ -2671,9 +2677,9 @@ static int32_t setTableCacheLastMode(STranslateContext* pCxt, SSelectStmt* pSele ...@@ -2671,9 +2677,9 @@ static int32_t setTableCacheLastMode(STranslateContext* pCxt, SSelectStmt* pSele
static EDealRes doTranslateTbName(SNode** pNode, void* pContext) { static EDealRes doTranslateTbName(SNode** pNode, void* pContext) {
switch (nodeType(*pNode)) { switch (nodeType(*pNode)) {
case QUERY_NODE_FUNCTION: { case QUERY_NODE_FUNCTION: {
SFunctionNode *pFunc = (SFunctionNode *)*pNode; SFunctionNode* pFunc = (SFunctionNode*)*pNode;
if (FUNCTION_TYPE_TBNAME == pFunc->funcType) { if (FUNCTION_TYPE_TBNAME == pFunc->funcType) {
SRewriteTbNameContext *pCxt = (SRewriteTbNameContext*)pContext; SRewriteTbNameContext* pCxt = (SRewriteTbNameContext*)pContext;
SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
if (NULL == pVal) { if (NULL == pVal) {
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY; pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
...@@ -2713,7 +2719,8 @@ static int32_t replaceTbName(STranslateContext* pCxt, SSelectStmt* pSelect) { ...@@ -2713,7 +2719,8 @@ static int32_t replaceTbName(STranslateContext* pCxt, SSelectStmt* pSelect) {
} }
SRealTableNode* pTable = (SRealTableNode*)pSelect->pFromTable; SRealTableNode* pTable = (SRealTableNode*)pSelect->pFromTable;
if (TSDB_CHILD_TABLE != pTable->pMeta->tableType && TSDB_NORMAL_TABLE != pTable->pMeta->tableType && TSDB_SYSTEM_TABLE != pTable->pMeta->tableType) { if (TSDB_CHILD_TABLE != pTable->pMeta->tableType && TSDB_NORMAL_TABLE != pTable->pMeta->tableType &&
TSDB_SYSTEM_TABLE != pTable->pMeta->tableType) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -3124,7 +3131,8 @@ static int32_t convertFillValue(STranslateContext* pCxt, SDataType dt, SNodeList ...@@ -3124,7 +3131,8 @@ static int32_t convertFillValue(STranslateContext* pCxt, SDataType dt, SNodeList
code = scalarCalculateConstants(pCastFunc, &pCell->pNode); code = scalarCalculateConstants(pCastFunc, &pCell->pNode);
} }
if (TSDB_CODE_SUCCESS == code && QUERY_NODE_VALUE != nodeType(pCell->pNode)) { if (TSDB_CODE_SUCCESS == code && QUERY_NODE_VALUE != nodeType(pCell->pNode)) {
code = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Fill value can only accept constant"); code =
generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Fill value can only accept constant");
} else if (TSDB_CODE_SUCCESS != code) { } else if (TSDB_CODE_SUCCESS != code) {
code = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Filled data type mismatch"); code = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Filled data type mismatch");
} }
...@@ -3590,7 +3598,6 @@ static int32_t createDefaultEveryNode(STranslateContext* pCxt, SNode** pOutput) ...@@ -3590,7 +3598,6 @@ static int32_t createDefaultEveryNode(STranslateContext* pCxt, SNode** pOutput)
pEvery->isDuration = true; pEvery->isDuration = true;
pEvery->literal = taosStrdup("1s"); pEvery->literal = taosStrdup("1s");
*pOutput = (SNode*)pEvery; *pOutput = (SNode*)pEvery;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -3689,8 +3696,8 @@ static int32_t translatePartitionBy(STranslateContext* pCxt, SSelectStmt* pSelec ...@@ -3689,8 +3696,8 @@ static int32_t translatePartitionBy(STranslateContext* pCxt, SSelectStmt* pSelec
if (pSelect->pPartitionByList) { if (pSelect->pPartitionByList) {
int8_t typeType = getTableTypeFromTableNode(pSelect->pFromTable); int8_t typeType = getTableTypeFromTableNode(pSelect->pFromTable);
SNode* pPar = nodesListGetNode(pSelect->pPartitionByList, 0); SNode* pPar = nodesListGetNode(pSelect->pPartitionByList, 0);
if (!((TSDB_NORMAL_TABLE == typeType || TSDB_CHILD_TABLE == typeType) && if (!((TSDB_NORMAL_TABLE == typeType || TSDB_CHILD_TABLE == typeType) && 1 == pSelect->pPartitionByList->length &&
1 == pSelect->pPartitionByList->length && (QUERY_NODE_FUNCTION == nodeType(pPar) && FUNCTION_TYPE_TBNAME == ((SFunctionNode*)pPar)->funcType))) { (QUERY_NODE_FUNCTION == nodeType(pPar) && FUNCTION_TYPE_TBNAME == ((SFunctionNode*)pPar)->funcType))) {
pSelect->timeLineResMode = TIME_LINE_MULTI; pSelect->timeLineResMode = TIME_LINE_MULTI;
} }
...@@ -3957,9 +3964,9 @@ static int32_t translateSetOperProject(STranslateContext* pCxt, SSetOperator* pS ...@@ -3957,9 +3964,9 @@ static int32_t translateSetOperProject(STranslateContext* pCxt, SSetOperator* pS
} }
snprintf(pRightExpr->aliasName, sizeof(pRightExpr->aliasName), "%s", pLeftExpr->aliasName); snprintf(pRightExpr->aliasName, sizeof(pRightExpr->aliasName), "%s", pLeftExpr->aliasName);
SNode* pProj = createSetOperProject(pSetOperator->stmtName, pLeft); SNode* pProj = createSetOperProject(pSetOperator->stmtName, pLeft);
if (QUERY_NODE_COLUMN == nodeType(pLeft) && QUERY_NODE_COLUMN == nodeType(pRight) if (QUERY_NODE_COLUMN == nodeType(pLeft) && QUERY_NODE_COLUMN == nodeType(pRight) &&
&& ((SColumnNode*)pLeft)->colId == PRIMARYKEY_TIMESTAMP_COL_ID ((SColumnNode*)pLeft)->colId == PRIMARYKEY_TIMESTAMP_COL_ID &&
&& ((SColumnNode*)pRight)->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { ((SColumnNode*)pRight)->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
((SColumnNode*)pProj)->colId = PRIMARYKEY_TIMESTAMP_COL_ID; ((SColumnNode*)pProj)->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
} }
if (TSDB_CODE_SUCCESS != nodesListMakeStrictAppend(&pSetOperator->pProjectionList, pProj)) { if (TSDB_CODE_SUCCESS != nodesListMakeStrictAppend(&pSetOperator->pProjectionList, pProj)) {
...@@ -5739,7 +5746,6 @@ static int32_t translateRestoreDnode(STranslateContext* pCxt, SRestoreComponentN ...@@ -5739,7 +5746,6 @@ static int32_t translateRestoreDnode(STranslateContext* pCxt, SRestoreComponentN
return buildCmdMsg(pCxt, TDMT_MND_RESTORE_DNODE, (FSerializeFunc)tSerializeSRestoreDnodeReq, &restoreReq); return buildCmdMsg(pCxt, TDMT_MND_RESTORE_DNODE, (FSerializeFunc)tSerializeSRestoreDnodeReq, &restoreReq);
} }
static int32_t getSmaIndexDstVgId(STranslateContext* pCxt, const char* pDbName, const char* pTableName, static int32_t getSmaIndexDstVgId(STranslateContext* pCxt, const char* pDbName, const char* pTableName,
int32_t* pVgId) { int32_t* pVgId) {
SVgroupInfo vg = {0}; SVgroupInfo vg = {0};
...@@ -5881,13 +5887,15 @@ int32_t createIntervalFromCreateSmaIndexStmt(SCreateIndexStmt* pStmt, SInterval* ...@@ -5881,13 +5887,15 @@ int32_t createIntervalFromCreateSmaIndexStmt(SCreateIndexStmt* pStmt, SInterval*
pInterval->interval = ((SValueNode*)pStmt->pOptions->pInterval)->datum.i; pInterval->interval = ((SValueNode*)pStmt->pOptions->pInterval)->datum.i;
pInterval->intervalUnit = ((SValueNode*)pStmt->pOptions->pInterval)->unit; pInterval->intervalUnit = ((SValueNode*)pStmt->pOptions->pInterval)->unit;
pInterval->offset = NULL != pStmt->pOptions->pOffset ? ((SValueNode*)pStmt->pOptions->pOffset)->datum.i : 0; pInterval->offset = NULL != pStmt->pOptions->pOffset ? ((SValueNode*)pStmt->pOptions->pOffset)->datum.i : 0;
pInterval->sliding = NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->datum.i : pInterval->interval; pInterval->sliding =
pInterval->slidingUnit = NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->unit : pInterval->intervalUnit; NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->datum.i : pInterval->interval;
pInterval->slidingUnit =
NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->unit : pInterval->intervalUnit;
pInterval->precision = pStmt->pOptions->tsPrecision; pInterval->precision = pStmt->pOptions->tsPrecision;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t translatePostCreateSmaIndex(SParseContext* pParseCxt, SQuery* pQuery, void ** pResRow) { int32_t translatePostCreateSmaIndex(SParseContext* pParseCxt, SQuery* pQuery, void** pResRow) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SCreateIndexStmt* pStmt = (SCreateIndexStmt*)pQuery->pRoot; SCreateIndexStmt* pStmt = (SCreateIndexStmt*)pQuery->pRoot;
int64_t lastTs = 0; int64_t lastTs = 0;
...@@ -6055,7 +6063,7 @@ static int32_t buildCreateTopicReq(STranslateContext* pCxt, SCreateTopicStmt* pS ...@@ -6055,7 +6063,7 @@ static int32_t buildCreateTopicReq(STranslateContext* pCxt, SCreateTopicStmt* pS
toName(pCxt->pParseCxt->acctId, pStmt->subDbName, pStmt->subSTbName, &name); toName(pCxt->pParseCxt->acctId, pStmt->subDbName, pStmt->subSTbName, &name);
tNameGetFullDbName(&name, pReq->subDbName); tNameGetFullDbName(&name, pReq->subDbName);
tNameExtractFullName(&name, pReq->subStbName); tNameExtractFullName(&name, pReq->subStbName);
if(pStmt->pQuery != NULL) { if (pStmt->pQuery != NULL) {
code = nodesNodeToString(pStmt->pQuery, false, &pReq->ast, NULL); code = nodesNodeToString(pStmt->pQuery, false, &pReq->ast, NULL);
} }
} else if ('\0' != pStmt->subDbName[0]) { } else if ('\0' != pStmt->subDbName[0]) {
...@@ -6114,7 +6122,8 @@ static EDealRes checkColumnTagsInCond(SNode* pNode, void* pContext) { ...@@ -6114,7 +6122,8 @@ static EDealRes checkColumnTagsInCond(SNode* pNode, void* pContext) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
static int32_t checkCollectTopicTags(STranslateContext* pCxt, SCreateTopicStmt* pStmt, STableMeta* pMeta, SNodeList** ppProjection) { static int32_t checkCollectTopicTags(STranslateContext* pCxt, SCreateTopicStmt* pStmt, STableMeta* pMeta,
SNodeList** ppProjection) {
SBuildTopicContext colCxt = {.colExists = false, .colNotFound = false, .pMeta = pMeta, .pTags = NULL}; SBuildTopicContext colCxt = {.colExists = false, .colNotFound = false, .pMeta = pMeta, .pTags = NULL};
nodesWalkExprPostOrder(pStmt->pWhere, checkColumnTagsInCond, &colCxt); nodesWalkExprPostOrder(pStmt->pWhere, checkColumnTagsInCond, &colCxt);
if (colCxt.colNotFound) { if (colCxt.colNotFound) {
...@@ -6125,7 +6134,7 @@ static int32_t checkCollectTopicTags(STranslateContext* pCxt, SCreateTopicStmt* ...@@ -6125,7 +6134,7 @@ static int32_t checkCollectTopicTags(STranslateContext* pCxt, SCreateTopicStmt*
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, "Columns are forbidden in where clause"); return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, "Columns are forbidden in where clause");
} }
if (NULL == colCxt.pTags) { // put one column to select if (NULL == colCxt.pTags) { // put one column to select
// for (int32_t i = 0; i < pMeta->tableInfo.numOfColumns; ++i) { // for (int32_t i = 0; i < pMeta->tableInfo.numOfColumns; ++i) {
SSchema* column = &pMeta->schema[0]; SSchema* column = &pMeta->schema[0];
SColumnNode* col = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); SColumnNode* col = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
if (NULL == col) { if (NULL == col) {
...@@ -6135,7 +6144,7 @@ static int32_t checkCollectTopicTags(STranslateContext* pCxt, SCreateTopicStmt* ...@@ -6135,7 +6144,7 @@ static int32_t checkCollectTopicTags(STranslateContext* pCxt, SCreateTopicStmt*
strcpy(col->node.aliasName, col->colName); strcpy(col->node.aliasName, col->colName);
strcpy(col->node.userAlias, col->colName); strcpy(col->node.userAlias, col->colName);
addTagList(&colCxt.pTags, (SNode*)col); addTagList(&colCxt.pTags, (SNode*)col);
// } // }
} }
*ppProjection = colCxt.pTags; *ppProjection = colCxt.pTags;
...@@ -6556,7 +6565,8 @@ static int32_t checkStreamQuery(STranslateContext* pCxt, SCreateStreamStmt* pStm ...@@ -6556,7 +6565,8 @@ static int32_t checkStreamQuery(STranslateContext* pCxt, SCreateStreamStmt* pStm
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
"SUBTABLE expression must be of VARCHAR type"); "SUBTABLE expression must be of VARCHAR type");
} }
if (NULL != pSelect->pSubtable && 0 == LIST_LENGTH(pSelect->pPartitionByList) && subtableExprHasColumnOrPseudoColumn(pSelect->pSubtable)) { if (NULL != pSelect->pSubtable && 0 == LIST_LENGTH(pSelect->pPartitionByList) &&
subtableExprHasColumnOrPseudoColumn(pSelect->pSubtable)) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
"SUBTABLE expression must not has column when no partition by clause"); "SUBTABLE expression must not has column when no partition by clause");
} }
...@@ -6917,13 +6927,13 @@ static int32_t createLastTsSelectStmt(char* pDb, char* pTable, STableMeta* pMeta ...@@ -6917,13 +6927,13 @@ static int32_t createLastTsSelectStmt(char* pDb, char* pTable, STableMeta* pMeta
strcpy(col->colName, pMeta->schema[0].name); strcpy(col->colName, pMeta->schema[0].name);
SNodeList* pParamterList = nodesMakeList(); SNodeList* pParamterList = nodesMakeList();
if (NULL == pParamterList) { if (NULL == pParamterList) {
nodesDestroyNode((SNode *)col); nodesDestroyNode((SNode*)col);
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
int32_t code = nodesListStrictAppend(pParamterList, (SNode *)col); int32_t code = nodesListStrictAppend(pParamterList, (SNode*)col);
if (code) { if (code) {
nodesDestroyNode((SNode *)col); nodesDestroyNode((SNode*)col);
nodesDestroyList(pParamterList); nodesDestroyList(pParamterList);
return code; return code;
} }
...@@ -6946,7 +6956,7 @@ static int32_t createLastTsSelectStmt(char* pDb, char* pTable, STableMeta* pMeta ...@@ -6946,7 +6956,7 @@ static int32_t createLastTsSelectStmt(char* pDb, char* pTable, STableMeta* pMeta
return code; return code;
} }
code = createSimpleSelectStmtFromProjList(pDb, pTable, pProjectionList, (SSelectStmt **)pQuery); code = createSimpleSelectStmtFromProjList(pDb, pTable, pProjectionList, (SSelectStmt**)pQuery);
if (code) { if (code) {
nodesDestroyList(pProjectionList); nodesDestroyList(pProjectionList);
return code; return code;
...@@ -6984,14 +6994,14 @@ static int32_t buildCreateStreamQuery(STranslateContext* pCxt, SCreateStreamStmt ...@@ -6984,14 +6994,14 @@ static int32_t buildCreateStreamQuery(STranslateContext* pCxt, SCreateStreamStmt
if (TSDB_CODE_SUCCESS == code && pStmt->pOptions->fillHistory) { if (TSDB_CODE_SUCCESS == code && pStmt->pOptions->fillHistory) {
SRealTableNode* pTable = (SRealTableNode*)(((SSelectStmt*)pStmt->pQuery)->pFromTable); SRealTableNode* pTable = (SRealTableNode*)(((SSelectStmt*)pStmt->pQuery)->pFromTable);
code = createLastTsSelectStmt(pTable->table.dbName, pTable->table.tableName, pTable->pMeta, &pStmt->pPrevQuery); code = createLastTsSelectStmt(pTable->table.dbName, pTable->table.tableName, pTable->pMeta, &pStmt->pPrevQuery);
/* /*
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
STranslateContext cxt = {0}; STranslateContext cxt = {0};
int32_t code = initTranslateContext(pCxt->pParseCxt, pCxt->pMetaCache, &cxt); int32_t code = initTranslateContext(pCxt->pParseCxt, pCxt->pMetaCache, &cxt);
code = translateQuery(&cxt, pStmt->pPrevQuery); code = translateQuery(&cxt, pStmt->pPrevQuery);
destroyTranslateContext(&cxt); destroyTranslateContext(&cxt);
} }
*/ */
} }
taosMemoryFree(pMeta); taosMemoryFree(pMeta);
return code; return code;
...@@ -7138,7 +7148,6 @@ int32_t translatePostCreateStream(SParseContext* pParseCxt, SQuery* pQuery, void ...@@ -7138,7 +7148,6 @@ int32_t translatePostCreateStream(SParseContext* pParseCxt, SQuery* pQuery, void
return code; return code;
} }
static int32_t translateDropStream(STranslateContext* pCxt, SDropStreamStmt* pStmt) { static int32_t translateDropStream(STranslateContext* pCxt, SDropStreamStmt* pStmt) {
SMDropStreamReq dropReq = {0}; SMDropStreamReq dropReq = {0};
SName name; SName name;
...@@ -7169,7 +7178,7 @@ static int32_t translateResumeStream(STranslateContext* pCxt, SResumeStreamStmt* ...@@ -7169,7 +7178,7 @@ static int32_t translateResumeStream(STranslateContext* pCxt, SResumeStreamStmt*
static int32_t readFromFile(char* pName, int32_t* len, char** buf) { static int32_t readFromFile(char* pName, int32_t* len, char** buf) {
int64_t filesize = 0; int64_t filesize = 0;
if (taosStatFile(pName, &filesize, NULL) < 0) { if (taosStatFile(pName, &filesize, NULL, NULL) < 0) {
return TAOS_SYSTEM_ERROR(errno); return TAOS_SYSTEM_ERROR(errno);
} }
...@@ -7823,7 +7832,8 @@ static SNodeList* createProjectCols(int32_t ncols, const char* const pCols[]) { ...@@ -7823,7 +7832,8 @@ static SNodeList* createProjectCols(int32_t ncols, const char* const pCols[]) {
return pProjections; return pProjections;
} }
static int32_t createSimpleSelectStmtImpl(const char* pDb, const char* pTable, SNodeList* pProjectionList, SSelectStmt** pStmt) { static int32_t createSimpleSelectStmtImpl(const char* pDb, const char* pTable, SNodeList* pProjectionList,
SSelectStmt** pStmt) {
SSelectStmt* pSelect = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT); SSelectStmt* pSelect = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT);
if (NULL == pSelect) { if (NULL == pSelect) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
...@@ -7846,7 +7856,6 @@ static int32_t createSimpleSelectStmtImpl(const char* pDb, const char* pTable, S ...@@ -7846,7 +7856,6 @@ static int32_t createSimpleSelectStmtImpl(const char* pDb, const char* pTable, S
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t createSimpleSelectStmtFromCols(const char* pDb, const char* pTable, int32_t numOfProjs, static int32_t createSimpleSelectStmtFromCols(const char* pDb, const char* pTable, int32_t numOfProjs,
const char* const pProjCol[], SSelectStmt** pStmt) { const char* const pProjCol[], SSelectStmt** pStmt) {
SNodeList* pProjectionList = NULL; SNodeList* pProjectionList = NULL;
...@@ -7860,13 +7869,15 @@ static int32_t createSimpleSelectStmtFromCols(const char* pDb, const char* pTabl ...@@ -7860,13 +7869,15 @@ static int32_t createSimpleSelectStmtFromCols(const char* pDb, const char* pTabl
return createSimpleSelectStmtImpl(pDb, pTable, pProjectionList, pStmt); return createSimpleSelectStmtImpl(pDb, pTable, pProjectionList, pStmt);
} }
static int32_t createSimpleSelectStmtFromProjList(const char* pDb, const char* pTable, SNodeList* pProjectionList, SSelectStmt** pStmt) { static int32_t createSimpleSelectStmtFromProjList(const char* pDb, const char* pTable, SNodeList* pProjectionList,
SSelectStmt** pStmt) {
return createSimpleSelectStmtImpl(pDb, pTable, pProjectionList, pStmt); return createSimpleSelectStmtImpl(pDb, pTable, pProjectionList, pStmt);
} }
static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt) { static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt) {
const SSysTableShowAdapter* pShow = &sysTableShowAdapter[showType - SYSTABLE_SHOW_TYPE_OFFSET]; const SSysTableShowAdapter* pShow = &sysTableShowAdapter[showType - SYSTABLE_SHOW_TYPE_OFFSET];
return createSimpleSelectStmtFromCols(pShow->pDbName, pShow->pTableName, pShow->numOfShowCols, pShow->pShowCols, pStmt); return createSimpleSelectStmtFromCols(pShow->pDbName, pShow->pTableName, pShow->numOfShowCols, pShow->pShowCols,
pStmt);
} }
static int32_t createSelectStmtForShowTableDist(SShowTableDistributedStmt* pStmt, SSelectStmt** pOutput) { static int32_t createSelectStmtForShowTableDist(SShowTableDistributedStmt* pStmt, SSelectStmt** pOutput) {
...@@ -8004,8 +8015,8 @@ static int32_t createShowTableTagsProjections(SNodeList** pProjections, SNodeLis ...@@ -8004,8 +8015,8 @@ static int32_t createShowTableTagsProjections(SNodeList** pProjections, SNodeLis
static int32_t rewriteShowStableTags(STranslateContext* pCxt, SQuery* pQuery) { static int32_t rewriteShowStableTags(STranslateContext* pCxt, SQuery* pQuery) {
SShowTableTagsStmt* pShow = (SShowTableTagsStmt*)pQuery->pRoot; SShowTableTagsStmt* pShow = (SShowTableTagsStmt*)pQuery->pRoot;
SSelectStmt* pSelect = NULL; SSelectStmt* pSelect = NULL;
int32_t code = createSimpleSelectStmtFromCols(((SValueNode*)pShow->pDbName)->literal, ((SValueNode*)pShow->pTbName)->literal, int32_t code = createSimpleSelectStmtFromCols(((SValueNode*)pShow->pDbName)->literal,
-1, NULL, &pSelect); ((SValueNode*)pShow->pTbName)->literal, -1, NULL, &pSelect);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = createShowTableTagsProjections(&pSelect->pProjectionList, &pShow->pTags); code = createShowTableTagsProjections(&pSelect->pProjectionList, &pShow->pTags);
} }
......
...@@ -42,7 +42,7 @@ int32_t raftStoreReadFile(SSyncNode *pNode) { ...@@ -42,7 +42,7 @@ int32_t raftStoreReadFile(SSyncNode *pNode) {
const char *file = pNode->raftStorePath; const char *file = pNode->raftStorePath;
SRaftStore *pStore = &pNode->raftStore; SRaftStore *pStore = &pNode->raftStore;
if (taosStatFile(file, NULL, NULL) < 0) { if (taosStatFile(file, NULL, NULL, NULL) < 0) {
sInfo("vgId:%d, raft store file:%s not exist, use default value", pNode->vgId, file); sInfo("vgId:%d, raft store file:%s not exist, use default value", pNode->vgId, file);
pStore->currentTerm = 0; pStore->currentTerm = 0;
pStore->voteFor.addr = 0; pStore->voteFor.addr = 0;
......
...@@ -53,7 +53,7 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx) { ...@@ -53,7 +53,7 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx) {
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr); walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
int64_t fileSize = 0; int64_t fileSize = 0;
taosStatFile(fnameStr, &fileSize, NULL); taosStatFile(fnameStr, &fileSize, NULL, NULL);
TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE); TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE);
if (pFile == NULL) { if (pFile == NULL) {
...@@ -304,7 +304,7 @@ int walRepairLogFileTs(SWal* pWal, bool* updateMeta) { ...@@ -304,7 +304,7 @@ int walRepairLogFileTs(SWal* pWal, bool* updateMeta) {
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr); walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
int32_t mtime = 0; int32_t mtime = 0;
if (taosStatFile(fnameStr, NULL, &mtime) < 0) { if (taosStatFile(fnameStr, NULL, &mtime, NULL) < 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
wError("vgId:%d, failed to stat file due to %s, file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); wError("vgId:%d, failed to stat file due to %s, file:%s", pWal->cfg.vgId, strerror(errno), fnameStr);
return -1; return -1;
...@@ -353,7 +353,7 @@ int walTrimIdxFile(SWal* pWal, int32_t fileIdx) { ...@@ -353,7 +353,7 @@ int walTrimIdxFile(SWal* pWal, int32_t fileIdx) {
walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr); walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr);
int64_t fileSize = 0; int64_t fileSize = 0;
taosStatFile(fnameStr, &fileSize, NULL); taosStatFile(fnameStr, &fileSize, NULL, NULL);
int64_t records = TMAX(0, pFileInfo->lastVer - pFileInfo->firstVer + 1); int64_t records = TMAX(0, pFileInfo->lastVer - pFileInfo->firstVer + 1);
int64_t lastEndOffset = records * sizeof(SWalIdxEntry); int64_t lastEndOffset = records * sizeof(SWalIdxEntry);
...@@ -436,7 +436,7 @@ int walCheckAndRepairMeta(SWal* pWal) { ...@@ -436,7 +436,7 @@ int walCheckAndRepairMeta(SWal* pWal) {
SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx); SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx);
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr); walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
int32_t code = taosStatFile(fnameStr, &fileSize, NULL); int32_t code = taosStatFile(fnameStr, &fileSize, NULL, NULL);
if (code < 0) { if (code < 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
wError("failed to stat file since %s. file:%s", terrstr(), fnameStr); wError("failed to stat file since %s. file:%s", terrstr(), fnameStr);
...@@ -522,7 +522,7 @@ int walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { ...@@ -522,7 +522,7 @@ int walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) {
walBuildLogName(pWal, pFileInfo->firstVer, fLogNameStr); walBuildLogName(pWal, pFileInfo->firstVer, fLogNameStr);
int64_t fileSize = 0; int64_t fileSize = 0;
if (taosStatFile(fnameStr, &fileSize, NULL) < 0 && errno != ENOENT) { if (taosStatFile(fnameStr, &fileSize, NULL, NULL) < 0 && errno != ENOENT) {
wError("vgId:%d, failed to stat file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); wError("vgId:%d, failed to stat file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr);
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
...@@ -935,7 +935,7 @@ int walLoadMeta(SWal* pWal) { ...@@ -935,7 +935,7 @@ int walLoadMeta(SWal* pWal) {
walBuildMetaName(pWal, metaVer, fnameStr); walBuildMetaName(pWal, metaVer, fnameStr);
// read metafile // read metafile
int64_t fileSize = 0; int64_t fileSize = 0;
taosStatFile(fnameStr, &fileSize, NULL); taosStatFile(fnameStr, &fileSize, NULL, NULL);
if (fileSize == 0) { if (fileSize == 0) {
(void)taosRemoveFile(fnameStr); (void)taosRemoveFile(fnameStr);
wDebug("vgId:%d, wal find empty meta ver %d", pWal->cfg.vgId, metaVer); wDebug("vgId:%d, wal find empty meta ver %d", pWal->cfg.vgId, metaVer);
......
...@@ -191,7 +191,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) { ...@@ -191,7 +191,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
#endif #endif
} }
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) { int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime, int32_t *atime) {
#ifdef WINDOWS #ifdef WINDOWS
struct _stati64 fileStat; struct _stati64 fileStat;
int32_t code = _stati64(path, &fileStat); int32_t code = _stati64(path, &fileStat);
...@@ -211,6 +211,10 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) { ...@@ -211,6 +211,10 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) {
*mtime = fileStat.st_mtime; *mtime = fileStat.st_mtime;
} }
if (atime != NULL) {
*atime = fileStat.st_mtime;
}
return 0; return 0;
} }
int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) { int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) {
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
#include "tlog.h" #include "tlog.h"
#include "os.h" #include "os.h"
#include "tconfig.h" #include "tconfig.h"
#include "tjson.h"
#include "tglobal.h" #include "tglobal.h"
#include "tjson.h"
#define LOG_MAX_LINE_SIZE (10024) #define LOG_MAX_LINE_SIZE (10024)
#define LOG_MAX_LINE_BUFFER_SIZE (LOG_MAX_LINE_SIZE + 3) #define LOG_MAX_LINE_BUFFER_SIZE (LOG_MAX_LINE_SIZE + 3)
...@@ -403,13 +403,13 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { ...@@ -403,13 +403,13 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
strcpy(name, fn); strcpy(name, fn);
strcat(name, ".0"); strcat(name, ".0");
} }
bool log0Exist = taosStatFile(name, NULL, &logstat0_mtime) >= 0; bool log0Exist = taosStatFile(name, NULL, &logstat0_mtime, NULL) >= 0;
if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) { if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) {
strcpy(name, fn); strcpy(name, fn);
strcat(name, ".1"); strcat(name, ".1");
} }
bool log1Exist = taosStatFile(name, NULL, &logstat1_mtime) >= 0; bool log1Exist = taosStatFile(name, NULL, &logstat1_mtime, NULL) >= 0;
// if none of the log files exist, open 0, if both exists, open the old one // if none of the log files exist, open 0, if both exists, open the old one
if (!log0Exist && !log1Exist) { if (!log0Exist && !log1Exist) {
...@@ -834,7 +834,7 @@ bool taosAssertDebug(bool condition, const char *file, int32_t line, const char ...@@ -834,7 +834,7 @@ bool taosAssertDebug(bool condition, const char *file, int32_t line, const char
return true; return true;
} }
void taosLogCrashInfo(char* nodeType, char* pMsg, int64_t msgLen, int signum, void *sigInfo) { void taosLogCrashInfo(char *nodeType, char *pMsg, int64_t msgLen, int signum, void *sigInfo) {
const char *flags = "UTL FATAL "; const char *flags = "UTL FATAL ";
ELogLevel level = DEBUG_FATAL; ELogLevel level = DEBUG_FATAL;
int32_t dflag = 255; int32_t dflag = 255;
...@@ -892,17 +892,17 @@ _return: ...@@ -892,17 +892,17 @@ _return:
taosMemoryFree(pMsg); taosMemoryFree(pMsg);
} }
void taosReadCrashInfo(char* filepath, char** pMsg, int64_t* pMsgLen, TdFilePtr* pFd) { void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr *pFd) {
const char *flags = "UTL FATAL "; const char *flags = "UTL FATAL ";
ELogLevel level = DEBUG_FATAL; ELogLevel level = DEBUG_FATAL;
int32_t dflag = 255; int32_t dflag = 255;
TdFilePtr pFile = NULL; TdFilePtr pFile = NULL;
bool truncateFile = false; bool truncateFile = false;
char* buf = NULL; char *buf = NULL;
if (NULL == *pFd) { if (NULL == *pFd) {
int64_t filesize = 0; int64_t filesize = 0;
if (taosStatFile(filepath, &filesize, NULL) < 0) { if (taosStatFile(filepath, &filesize, NULL, NULL) < 0) {
if (ENOENT == errno) { if (ENOENT == errno) {
return; return;
} }
...@@ -916,7 +916,7 @@ void taosReadCrashInfo(char* filepath, char** pMsg, int64_t* pMsgLen, TdFilePtr* ...@@ -916,7 +916,7 @@ void taosReadCrashInfo(char* filepath, char** pMsg, int64_t* pMsgLen, TdFilePtr*
return; return;
} }
pFile = taosOpenFile(filepath, TD_FILE_READ|TD_FILE_WRITE); pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_WRITE);
if (pFile == NULL) { if (pFile == NULL) {
if (ENOENT == errno) { if (ENOENT == errno) {
return; return;
...@@ -952,8 +952,8 @@ void taosReadCrashInfo(char* filepath, char** pMsg, int64_t* pMsgLen, TdFilePtr* ...@@ -952,8 +952,8 @@ void taosReadCrashInfo(char* filepath, char** pMsg, int64_t* pMsgLen, TdFilePtr*
readSize = taosReadFile(pFile, buf, msgLen); readSize = taosReadFile(pFile, buf, msgLen);
if (msgLen != readSize) { if (msgLen != readSize) {
truncateFile = true; truncateFile = true;
taosPrintLog(flags, level, dflag, "failed to read file:%s,%p wlen:%" PRId64 " tlen:%" PRId64 " since %s", taosPrintLog(flags, level, dflag, "failed to read file:%s,%p wlen:%" PRId64 " tlen:%" PRId64 " since %s", filepath,
filepath, pFile, readSize, msgLen, terrstr()); pFile, readSize, msgLen, terrstr());
goto _return; goto _return;
} }
......
...@@ -60,6 +60,7 @@ docker run \ ...@@ -60,6 +60,7 @@ docker run \
-v /root/.cargo/git:/root/.cargo/git \ -v /root/.cargo/git:/root/.cargo/git \
-v /root/go/pkg/mod:/root/go/pkg/mod \ -v /root/go/pkg/mod:/root/go/pkg/mod \
-v /root/.cache/go-build:/root/.cache/go-build \ -v /root/.cache/go-build:/root/.cache/go-build \
-v /root/.cos-local.1:/root/.cos-local.1 \
-v ${REP_REAL_PATH}/enterprise/src/plugins/taosx/target:${REP_DIR}/enterprise/src/plugins/taosx/target \ -v ${REP_REAL_PATH}/enterprise/src/plugins/taosx/target:${REP_DIR}/enterprise/src/plugins/taosx/target \
-v ${REP_REAL_PATH}/community/tools/taosws-rs/target:${REP_DIR}/community/tools/taosws-rs/target \ -v ${REP_REAL_PATH}/community/tools/taosws-rs/target:${REP_DIR}/community/tools/taosws-rs/target \
-v ${REP_REAL_PATH}/community/contrib/cJson/:${REP_DIR}/community/contrib/cJson \ -v ${REP_REAL_PATH}/community/contrib/cJson/:${REP_DIR}/community/contrib/cJson \
...@@ -88,6 +89,7 @@ docker run \ ...@@ -88,6 +89,7 @@ docker run \
-v /root/.cargo/git:/root/.cargo/git \ -v /root/.cargo/git:/root/.cargo/git \
-v /root/go/pkg/mod:/root/go/pkg/mod \ -v /root/go/pkg/mod:/root/go/pkg/mod \
-v /root/.cache/go-build:/root/.cache/go-build \ -v /root/.cache/go-build:/root/.cache/go-build \
-v /root/.cos-local.1:/root/.cos-local.1 \
-v ${REP_REAL_PATH}/enterprise/src/plugins/taosx/target:${REP_DIR}/enterprise/src/plugins/taosx/target \ -v ${REP_REAL_PATH}/enterprise/src/plugins/taosx/target:${REP_DIR}/enterprise/src/plugins/taosx/target \
-v ${REP_REAL_PATH}/community/tools/taosws-rs/target:${REP_DIR}/community/tools/taosws-rs/target \ -v ${REP_REAL_PATH}/community/tools/taosws-rs/target:${REP_DIR}/community/tools/taosws-rs/target \
-v ${REP_REAL_PATH}/community/contrib/cJson/:${REP_DIR}/community/contrib/cJson \ -v ${REP_REAL_PATH}/community/contrib/cJson/:${REP_DIR}/community/contrib/cJson \
......
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#define _XOPEN_SOURCE #define _XOPEN_SOURCE
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "shellInt.h"
#include "shellAuto.h"
#include "geosWrapper.h" #include "geosWrapper.h"
#include "shellAuto.h"
#include "shellInt.h"
static bool shellIsEmptyCommand(const char *cmd); static bool shellIsEmptyCommand(const char *cmd);
static int32_t shellRunSingleCommand(char *command); static int32_t shellRunSingleCommand(char *command);
...@@ -143,7 +143,7 @@ int32_t shellRunCommand(char *command, bool recordHistory) { ...@@ -143,7 +143,7 @@ int32_t shellRunCommand(char *command, bool recordHistory) {
} }
// add help or help; // add help or help;
if(strncasecmp(command, "help;", 5) == 0) { if (strncasecmp(command, "help;", 5) == 0) {
showHelp(); showHelp();
return 0; return 0;
} }
...@@ -223,14 +223,14 @@ void shellRunSingleCommandImp(char *command) { ...@@ -223,14 +223,14 @@ void shellRunSingleCommandImp(char *command) {
} }
// pre string // pre string
char * pre = "Query OK"; char *pre = "Query OK";
if (shellRegexMatch(command, "^\\s*delete\\s*from\\s*.*", REG_EXTENDED | REG_ICASE)) { if (shellRegexMatch(command, "^\\s*delete\\s*from\\s*.*", REG_EXTENDED | REG_ICASE)) {
pre = "Delete OK"; pre = "Delete OK";
} else if(shellRegexMatch(command, "^\\s*insert\\s*into\\s*.*", REG_EXTENDED | REG_ICASE)) { } else if (shellRegexMatch(command, "^\\s*insert\\s*into\\s*.*", REG_EXTENDED | REG_ICASE)) {
pre = "Insert OK"; pre = "Insert OK";
} else if(shellRegexMatch(command, "^\\s*create\\s*.*", REG_EXTENDED | REG_ICASE)) { } else if (shellRegexMatch(command, "^\\s*create\\s*.*", REG_EXTENDED | REG_ICASE)) {
pre = "Create OK"; pre = "Create OK";
} else if(shellRegexMatch(command, "^\\s*drop\\s*.*", REG_EXTENDED | REG_ICASE)) { } else if (shellRegexMatch(command, "^\\s*drop\\s*.*", REG_EXTENDED | REG_ICASE)) {
pre = "Drop OK"; pre = "Drop OK";
} }
...@@ -387,8 +387,7 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i ...@@ -387,8 +387,7 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_JSON: case TSDB_DATA_TYPE_JSON: {
{
int32_t bufIndex = 0; int32_t bufIndex = 0;
for (int32_t i = 0; i < length; i++) { for (int32_t i = 0; i < length; i++) {
buf[bufIndex] = val[i]; buf[bufIndex] = val[i];
...@@ -401,8 +400,7 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i ...@@ -401,8 +400,7 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i
buf[bufIndex] = 0; buf[bufIndex] = 0;
taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr); taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr);
} } break;
break;
case TSDB_DATA_TYPE_GEOMETRY: case TSDB_DATA_TYPE_GEOMETRY:
shellDumpHexValue(buf, val, length); shellDumpHexValue(buf, val, length);
taosFprintfFile(pFile, "%s", buf); taosFprintfFile(pFile, "%s", buf);
...@@ -535,12 +533,10 @@ void shellPrintString(const char *str, int32_t width) { ...@@ -535,12 +533,10 @@ void shellPrintString(const char *str, int32_t width) {
if (width == 0) { if (width == 0) {
printf("%s", str); printf("%s", str);
} } else if (len > width) {
else if (len > width) {
if (width <= 3) { if (width <= 3) {
printf("%.*s.", width - 1, str); printf("%.*s.", width - 1, str);
} } else {
else {
printf("%.*s...", width - 3, str); printf("%.*s...", width - 3, str);
} }
} else { } else {
...@@ -549,7 +545,7 @@ void shellPrintString(const char *str, int32_t width) { ...@@ -549,7 +545,7 @@ void shellPrintString(const char *str, int32_t width) {
} }
void shellPrintGeometry(const unsigned char *val, int32_t length, int32_t width) { void shellPrintGeometry(const unsigned char *val, int32_t length, int32_t width) {
if (length == 0) { //empty value if (length == 0) { // empty value
shellPrintString("", width); shellPrintString("", width);
return; return;
} }
...@@ -565,7 +561,7 @@ void shellPrintGeometry(const unsigned char *val, int32_t length, int32_t width) ...@@ -565,7 +561,7 @@ void shellPrintGeometry(const unsigned char *val, int32_t length, int32_t width)
char *outputWKT = NULL; char *outputWKT = NULL;
code = doAsText(val, length, &outputWKT); code = doAsText(val, length, &outputWKT);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
shellPrintString(getThreadLocalGeosCtx()->errMsg, width); //should NOT happen shellPrintString(getThreadLocalGeosCtx()->errMsg, width); // should NOT happen
return; return;
} }
...@@ -612,12 +608,11 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t ...@@ -612,12 +608,11 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t
break; break;
case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_FLOAT:
if (tsEnableScience) { if (tsEnableScience) {
printf("%*.7e",width,GET_FLOAT_VAL(val)); printf("%*.7e", width, GET_FLOAT_VAL(val));
} else { } else {
n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.7f", width, GET_FLOAT_VAL(val)); n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.7f", width, GET_FLOAT_VAL(val));
if (n > SHELL_FLOAT_WIDTH) { if (n > SHELL_FLOAT_WIDTH) {
printf("%*.7e", width, GET_FLOAT_VAL(val));
printf("%*.7e", width,GET_FLOAT_VAL(val));
} else { } else {
printf("%s", buf); printf("%s", buf);
} }
...@@ -625,14 +620,14 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t ...@@ -625,14 +620,14 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t
break; break;
case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_DOUBLE:
if (tsEnableScience) { if (tsEnableScience) {
snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.15e", width,GET_DOUBLE_VAL(val)); snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.15e", width, GET_DOUBLE_VAL(val));
printf("%s", buf); printf("%s", buf);
} else { } else {
n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.15f", width, GET_DOUBLE_VAL(val)); n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.15f", width, GET_DOUBLE_VAL(val));
if (n > SHELL_DOUBLE_WIDTH) { if (n > SHELL_DOUBLE_WIDTH) {
printf("%*.15e", width, GET_DOUBLE_VAL(val)); printf("%*.15e", width, GET_DOUBLE_VAL(val));
} else { } else {
printf("%*s", width,buf); printf("%*s", width, buf);
} }
} }
break; break;
...@@ -922,7 +917,7 @@ void shellReadHistory() { ...@@ -922,7 +917,7 @@ void shellReadHistory() {
taosMemoryFreeClear(line); taosMemoryFreeClear(line);
taosCloseFile(&pFile); taosCloseFile(&pFile);
int64_t file_size; int64_t file_size;
if (taosStatFile(pHistory->file, &file_size, NULL) == 0 && file_size > SHELL_MAX_COMMAND_SIZE) { if (taosStatFile(pHistory->file, &file_size, NULL, NULL) == 0 && file_size > SHELL_MAX_COMMAND_SIZE) {
TdFilePtr pFile = taosOpenFile(pHistory->file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_STREAM | TD_FILE_TRUNC); TdFilePtr pFile = taosOpenFile(pHistory->file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_STREAM | TD_FILE_TRUNC);
if (pFile == NULL) return; if (pFile == NULL) return;
int32_t endIndex = pHistory->hstart; int32_t endIndex = pHistory->hstart;
...@@ -991,7 +986,7 @@ void shellSourceFile(const char *file) { ...@@ -991,7 +986,7 @@ void shellSourceFile(const char *file) {
tstrncpy(fullname, file, PATH_MAX); tstrncpy(fullname, file, PATH_MAX);
} }
sprintf(sourceFileCommand, "source %s;",fullname); sprintf(sourceFileCommand, "source %s;", fullname);
shellRecordCommandToHistory(sourceFileCommand); shellRecordCommandToHistory(sourceFileCommand);
TdFilePtr pFile = taosOpenFile(fullname, TD_FILE_READ | TD_FILE_STREAM); TdFilePtr pFile = taosOpenFile(fullname, TD_FILE_READ | TD_FILE_STREAM);
...@@ -1044,7 +1039,8 @@ void shellGetGrantInfo() { ...@@ -1044,7 +1039,8 @@ void shellGetGrantInfo() {
int32_t code = taos_errno(tres); int32_t code = taos_errno(tres);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
if (code != TSDB_CODE_OPS_NOT_SUPPORT && code != TSDB_CODE_MND_NO_RIGHTS && code != TSDB_CODE_PAR_PERMISSION_DENIED) { if (code != TSDB_CODE_OPS_NOT_SUPPORT && code != TSDB_CODE_MND_NO_RIGHTS &&
code != TSDB_CODE_PAR_PERMISSION_DENIED) {
fprintf(stderr, "Failed to check Server Edition, Reason:0x%04x:%s\r\n\r\n", code, taos_errstr(tres)); fprintf(stderr, "Failed to check Server Edition, Reason:0x%04x:%s\r\n\r\n", code, taos_errstr(tres));
} }
return; return;
...@@ -1080,7 +1076,8 @@ void shellGetGrantInfo() { ...@@ -1080,7 +1076,8 @@ void shellGetGrantInfo() {
} else if (strcmp(expiretime, "unlimited") == 0) { } else if (strcmp(expiretime, "unlimited") == 0) {
fprintf(stdout, "Server is Enterprise %s Edition, %s and will never expire.\r\n", serverVersion, sinfo); fprintf(stdout, "Server is Enterprise %s Edition, %s and will never expire.\r\n", serverVersion, sinfo);
} else { } else {
fprintf(stdout, "Server is Enterprise %s Edition, %s and will expire at %s.\r\n", serverVersion, sinfo, expiretime); fprintf(stdout, "Server is Enterprise %s Edition, %s and will expire at %s.\r\n", serverVersion, sinfo,
expiretime);
} }
taos_free_result(tres); taos_free_result(tres);
...@@ -1123,9 +1120,9 @@ void *shellCancelHandler(void *arg) { ...@@ -1123,9 +1120,9 @@ void *shellCancelHandler(void *arg) {
#ifdef WEBSOCKET #ifdef WEBSOCKET
} }
#endif #endif
#ifdef WINDOWS #ifdef WINDOWS
printf("\n%s", shell.info.promptHeader); printf("\n%s", shell.info.promptHeader);
#endif #endif
} }
return NULL; return NULL;
...@@ -1165,8 +1162,7 @@ void *shellThreadLoop(void *arg) { ...@@ -1165,8 +1162,7 @@ void *shellThreadLoop(void *arg) {
} }
int32_t shellExecute() { int32_t shellExecute() {
printf(shell.info.clientVersion, shell.info.cusName, printf(shell.info.clientVersion, shell.info.cusName, taos_get_client_info(), shell.info.cusName);
taos_get_client_info(), shell.info.cusName);
fflush(stdout); fflush(stdout);
SShellArgs *pArgs = &shell.args; SShellArgs *pArgs = &shell.args;
......
...@@ -221,7 +221,7 @@ int64_t getDirectorySize(char* dir) { ...@@ -221,7 +221,7 @@ int64_t getDirectorySize(char* dir) {
totalSize += subDirSize; totalSize += subDirSize;
} else if (0 == strcmp(strchr(fileName, '.'), ".log")) { // only calc .log file size, and not include .idx file } else if (0 == strcmp(strchr(fileName, '.'), ".log")) { // only calc .log file size, and not include .idx file
int64_t file_size = 0; int64_t file_size = 0;
taosStatFile(subdir, &file_size, NULL); taosStatFile(subdir, &file_size, NULL, NULL);
totalSize += file_size; totalSize += file_size;
} }
} }
...@@ -702,4 +702,3 @@ int main(int32_t argc, char* argv[]) { ...@@ -702,4 +702,3 @@ int main(int32_t argc, char* argv[]) {
taosCloseFile(&g_fp); taosCloseFile(&g_fp);
return 0; return 0;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册