diff --git a/cache/cache_evbase_client.cpp b/cache/cache_evbase_client.cpp index 675a169..c4e68c4 100644 --- a/cache/cache_evbase_client.cpp +++ b/cache/cache_evbase_client.cpp @@ -57,9 +57,9 @@ struct tango_cache_result *cache_evbase_read_result(void *promise_result) return tango_cache_read_result(promise_result); } -const char *cache_evbase_get_object_key(struct cache_evbase_ctx *ctx_asyn) +void cache_evbase_get_object_path(const struct cache_evbase_ctx *ctx_asyn, char *path, size_t pathsize) { - return tango_cache_get_object_key(ctx_asyn->ctx); + tango_cache_get_object_path(ctx_asyn->ctx, path, pathsize); } static int create_notification_pipe(evutil_socket_t sv[2]) @@ -344,7 +344,7 @@ struct cache_evbase_ctx *cache_evbase_update_start(struct cache_evbase_instance } int cache_evbase_upload_once_data(struct cache_evbase_instance *instance, struct future* future, - enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, struct tango_cache_meta *meta, char *objectkey, size_t keysize) + enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, struct tango_cache_meta *meta, char *path, size_t pathsize) { struct cache_evbase_ctx *ctx_asyn; struct tango_cache_ctx *ctx; @@ -355,9 +355,9 @@ int cache_evbase_upload_once_data(struct cache_evbase_instance *instance, struct { return -1; } - if(objectkey != NULL) + if(path != NULL) { - snprintf(objectkey, keysize, "%s", ctx->object_key); + snprintf(path, pathsize, "http://%s/%s/%s", ctx->hostaddr, instance->instance->bucketname, ctx->object_key); } ctx_asyn = (struct cache_evbase_ctx *)calloc(1, sizeof(struct cache_evbase_ctx)); @@ -390,7 +390,7 @@ int cache_evbase_upload_once_data(struct cache_evbase_instance *instance, struct } int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struct future* future, - struct evbuffer *evbuf, struct tango_cache_meta *meta, char *objectkey, size_t keysize) + struct evbuffer *evbuf, struct tango_cache_meta *meta, char *path, size_t pathsize) { struct cache_evbase_ctx *ctx_asyn; struct tango_cache_ctx *ctx; @@ -401,9 +401,9 @@ int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struc { return -1; } - if(objectkey != NULL) + if(path != NULL) { - snprintf(objectkey, keysize, "%s", ctx->object_key); + snprintf(path, pathsize, "http://%s/%s/%s", ctx->hostaddr, instance->instance->bucketname, ctx->object_key); } ctx_asyn = (struct cache_evbase_ctx *)calloc(1, sizeof(struct cache_evbase_ctx)); diff --git a/cache/include/cache_evbase_client.h b/cache/include/cache_evbase_client.h index 83d0534..01bbca4 100644 --- a/cache/include/cache_evbase_client.h +++ b/cache/include/cache_evbase_client.h @@ -41,11 +41,11 @@ int cache_evbase_delete_object(struct cache_evbase_instance *instance, struct fu int cache_evbase_upload_once_data(struct cache_evbase_instance *instance, struct future* future, enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, struct tango_cache_meta *meta, - char *objectkey, size_t keysize); + char *path, size_t pathsize); int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struct future* future, struct evbuffer *evbuf, struct tango_cache_meta *meta, - char *objectkey, size_t keysize); + char *path, size_t pathsize); //流式上传接口 struct cache_evbase_ctx *cache_evbase_update_start(struct cache_evbase_instance *instance, struct future* future, struct tango_cache_meta *meta); @@ -53,7 +53,7 @@ int cache_evbase_update_frag_data(struct cache_evbase_ctx *ctx_asyn, enum PUT_ME int cache_evbase_update_frag_evbuf(struct cache_evbase_ctx *ctx_asyn, struct evbuffer *evbuf); void cache_evbase_update_end(struct cache_evbase_ctx *ctx_asyn); -const char *cache_evbase_get_object_key(struct cache_evbase_ctx *ctx_asyn); +void cache_evbase_get_object_path(const struct cache_evbase_ctx *ctx, char *path, size_t pathsize); #endif diff --git a/cache/include/tango_cache_client.h b/cache/include/tango_cache_client.h index 218332b..bcd2f63 100644 --- a/cache/include/tango_cache_client.h +++ b/cache/include/tango_cache_client.h @@ -113,16 +113,16 @@ int tango_cache_delete_object(struct tango_cache_instance *instance, struct futu */ /*完整一次上传API*/ -//若objectkey不为空,则输出对象的KEY,当CACHE_OBJECT_KEY_HASH_SWITCH=1开启对文件名哈希时有用; +//若path不为空,则输出对象的存储路径 //返回值: 0-成功;<0失败;下同 int tango_cache_upload_once_data(struct tango_cache_instance *instance, struct future* future, enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, struct tango_cache_meta *meta, - char *objectkey, size_t keysize); + char *path, size_t pathsize); int tango_cache_upload_once_evbuf(struct tango_cache_instance *instance, struct future* future, enum EVBUFFER_COPY_WAY way, struct evbuffer *evbuf, struct tango_cache_meta *meta, - char *objectkey, size_t keysize); + char *path, size_t pathsize); /*流式上传API*/ //返回值: 若为NULL则表示创建失败,调用tango_cache_ctx_error查看错误码是否是CACHE_OUTOF_MEMORY(正常情况下是); struct tango_cache_ctx *tango_cache_update_start(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta); @@ -132,7 +132,7 @@ int tango_cache_update_frag_evbuf(struct tango_cache_ctx *ctx, enum EVBUFFER_COP void tango_cache_update_end(struct tango_cache_ctx *ctx); //获取对象key值;当CACHE_OBJECT_KEY_HASH_SWITCH=1开启对URL/文件名哈希时有用 -const char *tango_cache_get_object_key(struct tango_cache_ctx *ctx); +void tango_cache_get_object_path(const struct tango_cache_ctx *ctx, char *path, size_t pathsize); #endif diff --git a/cache/pangu_tango_cache.a b/cache/pangu_tango_cache.a new file mode 100644 index 0000000..39442a1 Binary files /dev/null and b/cache/pangu_tango_cache.a differ diff --git a/cache/tango_cache_client.cpp b/cache/tango_cache_client.cpp index 3b7317b..3e76f64 100644 --- a/cache/tango_cache_client.cpp +++ b/cache/tango_cache_client.cpp @@ -63,9 +63,9 @@ struct tango_cache_result *tango_cache_read_result(void *promise_result) return (struct tango_cache_result *)promise_result; } -const char *tango_cache_get_object_key(struct tango_cache_ctx *ctx) +void tango_cache_get_object_path(const struct tango_cache_ctx *ctx, char *path, size_t pathsize) { - return ctx->object_key; + snprintf(path, pathsize, "http://%s/%s/%s", ctx->hostaddr, ctx->instance->bucketname, ctx->object_key); } static inline void update_statistics(enum CACHE_REQUEST_METHOD method, bool fail_state, enum CACHE_ERR_CODE error_code, struct cache_statistics *statistic) @@ -262,6 +262,7 @@ struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance * { snprintf(ctx->object_key, 256, "%s", meta->url); } + sprintf(ctx->hostaddr, "%s", instance->minio_hostlist); //Expires字段,用于缓存内部判定缓存是否超时 now = time(NULL); @@ -319,7 +320,7 @@ struct tango_cache_ctx *tango_cache_update_start(struct tango_cache_instance *in } int tango_cache_upload_once_data(struct tango_cache_instance *instance, struct future* future, - enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, struct tango_cache_meta *meta, char *objectkey, size_t keysize) + enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, struct tango_cache_meta *meta, char *path, size_t pathsize) { struct tango_cache_ctx *ctx; @@ -328,16 +329,16 @@ int tango_cache_upload_once_data(struct tango_cache_instance *instance, struct f { return -1; } - if(objectkey != NULL) + if(path != NULL) { - snprintf(objectkey, keysize, "%s", ctx->object_key); + snprintf(path, pathsize, "http://%s/%s/%s", ctx->hostaddr, instance->bucketname, ctx->object_key); } return tango_cache_upload_once_start_data(ctx, way, data, size); } int tango_cache_upload_once_evbuf(struct tango_cache_instance *instance, struct future* future, - enum EVBUFFER_COPY_WAY way, struct evbuffer *evbuf, struct tango_cache_meta *meta, char *objectkey, size_t keysize) + enum EVBUFFER_COPY_WAY way, struct evbuffer *evbuf, struct tango_cache_meta *meta, char *path, size_t pathsize) { struct tango_cache_ctx *ctx; @@ -346,9 +347,9 @@ int tango_cache_upload_once_evbuf(struct tango_cache_instance *instance, struct { return -1; } - if(objectkey != NULL) + if(path != NULL) { - snprintf(objectkey, keysize, "%s", ctx->object_key); + snprintf(path, pathsize, "http://%s/%s/%s", ctx->hostaddr, instance->bucketname, ctx->object_key); } return tango_cache_upload_once_start_evbuf(ctx, way, evbuf); @@ -377,6 +378,7 @@ struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *i { snprintf(ctx->object_key, 256, "%s", meta->url); } + sprintf(ctx->hostaddr, "%s", instance->minio_hostlist); return ctx; } @@ -405,6 +407,7 @@ struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance * { snprintf(ctx->object_key, 256, "%s", objkey); } + sprintf(ctx->hostaddr, "%s", instance->minio_hostlist); return ctx; } diff --git a/cache/tango_cache_client_in.h b/cache/tango_cache_client_in.h index dadb14e..bf32947 100644 --- a/cache/tango_cache_client_in.h +++ b/cache/tango_cache_client_in.h @@ -98,6 +98,7 @@ struct tango_cache_ctx struct future* future; char error[CURL_ERROR_SIZE]; char object_key[256]; + char hostaddr[24]; enum CACHE_REQUEST_METHOD method; enum CACHE_ERR_CODE error_code; diff --git a/cache/tango_cache_transfer.cpp b/cache/tango_cache_transfer.cpp index ed0bb6e..9a4b1af 100644 --- a/cache/tango_cache_transfer.cpp +++ b/cache/tango_cache_transfer.cpp @@ -110,11 +110,11 @@ static int http_put_bodypart_request_evbuf(struct tango_cache_ctx *ctx, bool ful ctx->put.upload_offset = 0; if(full) { - snprintf(minio_url, 256, "http://%s/%s/%s", ctx->instance->minio_hostlist, ctx->instance->bucketname, ctx->object_key); + snprintf(minio_url, 256, "http://%s/%s/%s", ctx->hostaddr, ctx->instance->bucketname, ctx->object_key); } else { - snprintf(minio_url, 256, "http://%s/%s/%s?partNumber=%d&uploadId=%s", ctx->instance->minio_hostlist, ctx->instance->bucketname, ctx->object_key, ++ctx->put.part_index, ctx->put.uploadID); + snprintf(minio_url, 256, "http://%s/%s/%s?partNumber=%d&uploadId=%s", ctx->hostaddr, ctx->instance->bucketname, ctx->object_key, ++ctx->put.part_index, ctx->put.uploadID); curl_easy_setopt(ctx->curl, CURLOPT_HEADERFUNCTION, curl_put_multipart_header_cb); curl_easy_setopt(ctx->curl, CURLOPT_HEADERDATA, ctx); } @@ -179,7 +179,7 @@ int curl_get_minio_uploadID(struct tango_cache_ctx *ctx) return -1; } - snprintf(minio_url, 256, "http://%s/%s/%s?uploads", ctx->instance->minio_hostlist, ctx->instance->bucketname, ctx->object_key); + snprintf(minio_url, 256, "http://%s/%s/%s?uploads", ctx->hostaddr, ctx->instance->bucketname, ctx->object_key); curl_easy_setopt(ctx->curl, CURLOPT_POST, 1L); curl_easy_setopt(ctx->curl, CURLOPT_URL, minio_url); curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, "aws-sdk-cpp/1.5.24 Linux/3.10.0-327.el7.x86_64 x86_64 pangu_cache"); @@ -209,7 +209,7 @@ int cache_delete_minio_object(struct tango_cache_ctx *ctx) return 0; } - snprintf(minio_url, 256, "http://%s/%s/%s", ctx->instance->minio_hostlist, ctx->instance->bucketname, ctx->object_key); + snprintf(minio_url, 256, "http://%s/%s/%s", ctx->hostaddr, ctx->instance->bucketname, ctx->object_key); curl_easy_setopt(ctx->curl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_easy_setopt(ctx->curl, CURLOPT_URL, minio_url); curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, "aws-sdk-cpp/1.5.24 Linux/3.10.0-327.el7.x86_64 x86_64 pangu_cache"); @@ -237,7 +237,7 @@ bool cache_cancel_upload_minio(struct tango_cache_ctx *ctx) return false; } - snprintf(minio_url, 256, "http://%s/%s/%s?uploadId=%s", ctx->instance->minio_hostlist, ctx->instance->bucketname, ctx->object_key, ctx->put.uploadID); + snprintf(minio_url, 256, "http://%s/%s/%s?uploadId=%s", ctx->hostaddr, ctx->instance->bucketname, ctx->object_key, ctx->put.uploadID); curl_easy_setopt(ctx->curl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_easy_setopt(ctx->curl, CURLOPT_URL, minio_url); curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, "aws-sdk-cpp/1.5.24 Linux/3.10.0-327.el7.x86_64 x86_64 pangu_cache"); @@ -267,7 +267,7 @@ bool cache_kick_combine_minio(struct tango_cache_ctx *ctx) } construct_complete_xml(ctx, &ctx->put.combine_xml, &len); - snprintf(minio_url, 256, "http://%s/%s/%s?uploadId=%s", ctx->instance->minio_hostlist, ctx->instance->bucketname, ctx->object_key, ctx->put.uploadID); + snprintf(minio_url, 256, "http://%s/%s/%s?uploadId=%s", ctx->hostaddr, ctx->instance->bucketname, ctx->object_key, ctx->put.uploadID); curl_easy_setopt(ctx->curl, CURLOPT_POST, 1L); curl_easy_setopt(ctx->curl, CURLOPT_URL, minio_url); curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, "aws-sdk-cpp/1.5.24 Linux/3.10.0-327.el7.x86_64 x86_64 pangu_cache"); @@ -516,7 +516,7 @@ int tango_cache_upload_once_start_data(struct tango_cache_ctx *ctx, enum PUT_MEM } ctx->put.state = PUT_STATE_END; - snprintf(minio_url, 256, "http://%s/%s/%s", ctx->instance->minio_hostlist, ctx->instance->bucketname, ctx->object_key); + snprintf(minio_url, 256, "http://%s/%s/%s", ctx->hostaddr, ctx->instance->bucketname, ctx->object_key); curl_easy_setopt(ctx->curl, CURLOPT_URL, minio_url); curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, "aws-sdk-cpp/1.5.24 Linux/3.10.0-327.el7.x86_64 x86_64 pangu_cache"); curl_easy_setopt(ctx->curl, CURLOPT_NOSIGNAL, 1L); @@ -797,7 +797,7 @@ int tango_cache_fetch_start(struct tango_cache_ctx *ctx) return -1; } - snprintf(minio_url, 256, "http://%s/%s/%s", ctx->instance->minio_hostlist, ctx->instance->bucketname, ctx->object_key); + snprintf(minio_url, 256, "http://%s/%s/%s", ctx->hostaddr, ctx->instance->bucketname, ctx->object_key); curl_easy_setopt(ctx->curl, CURLOPT_URL, minio_url); curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, "aws-sdk-cpp/1.5.24 Linux/3.10.0-327.el7.x86_64 x86_64 pangu_cache"); curl_easy_setopt(ctx->curl, CURLOPT_NOSIGNAL,1L); diff --git a/cache/test_demo/cache_evbase_test.cpp b/cache/test_demo/cache_evbase_test.cpp index 172041e..025a5a4 100644 --- a/cache/test_demo/cache_evbase_test.cpp +++ b/cache/test_demo/cache_evbase_test.cpp @@ -245,7 +245,7 @@ int main(int argc, char **argv) promise_set_ctx(future_to_promise(pdata->future), NULL, NULL); ctx = cache_evbase_update_start(instance_asyn, pdata->future, &meta); - sprintf(pdata->filename, "%s", cache_evbase_get_object_key(ctx)); + cache_evbase_get_object_path(ctx, pdata->filename, 256); char buffer[1024]; FILE *fp = fopen(filename_in, "r"); diff --git a/cache/test_demo/tango_cache_test.c b/cache/test_demo/tango_cache_test.c index ce8f16d..679f4ec 100644 --- a/cache/test_demo/tango_cache_test.c +++ b/cache/test_demo/tango_cache_test.c @@ -213,7 +213,7 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg) promise_set_ctx(future_to_promise(pdata->future), NULL, NULL); ctx = tango_cache_update_start(tango_instance, pdata->future, &meta); - sprintf(pdata->filename, "%s", tango_cache_get_object_key(ctx)); + tango_cache_get_object_path(ctx, pdata->filename, 256); FILE *fp = fopen(s, "r"); while(!feof(fp))