提交 65d8af19 编写于 作者: M Minglei Jin

s3: new api s3Size

上级 87783a96
......@@ -29,9 +29,9 @@ void s3CleanUp();
void s3PutObjectFromFile(const char *file, const char *object);
void s3DeleteObjects(const char *object_name[], int nobject);
bool s3Exists(const char *object_name);
void s3Get(const char *object_name, const char *path);
bool s3Get(const char *object_name, const char *path);
void s3EvictCache();
long s3Size(const char *object_name);
#ifdef __cplusplus
}
#endif
......
......@@ -36,7 +36,8 @@ int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsdbFD **p
pFD->pFD = taosOpenFile(path, flag);
if (pFD->pFD == NULL) {
const char *object_name = taosDirEntryBaseName((char *)path);
if (!strncmp(path + strlen(path) - 5, ".data", 5) && s3Exists(object_name)) {
long s3_size = s3Size(object_name);
if (!strncmp(path + strlen(path) - 5, ".data", 5) && s3_size > 0) {
s3EvictCache();
s3Get(object_name, path);
......
......@@ -147,7 +147,8 @@ bool s3Exists(const char *object_name) {
return ret;
}
void s3Get(const char *object_name, const char *path) {
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;
......@@ -177,6 +178,7 @@ void s3Get(const char *object_name, const char *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");
......@@ -184,6 +186,47 @@ void s3Get(const char *object_name, const char *path) {
//销毁内存池
cos_pool_destroy(p);
return ret;
}
void s3EvictCache() {}
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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册