修改GET/PUT对外接口;cache miss不算fail;
This commit is contained in:
30
cache/src/cache_evbase_client.cpp
vendored
30
cache/src/cache_evbase_client.cpp
vendored
@@ -325,13 +325,13 @@ int cache_evbase_update_frag_evbuf(struct cache_evbase_ctx *ctx_asyn, struct evb
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct cache_evbase_ctx *cache_evbase_update_start(struct cache_evbase_instance *instance, struct future* future, struct tango_cache_meta *meta)
|
||||
struct cache_evbase_ctx *cache_evbase_update_start(struct cache_evbase_instance *instance, struct future* f, struct tango_cache_meta_put *meta)
|
||||
{
|
||||
struct cache_evbase_ctx *ctx_asyn;
|
||||
struct tango_cache_ctx *ctx;
|
||||
struct databuffer *buffer;
|
||||
|
||||
ctx = tango_cache_update_prepare(instance->instance, future, meta);
|
||||
ctx = tango_cache_update_prepare(instance->instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return NULL;
|
||||
@@ -357,14 +357,14 @@ struct cache_evbase_ctx *cache_evbase_update_start(struct cache_evbase_instance
|
||||
return ctx_asyn;
|
||||
}
|
||||
|
||||
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 *path, size_t pathsize)
|
||||
int cache_evbase_upload_once_data(struct cache_evbase_instance *instance, struct future* f,
|
||||
enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, struct tango_cache_meta_put *meta, char *path, size_t pathsize)
|
||||
{
|
||||
struct cache_evbase_ctx *ctx_asyn;
|
||||
struct tango_cache_ctx *ctx;
|
||||
struct databuffer *buffer;
|
||||
|
||||
ctx = tango_cache_update_prepare(instance->instance, future, meta);
|
||||
ctx = tango_cache_update_prepare(instance->instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -404,14 +404,14 @@ int cache_evbase_upload_once_data(struct cache_evbase_instance *instance, struct
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struct future* future,
|
||||
struct evbuffer *evbuf, struct tango_cache_meta *meta, char *path, size_t pathsize)
|
||||
int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struct future* f,
|
||||
struct evbuffer *evbuf, struct tango_cache_meta_put *meta, char *path, size_t pathsize)
|
||||
{
|
||||
struct cache_evbase_ctx *ctx_asyn;
|
||||
struct tango_cache_ctx *ctx;
|
||||
struct databuffer *buffer;
|
||||
|
||||
ctx = tango_cache_update_prepare(instance->instance, future, meta);
|
||||
ctx = tango_cache_update_prepare(instance->instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -443,14 +443,14 @@ int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struc
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cache_evbase_fetch_object(struct cache_evbase_instance *instance, struct future* future, struct tango_cache_meta *meta)
|
||||
int cache_evbase_fetch_object(struct cache_evbase_instance *instance, struct future* f, struct tango_cache_meta_get *meta)
|
||||
{
|
||||
struct cache_evbase_ctx *ctx_asyn;
|
||||
struct databuffer *buffer;
|
||||
|
||||
ctx_asyn = (struct cache_evbase_ctx *)calloc(1, sizeof(struct cache_evbase_ctx));
|
||||
ctx_asyn->instance_asyn = instance;
|
||||
ctx_asyn->ctx = tango_cache_fetch_prepare(instance->instance, future, meta);
|
||||
ctx_asyn->ctx = tango_cache_fetch_prepare(instance->instance, f, meta);
|
||||
if(ctx_asyn->ctx == NULL)
|
||||
{
|
||||
free(ctx_asyn);
|
||||
@@ -464,7 +464,7 @@ int cache_evbase_fetch_object(struct cache_evbase_instance *instance, struct fut
|
||||
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 2) != sizeof(void *))
|
||||
{
|
||||
tango_cache_set_fail_state(ctx_asyn->ctx, CACHE_ERR_SOCKPAIR);
|
||||
promise_failed(future_to_promise(future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx_asyn->ctx));
|
||||
promise_failed(future_to_promise(f), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx_asyn->ctx));
|
||||
tango_cache_ctx_destroy(ctx_asyn->ctx);
|
||||
cache_asyn_ctx_destroy(ctx_asyn);
|
||||
free(buffer);
|
||||
@@ -473,14 +473,14 @@ int cache_evbase_fetch_object(struct cache_evbase_instance *instance, struct fut
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cache_evbase_delete_object(struct cache_evbase_instance *instance, struct future* future, const char *objkey)
|
||||
int cache_evbase_delete_object(struct cache_evbase_instance *instance, struct future* f, const char *objkey)
|
||||
{
|
||||
struct cache_evbase_ctx *ctx_asyn;
|
||||
struct databuffer *buffer;
|
||||
|
||||
ctx_asyn = (struct cache_evbase_ctx *)calloc(1, sizeof(struct cache_evbase_ctx));
|
||||
ctx_asyn->instance_asyn = instance;
|
||||
ctx_asyn->ctx = tango_cache_delete_prepare(instance->instance, future, objkey);
|
||||
ctx_asyn->ctx = tango_cache_delete_prepare(instance->instance, f, objkey);
|
||||
if(ctx_asyn->ctx == NULL)
|
||||
{
|
||||
free(ctx_asyn);
|
||||
@@ -495,9 +495,9 @@ int cache_evbase_delete_object(struct cache_evbase_instance *instance, struct fu
|
||||
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 2) != sizeof(void *))
|
||||
{
|
||||
tango_cache_set_fail_state(ctx_asyn->ctx, CACHE_ERR_SOCKPAIR);
|
||||
if(future != NULL)
|
||||
if(f != NULL)
|
||||
{
|
||||
promise_failed(future_to_promise(future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx_asyn->ctx));
|
||||
promise_failed(future_to_promise(f), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx_asyn->ctx));
|
||||
}
|
||||
tango_cache_ctx_destroy(ctx_asyn->ctx);
|
||||
cache_asyn_ctx_destroy(ctx_asyn);
|
||||
|
||||
56
cache/src/tango_cache_client.cpp
vendored
56
cache/src/tango_cache_client.cpp
vendored
@@ -87,7 +87,7 @@ const char *tango_cache_get_errstring(const struct tango_cache_ctx *ctx)
|
||||
case CACHE_OUTOF_MEMORY:return "outof memory";
|
||||
case CACHE_ERR_WIREDLB: return "wiredlb error";
|
||||
case CACHE_ERR_SOCKPAIR:return "socketpair error";
|
||||
case CACHE_ERR_INTERNAL:return "cache Expires or x-amz-meta-lm not found";
|
||||
case CACHE_ERR_INTERNAL:return "internal error";
|
||||
default: return ctx->error;
|
||||
}
|
||||
}
|
||||
@@ -136,10 +136,10 @@ static void update_statistics(struct tango_cache_ctx *ctx, struct cache_statisti
|
||||
case CACHE_REQUEST_GET:
|
||||
if(ctx->fail_state)
|
||||
{
|
||||
if(ctx->error_code == CACHE_ERR_CURL)
|
||||
statistic->get_error_num += 1;
|
||||
else
|
||||
if(ctx->error_code == CACHE_CACHE_MISS || ctx->error_code == CACHE_TIMEOUT)
|
||||
statistic->get_miss_num += 1;
|
||||
else
|
||||
statistic->get_error_num += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -297,7 +297,7 @@ int tango_cache_update_frag_evbuf(struct tango_cache_ctx *ctx, enum EVBUFFER_COP
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta)
|
||||
struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta_put *meta)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
char buffer[256]={0};
|
||||
@@ -312,7 +312,7 @@ struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *
|
||||
|
||||
ctx = (struct tango_cache_ctx *)calloc(1, sizeof(struct tango_cache_ctx));
|
||||
ctx->instance = instance;
|
||||
ctx->future = future;
|
||||
ctx->future = f;
|
||||
ctx->method = CACHE_REQUEST_PUT;
|
||||
|
||||
if(instance->hash_object_key)
|
||||
@@ -375,11 +375,11 @@ struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *
|
||||
return ctx;
|
||||
}
|
||||
|
||||
struct tango_cache_ctx *tango_cache_update_start(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta)
|
||||
struct tango_cache_ctx *tango_cache_update_start(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta_put *meta)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_update_prepare(instance, future, meta);
|
||||
ctx = tango_cache_update_prepare(instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return NULL;
|
||||
@@ -389,12 +389,12 @@ struct tango_cache_ctx *tango_cache_update_start(struct tango_cache_instance *in
|
||||
return ctx;
|
||||
}
|
||||
|
||||
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 *path, size_t pathsize)
|
||||
int tango_cache_upload_once_data(struct tango_cache_instance *instance, struct future* f,
|
||||
enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, struct tango_cache_meta_put *meta, char *path, size_t pathsize)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_update_prepare(instance, future, meta);
|
||||
ctx = tango_cache_update_prepare(instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -407,12 +407,12 @@ int tango_cache_upload_once_data(struct tango_cache_instance *instance, struct f
|
||||
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 *path, size_t pathsize)
|
||||
int tango_cache_upload_once_evbuf(struct tango_cache_instance *instance, struct future* f,
|
||||
enum EVBUFFER_COPY_WAY way, struct evbuffer *evbuf, struct tango_cache_meta_put *meta, char *path, size_t pathsize)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_update_prepare(instance, future, meta);
|
||||
ctx = tango_cache_update_prepare(instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -425,14 +425,14 @@ int tango_cache_upload_once_evbuf(struct tango_cache_instance *instance, struct
|
||||
return tango_cache_upload_once_start_evbuf(ctx, way, evbuf);
|
||||
}
|
||||
|
||||
struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta)
|
||||
struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta_get *meta)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
char sha256[72]={0};
|
||||
|
||||
ctx = (struct tango_cache_ctx *)calloc(1, sizeof(struct tango_cache_ctx));
|
||||
ctx->instance = instance;
|
||||
ctx->future = future;
|
||||
ctx->future = f;
|
||||
ctx->method = CACHE_REQUEST_GET;
|
||||
ctx->get.state = GET_STATE_START;
|
||||
ctx->get.max_age = meta->get.max_age;
|
||||
@@ -457,11 +457,11 @@ struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *i
|
||||
return ctx;
|
||||
}
|
||||
|
||||
int tango_cache_fetch_object(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta)
|
||||
int tango_cache_fetch_object(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta_get *meta)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_fetch_prepare(instance, future, meta);
|
||||
ctx = tango_cache_fetch_prepare(instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -469,14 +469,14 @@ int tango_cache_fetch_object(struct tango_cache_instance *instance, struct futur
|
||||
return tango_cache_fetch_start(ctx);
|
||||
}
|
||||
|
||||
struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *instance, struct future* future, const char *objkey)
|
||||
struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *instance, struct future* f, const char *objkey)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
char sha256[72]={0};
|
||||
|
||||
ctx = (struct tango_cache_ctx *)calloc(1, sizeof(struct tango_cache_ctx));
|
||||
ctx->instance = instance;
|
||||
ctx->future = future;
|
||||
ctx->future = f;
|
||||
ctx->method = CACHE_REQUEST_DELETE;
|
||||
|
||||
if(instance->hash_object_key)
|
||||
@@ -498,11 +498,11 @@ struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *
|
||||
return ctx;
|
||||
}
|
||||
|
||||
int tango_cache_delete_object(struct tango_cache_instance *instance, struct future* future, const char *objkey)
|
||||
int tango_cache_delete_object(struct tango_cache_instance *instance, struct future* f, const char *objkey)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_delete_prepare(instance, future, objkey);
|
||||
ctx = tango_cache_delete_prepare(instance, f, objkey);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -510,14 +510,14 @@ int tango_cache_delete_object(struct tango_cache_instance *instance, struct futu
|
||||
return (cache_delete_minio_object(ctx)==1)?0:-1;
|
||||
}
|
||||
|
||||
struct tango_cache_ctx *tango_cache_multi_delete_prepare(struct tango_cache_instance *instance, struct future* future, char *objlist[], u_int32_t num)
|
||||
struct tango_cache_ctx *tango_cache_multi_delete_prepare(struct tango_cache_instance *instance, struct future* f, char *objlist[], u_int32_t num)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
char md5[48]={0}, content_md5[48];
|
||||
|
||||
ctx = (struct tango_cache_ctx *)calloc(1, sizeof(struct tango_cache_ctx));
|
||||
ctx->instance = instance;
|
||||
ctx->future = future;
|
||||
ctx->future = f;
|
||||
ctx->method = CACHE_REQUEST_DELETE_MUL;
|
||||
ctx->del.succ_num = num;
|
||||
|
||||
@@ -534,15 +534,16 @@ struct tango_cache_ctx *tango_cache_multi_delete_prepare(struct tango_cache_inst
|
||||
sprintf(content_md5, "Content-MD5: %s", md5);
|
||||
ctx->headers = curl_slist_append(ctx->headers, content_md5);
|
||||
ctx->headers = curl_slist_append(ctx->headers, "Content-Type: application/xml");
|
||||
ctx->headers = curl_slist_append(ctx->headers, "Expect:");
|
||||
return ctx;
|
||||
}
|
||||
|
||||
//TODO: AccessDenied
|
||||
int tango_cache_multi_delete(struct tango_cache_instance *instance, struct future* future, char *objlist[], u_int32_t num)
|
||||
int tango_cache_multi_delete(struct tango_cache_instance *instance, struct future* f, char *objlist[], u_int32_t num)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_multi_delete_prepare(instance, future, objlist, num);
|
||||
ctx = tango_cache_multi_delete_prepare(instance, f, objlist, num);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -752,9 +753,8 @@ static int load_local_configure(struct tango_cache_instance *instance, const cha
|
||||
MESA_load_profile_string_def(profile_path, section, "WIREDLB_GROUP", instance->wiredlb_group, 64, "KAZAKHSTAN");
|
||||
MESA_load_profile_string_def(profile_path, section, "WIREDLB_DATACENTER", instance->wiredlb_datacenter, 64, "ASTANA");
|
||||
MESA_load_profile_uint_def(profile_path, section, "WIREDLB_OVERRIDE", &instance->wiredlb_override, 1);
|
||||
|
||||
MESA_load_profile_uint_def(profile_path, section, "WIREDLB_HEALTH_PORT", &intval, 52100);
|
||||
instance->wiredlb_ha_port=(unsigned short)intval;
|
||||
instance->wiredlb_ha_port = (u_int16_t)intval;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
11
cache/src/tango_cache_client_in.h
vendored
11
cache/src/tango_cache_client_in.h
vendored
@@ -55,6 +55,7 @@ struct tango_cache_instance
|
||||
u_int32_t minio_port;
|
||||
u_int32_t wiredlb_override;
|
||||
u_int16_t wiredlb_ha_port;
|
||||
u_int32_t hash_object_key;
|
||||
struct event_base* evbase;
|
||||
struct event timer_event;
|
||||
struct cache_statistics statistic;
|
||||
@@ -66,7 +67,6 @@ struct tango_cache_instance
|
||||
long max_cnn_host;
|
||||
u_int32_t upload_block_size; //minio<69>ֶ<EFBFBD><D6B6>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
||||
enum CACHE_ERR_CODE error_code;
|
||||
u_int32_t hash_object_key;
|
||||
};
|
||||
|
||||
struct multipart_etag_list
|
||||
@@ -78,13 +78,14 @@ struct multipart_etag_list
|
||||
|
||||
struct cache_ctx_data_get
|
||||
{
|
||||
time_t max_age;//Get
|
||||
time_t min_fresh;//Get
|
||||
time_t max_age;
|
||||
time_t min_fresh;
|
||||
time_t expires;
|
||||
time_t last_modify;
|
||||
u_int32_t need_hdrs;
|
||||
enum GET_OBJECT_STATE state;
|
||||
struct easy_string response_tag;
|
||||
struct tango_cache_result result;
|
||||
};
|
||||
|
||||
struct cache_ctx_data_put
|
||||
@@ -144,8 +145,8 @@ void tango_cache_ctx_destroy(struct tango_cache_ctx *ctx);
|
||||
void tango_cache_set_fail_state(struct tango_cache_ctx *ctx, enum CACHE_ERR_CODE error_code);
|
||||
const char *tango_cache_get_errstring(const struct tango_cache_ctx *ctx);
|
||||
|
||||
struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta);
|
||||
struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta);
|
||||
struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta_put *meta);
|
||||
struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta_get *meta);
|
||||
struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *instance, struct future* future, const char *objkey);
|
||||
|
||||
#endif
|
||||
|
||||
141
cache/src/tango_cache_transfer.cpp
vendored
141
cache/src/tango_cache_transfer.cpp
vendored
@@ -647,48 +647,10 @@ int tango_cache_multi_delete_start(struct tango_cache_ctx *ctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tango_cache_curl_get_done(struct tango_cache_ctx *ctx, CURLcode res, long res_code)
|
||||
{
|
||||
switch(ctx->get.state)
|
||||
{
|
||||
case GET_STATE_START:
|
||||
if(!ctx->fail_state)
|
||||
{
|
||||
if(res!=CURLE_OK || res_code!=200L)
|
||||
{
|
||||
tango_cache_set_fail_state(ctx, (res!=CURLE_OK)?CACHE_ERR_CURL:CACHE_CACHE_MISS);
|
||||
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
|
||||
}
|
||||
else
|
||||
{
|
||||
promise_success(future_to_promise(ctx->future), NULL);
|
||||
}
|
||||
}
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
break;
|
||||
|
||||
case GET_STATE_DELETE:
|
||||
if(cache_delete_minio_object(ctx))
|
||||
{
|
||||
ctx->get.state = GET_STATE_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
}
|
||||
break;
|
||||
|
||||
case GET_STATE_END:
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
break;
|
||||
default: assert(0);break;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t curl_get_response_body_cb(void *ptr, size_t size, size_t count, void *userp)
|
||||
{
|
||||
struct tango_cache_ctx *ctx = (struct tango_cache_ctx *)userp;
|
||||
struct tango_cache_result result;
|
||||
|
||||
if(ctx->fail_state || ctx->get.state==GET_STATE_DELETE)
|
||||
{
|
||||
@@ -705,24 +667,24 @@ static size_t curl_get_response_body_cb(void *ptr, size_t size, size_t count, vo
|
||||
|
||||
if(ctx->get.response_tag.len > 0)
|
||||
{
|
||||
result.data_frag = ctx->get.response_tag.buff;
|
||||
result.size = ctx->get.response_tag.len;
|
||||
result.type = RESULT_TYPE_USERTAG;
|
||||
promise_success(future_to_promise(ctx->future), &result);
|
||||
ctx->get.result.data_frag = ctx->get.response_tag.buff;
|
||||
ctx->get.result.size = ctx->get.response_tag.len;
|
||||
ctx->get.result.type = RESULT_TYPE_USERTAG;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
easy_string_destroy(&ctx->get.response_tag);
|
||||
}
|
||||
if(ctx->response.len > 0)
|
||||
{
|
||||
result.data_frag = ctx->response.buff;
|
||||
result.size = ctx->response.len;
|
||||
result.type = RESULT_TYPE_HEADER;
|
||||
promise_success(future_to_promise(ctx->future), &result);
|
||||
ctx->get.result.data_frag = ctx->response.buff;
|
||||
ctx->get.result.size = ctx->response.len;
|
||||
ctx->get.result.type = RESULT_TYPE_HEADER;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
easy_string_destroy(&ctx->response);
|
||||
}
|
||||
result.data_frag = ptr;
|
||||
result.size = size * count;
|
||||
result.type = RESULT_TYPE_BODY;
|
||||
promise_success(future_to_promise(ctx->future), &result);
|
||||
ctx->get.result.data_frag = (const char *)ptr;
|
||||
ctx->get.result.size = size * count;
|
||||
ctx->get.result.type = RESULT_TYPE_BODY;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
return size*count;
|
||||
}
|
||||
|
||||
@@ -733,12 +695,13 @@ static bool check_expires_header(struct tango_cache_ctx *ctx, const char *expire
|
||||
ctx->get.expires = expires_hdr2timestamp(expires_val, len);
|
||||
time_gmt = get_gmtime_timestamp(time(NULL));
|
||||
|
||||
if(time_gmt > ctx->get.expires) //<2F><><EFBFBD><EFBFBD>ʧЧ<CAA7><D0A7>TODO relative_age<67>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD>ɶ
|
||||
if(time_gmt > ctx->get.expires)
|
||||
{
|
||||
tango_cache_set_fail_state(ctx, CACHE_TIMEOUT);
|
||||
ctx->get.state = GET_STATE_DELETE; //<2F><><EFBFBD><EFBFBD>ʧЧʱ<D0A7><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
ctx->get.result.type = RESULT_TYPE_MISS;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
easy_string_destroy(&ctx->response);
|
||||
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -755,24 +718,38 @@ static bool check_fresh_header(struct tango_cache_ctx *ctx)
|
||||
if(ctx->get.last_modify+ctx->get.max_age > now_gmt || now_gmt+ctx->get.min_fresh>ctx->get.expires)
|
||||
{
|
||||
tango_cache_set_fail_state(ctx, CACHE_TIMEOUT);
|
||||
ctx->get.result.type = RESULT_TYPE_MISS;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
easy_string_destroy(&ctx->response);
|
||||
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool check_get_result_code(struct tango_cache_ctx *ctx)
|
||||
static bool check_get_result_code(struct tango_cache_ctx *ctx, CURLcode code, long res_code)
|
||||
{
|
||||
CURLcode code;
|
||||
|
||||
code = curl_easy_getinfo(ctx->curl, CURLINFO_RESPONSE_CODE, &ctx->res_code);
|
||||
if(code != CURLE_OK || ctx->res_code!=200L)
|
||||
if(code != CURLE_OK)
|
||||
{
|
||||
tango_cache_set_fail_state(ctx, (code!=CURLE_OK)?CACHE_ERR_CURL:CACHE_CACHE_MISS);
|
||||
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
|
||||
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(res_code != 200L)
|
||||
{
|
||||
if(res_code == 404L)
|
||||
{
|
||||
tango_cache_set_fail_state(ctx, CACHE_CACHE_MISS);
|
||||
ctx->get.result.type = RESULT_TYPE_MISS;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
}
|
||||
else
|
||||
{
|
||||
tango_cache_set_fail_state(ctx, CACHE_ERR_INTERNAL);
|
||||
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -788,9 +765,13 @@ static size_t curl_get_response_header_cb(void *ptr, size_t size, size_t count,
|
||||
{
|
||||
return raw_len;
|
||||
}
|
||||
if(ctx->res_code==0 && !check_get_result_code(ctx)) //<2F>״<EFBFBD>Ӧ<EFBFBD><D3A6>ʱ<EFBFBD>ȿ<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>200
|
||||
if(ctx->res_code == 0) //<2F>״<EFBFBD>Ӧ<EFBFBD><D3A6>ʱ<EFBFBD>ȿ<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>200
|
||||
{
|
||||
return raw_len;
|
||||
CURLcode code = curl_easy_getinfo(ctx->curl, CURLINFO_RESPONSE_CODE, &ctx->res_code);
|
||||
if(!check_get_result_code(ctx, code, ctx->res_code))
|
||||
{
|
||||
return raw_len;
|
||||
}
|
||||
}
|
||||
pos_colon = (char*)memchr(start, ':', raw_len);
|
||||
if(pos_colon == NULL)
|
||||
@@ -831,9 +812,14 @@ static size_t curl_get_response_header_cb(void *ptr, size_t size, size_t count,
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
if(strcmp_one_word_mesa_equal_len("content-length", "CONTENT-LENGTH", start, 14))
|
||||
{
|
||||
sscanf(pos_colon+1, "%lu", &ctx->get.result.tlength);
|
||||
}
|
||||
break;
|
||||
case 11: if(strcmp_one_word_mesa_equal_len("content-md5", "CONTENT-MD5", start, 11)) easy_string_savedata(&ctx->response, (const char*)ptr, raw_len); break;
|
||||
case 12: if(strcmp_one_word_mesa_equal_len("content-type", "CONTENT-TYPE", start, 12)) easy_string_savedata(&ctx->response, (const char*)ptr, raw_len); break;
|
||||
case 14: if(strcmp_one_word_mesa_equal_len("content-length", "CONTENT-LENGTH", start, 14)) easy_string_savedata(&ctx->response, (const char*)ptr, raw_len); break;
|
||||
case 16: if(strcmp_one_word_mesa_equal_len("content-encoding", "CONTENT-ENCODING", start, 16)) easy_string_savedata(&ctx->response, (const char*)ptr, raw_len); break;
|
||||
case 19: if(strcmp_one_word_mesa_equal_len("content-disposition", "CONTENT-DISPOSITION", start, 19)) easy_string_savedata(&ctx->response, (const char*)ptr, raw_len); break;
|
||||
default: break;
|
||||
@@ -841,6 +827,37 @@ static size_t curl_get_response_header_cb(void *ptr, size_t size, size_t count,
|
||||
return raw_len;
|
||||
}
|
||||
|
||||
void tango_cache_curl_get_done(struct tango_cache_ctx *ctx, CURLcode res, long res_code)
|
||||
{
|
||||
switch(ctx->get.state)
|
||||
{
|
||||
case GET_STATE_START:
|
||||
if(!ctx->fail_state && check_get_result_code(ctx, res, res_code))
|
||||
{
|
||||
ctx->get.result.type = RESULT_TYPE_END;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
}
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
break;
|
||||
|
||||
case GET_STATE_DELETE:
|
||||
if(cache_delete_minio_object(ctx))
|
||||
{
|
||||
ctx->get.state = GET_STATE_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
}
|
||||
break;
|
||||
|
||||
case GET_STATE_END:
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
break;
|
||||
default: assert(0);break;
|
||||
}
|
||||
}
|
||||
|
||||
int tango_cache_fetch_start(struct tango_cache_ctx *ctx)
|
||||
{
|
||||
CURLMcode rc;
|
||||
|
||||
Reference in New Issue
Block a user