修改promis_fail错误描述

This commit is contained in:
zhangchengwei
2018-10-08 16:07:43 +08:00
committed by zhengchao
parent 664911cc23
commit 1efbe65031
6 changed files with 70 additions and 57 deletions

View File

@@ -115,13 +115,13 @@ static int32_t iothread_notify_event(int32_t socket_fd, void *content, int32_t l
} }
if(res <= 0) if(res <= 0)
{ {
printf("log_error: select io res=%d, error: %s", res, strerror(errno)); printf("log_error: select io res=%d, error: %s\n", res, strerror(errno));
return -1; return -1;
} }
if(FD_ISSET(socket_fd, &e_set)) if(FD_ISSET(socket_fd, &e_set))
{ {
printf("log_error: select io is in efds, error: %s", strerror(errno)); printf("log_error: select io is in efds, error: %s\n", strerror(errno));
return -2; return -2;
} }
@@ -250,15 +250,11 @@ void cache_evbase_update_end(struct cache_evbase_ctx *ctx_asyn)
buffer->ctx_asyn = ctx_asyn; buffer->ctx_asyn = ctx_asyn;
buffer->cmd_type = CACHE_ASYN_UPLOAD_END; buffer->cmd_type = CACHE_ASYN_UPLOAD_END;
if(iothread_notify_event(ctx_asyn->instance_asyn->notify_sendfd, &buffer, sizeof(void *), 0) != sizeof(void *)) if(iothread_notify_event(ctx_asyn->instance_asyn->notify_sendfd, &buffer, sizeof(void *), 2) != sizeof(void *))
{ {
if(!ctx_asyn->ctx->fail_state) if(!ctx_asyn->ctx->fail_state)
{ {
ctx_asyn->ctx->fail_state = true; tango_cache_set_fail_state(ctx_asyn->ctx, CACHE_ERR_SOCKPAIR);
if(ctx_asyn->ctx->future != NULL)
{
promise_failed(future_to_promise(ctx_asyn->ctx->future), FUTURE_ERROR_CANCEL, "write sockpair error");
}
} }
tango_cache_ctx_destroy(ctx_asyn->ctx); tango_cache_ctx_destroy(ctx_asyn->ctx);
cache_asyn_ctx_destroy(ctx_asyn); cache_asyn_ctx_destroy(ctx_asyn);
@@ -289,12 +285,11 @@ int cache_evbase_update_frag_data(struct cache_evbase_ctx *ctx_asyn, enum PUT_ME
buffer->ctx_asyn = ctx_asyn; buffer->ctx_asyn = ctx_asyn;
buffer->cmd_type = CACHE_ASYN_UPLOAD_FRAG_DATA; buffer->cmd_type = CACHE_ASYN_UPLOAD_FRAG_DATA;
if(iothread_notify_event(ctx_asyn->instance_asyn->notify_sendfd, &buffer, sizeof(void *), 0) != sizeof(void *)) if(iothread_notify_event(ctx_asyn->instance_asyn->notify_sendfd, &buffer, sizeof(void *), 2) != sizeof(void *))
{ {
ctx_asyn->ctx->fail_state = true; if(!ctx_asyn->ctx->fail_state)
if(ctx_asyn->ctx->future != NULL)
{ {
promise_failed(future_to_promise(ctx_asyn->ctx->future), FUTURE_ERROR_CANCEL, "write sockpair error"); tango_cache_set_fail_state(ctx_asyn->ctx, CACHE_ERR_SOCKPAIR);
} }
free(buffer->data); free(buffer->data);
free(buffer); free(buffer);
@@ -317,12 +312,11 @@ int cache_evbase_update_frag_evbuf(struct cache_evbase_ctx *ctx_asyn, struct evb
buffer->evbuf = evbuffer_new(); buffer->evbuf = evbuffer_new();
evbuffer_add_buffer(buffer->evbuf, evbuf); evbuffer_add_buffer(buffer->evbuf, evbuf);
if(iothread_notify_event(ctx_asyn->instance_asyn->notify_sendfd, &buffer, sizeof(void *), 0) != sizeof(void *)) if(iothread_notify_event(ctx_asyn->instance_asyn->notify_sendfd, &buffer, sizeof(void *), 2) != sizeof(void *))
{ {
ctx_asyn->ctx->fail_state = true; if(!ctx_asyn->ctx->fail_state)
if(ctx_asyn->ctx->future != NULL)
{ {
promise_failed(future_to_promise(ctx_asyn->ctx->future), FUTURE_ERROR_CANCEL, "write sockpair error"); tango_cache_set_fail_state(ctx_asyn->ctx, CACHE_ERR_SOCKPAIR);
} }
evbuffer_free(buffer->evbuf); evbuffer_free(buffer->evbuf);
free(buffer); free(buffer);
@@ -352,9 +346,9 @@ struct cache_evbase_ctx *cache_evbase_update_start(struct cache_evbase_instance
buffer->cmd_type = CACHE_ASYN_UPLOAD_START; buffer->cmd_type = CACHE_ASYN_UPLOAD_START;
//<2F>¼<EFBFBD>֪ͨ<CDA8><D6AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD>Ϣ //<2F>¼<EFBFBD>֪ͨ<CDA8><D6AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD>Ϣ
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 0) != sizeof(void *)) if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 2) != sizeof(void *))
{ {
ctx_asyn->ctx->fail_state = true; tango_cache_set_fail_state(ctx_asyn->ctx, CACHE_ERR_SOCKPAIR);
tango_cache_ctx_destroy(ctx_asyn->ctx); tango_cache_ctx_destroy(ctx_asyn->ctx);
cache_asyn_ctx_destroy(ctx_asyn); cache_asyn_ctx_destroy(ctx_asyn);
free(buffer); free(buffer);
@@ -398,11 +392,11 @@ int cache_evbase_upload_once_data(struct cache_evbase_instance *instance, struct
buffer->ctx_asyn = ctx_asyn; buffer->ctx_asyn = ctx_asyn;
buffer->cmd_type = CACHE_ASYN_UPLOAD_ONCE_DATA; buffer->cmd_type = CACHE_ASYN_UPLOAD_ONCE_DATA;
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 0) != sizeof(void *)) if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 2) != sizeof(void *))
{ {
free(buffer->data); free(buffer->data);
free(buffer); free(buffer);
ctx_asyn->ctx->fail_state = true; tango_cache_set_fail_state(ctx_asyn->ctx, CACHE_ERR_SOCKPAIR);
tango_cache_ctx_destroy(ctx); tango_cache_ctx_destroy(ctx);
cache_asyn_ctx_destroy(ctx_asyn); cache_asyn_ctx_destroy(ctx_asyn);
return -2; return -2;
@@ -437,11 +431,11 @@ int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struc
buffer->evbuf = evbuffer_new(); buffer->evbuf = evbuffer_new();
evbuffer_add_buffer(buffer->evbuf, evbuf); evbuffer_add_buffer(buffer->evbuf, evbuf);
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 0) != sizeof(void *)) if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 2) != sizeof(void *))
{ {
evbuffer_free(buffer->evbuf); evbuffer_free(buffer->evbuf);
free(buffer); free(buffer);
ctx_asyn->ctx->fail_state = true; tango_cache_set_fail_state(ctx_asyn->ctx, CACHE_ERR_SOCKPAIR);
tango_cache_ctx_destroy(ctx); tango_cache_ctx_destroy(ctx);
cache_asyn_ctx_destroy(ctx_asyn); cache_asyn_ctx_destroy(ctx_asyn);
return -2; return -2;
@@ -467,8 +461,10 @@ int cache_evbase_fetch_object(struct cache_evbase_instance *instance, struct fut
buffer->ctx_asyn = ctx_asyn; buffer->ctx_asyn = ctx_asyn;
buffer->cmd_type = CACHE_ASYN_FETCH; buffer->cmd_type = CACHE_ASYN_FETCH;
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 0) != sizeof(void *)) 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));
tango_cache_ctx_destroy(ctx_asyn->ctx); tango_cache_ctx_destroy(ctx_asyn->ctx);
cache_asyn_ctx_destroy(ctx_asyn); cache_asyn_ctx_destroy(ctx_asyn);
free(buffer); free(buffer);
@@ -496,9 +492,13 @@ int cache_evbase_delete_object(struct cache_evbase_instance *instance, struct fu
buffer->cmd_type = CACHE_ASYN_DELETE; buffer->cmd_type = CACHE_ASYN_DELETE;
//<2F>ο<EFBFBD>Unix<69>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD>432ҳ<32><D2B3><EFBFBD>ڶ<EFBFBD><DAB6>߳<EFBFBD>д<EFBFBD>İ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> //<2F>ο<EFBFBD>Unix<69>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD>432ҳ<32><D2B3><EFBFBD>ڶ<EFBFBD><DAB6>߳<EFBFBD>д<EFBFBD>İ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 0) != sizeof(void *)) if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 2) != sizeof(void *))
{ {
ctx_asyn->ctx->fail_state = true; tango_cache_set_fail_state(ctx_asyn->ctx, CACHE_ERR_SOCKPAIR);
if(future != NULL)
{
promise_failed(future_to_promise(future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx_asyn->ctx));
}
tango_cache_ctx_destroy(ctx_asyn->ctx); tango_cache_ctx_destroy(ctx_asyn->ctx);
cache_asyn_ctx_destroy(ctx_asyn); cache_asyn_ctx_destroy(ctx_asyn);
free(buffer); free(buffer);

View File

@@ -17,6 +17,8 @@ enum CACHE_ERR_CODE
CACHE_OUTOF_MEMORY,//<2F><>ǰ<EFBFBD>ڴ<EFBFBD>ռ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3>鿴MAX_USED_MEMORY_SIZE_MB<4D>Ƿ<EFBFBD><C7B7><EFBFBD>С<EFBFBD><D0A1><EFBFBD>ߵ<EFBFBD>ǰ<EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ʸ<EFBFBD><CAB8><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD> CACHE_OUTOF_MEMORY,//<2F><>ǰ<EFBFBD>ڴ<EFBFBD>ռ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3>鿴MAX_USED_MEMORY_SIZE_MB<4D>Ƿ<EFBFBD><C7B7><EFBFBD>С<EFBFBD><D0A1><EFBFBD>ߵ<EFBFBD>ǰ<EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ʸ<EFBFBD><CAB8><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD>
CACHE_ERR_CURL, CACHE_ERR_CURL,
CACHE_ERR_WIREDLB, CACHE_ERR_WIREDLB,
CACHE_ERR_SOCKPAIR,
CACHE_ERR_INTERNAL,
}; };
enum PUT_MEMORY_COPY_WAY enum PUT_MEMORY_COPY_WAY

Binary file not shown.

View File

@@ -54,6 +54,26 @@ enum CACHE_ERR_CODE tango_cache_ctx_error(const struct tango_cache_instance *ins
return instance->error_code; return instance->error_code;
} }
void tango_cache_set_fail_state(struct tango_cache_ctx *ctx, enum CACHE_ERR_CODE error_code)
{
ctx->fail_state = true;
ctx->error_code = error_code;
}
const char *tango_cache_get_errstring(const struct tango_cache_ctx *ctx)
{
switch(ctx->error_code)
{
case CACHE_CACHE_MISS: return "cache not hit";
case CACHE_TIMEOUT: return "cache not fresh";
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";
default: return ctx->error;
}
}
void tango_cache_get_statistics(const struct tango_cache_instance *instance, struct cache_statistics *out) void tango_cache_get_statistics(const struct tango_cache_instance *instance, struct cache_statistics *out)
{ {
out->get_recv_num = instance->statistic.get_recv_num; out->get_recv_num = instance->statistic.get_recv_num;
@@ -182,7 +202,7 @@ void tango_cache_ctx_destroy(struct tango_cache_ctx *ctx)
{ {
if(ctx->fail_state) if(ctx->fail_state)
{ {
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, ctx->error); promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
} }
else else
{ {
@@ -313,7 +333,7 @@ struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *
{ {
ctx->headers = curl_slist_append(ctx->headers, "Content-Type:"); ctx->headers = curl_slist_append(ctx->headers, "Content-Type:");
} }
ctx->headers = curl_slist_append(ctx->headers, "Expect:"); //ctx->headers = curl_slist_append(ctx->headers, "Expect:"); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>curl_multi_socket_action<6F>ס
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>GETʱ<54><CAB1>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>GETʱ<54><CAB1>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(meta->usertag_len>0 && meta->usertag_len<=USER_TAG_MAX_LEN) if(meta->usertag_len>0 && meta->usertag_len<=USER_TAG_MAX_LEN)
{ {

View File

@@ -130,6 +130,8 @@ void easy_string_savedata(struct easy_string *estr, const char *data, size_t len
void easy_string_destroy(struct easy_string *estr); void easy_string_destroy(struct easy_string *estr);
void tango_cache_ctx_destroy(struct tango_cache_ctx *ctx); 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_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_fetch_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta);

View File

@@ -157,8 +157,7 @@ static size_t curl_write_uploadID_cb(void *ptr, size_t size, size_t count, void
code = curl_easy_getinfo(ctx->curl, CURLINFO_RESPONSE_CODE, &ctx->res_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 || ctx->res_code!=200L)
{ {
ctx->fail_state = true; tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
ctx->error_code = CACHE_ERR_CURL;
if(code != CURLE_OK) MESA_HANDLE_RUNTIME_LOGV2(ctx->instance->runtime_log, RLOG_LV_DEBUG, "%s", ctx->error); if(code != CURLE_OK) MESA_HANDLE_RUNTIME_LOGV2(ctx->instance->runtime_log, RLOG_LV_DEBUG, "%s", ctx->error);
return size*count; return size*count;
} }
@@ -182,6 +181,7 @@ int curl_get_minio_uploadID(struct tango_cache_ctx *ctx)
snprintf(minio_url, 256, "http://%s/%s/%s?uploads", ctx->hostaddr, 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_POST, 1L);
curl_easy_setopt(ctx->curl, CURLOPT_URL, minio_url); 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_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); curl_easy_setopt(ctx->curl, CURLOPT_NOSIGNAL,1L);
curl_easy_setopt(ctx->curl, CURLOPT_WRITEFUNCTION, curl_write_uploadID_cb); curl_easy_setopt(ctx->curl, CURLOPT_WRITEFUNCTION, curl_write_uploadID_cb);
@@ -321,8 +321,7 @@ bool cache_kick_upload_minio_multipart(struct tango_cache_ctx *ctx, size_t block
if(ret <= 0) if(ret <= 0)
{ {
ctx->fail_state = true; tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
ctx->error_code = CACHE_ERR_CURL;
return false; return false;
} }
return true; return true;
@@ -339,8 +338,7 @@ int http_put_complete_part_evbuf(struct tango_cache_ctx *ctx)
ret = http_put_bodypart_request_evbuf(ctx, true); ret = http_put_bodypart_request_evbuf(ctx, true);
if(ret <= 0) if(ret <= 0)
{ {
ctx->fail_state = true; tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
ctx->error_code = CACHE_ERR_CURL;
tango_cache_ctx_destroy(ctx); tango_cache_ctx_destroy(ctx);
} }
} }
@@ -381,8 +379,7 @@ int cache_kick_upload_minio_end(struct tango_cache_ctx *ctx)
} }
else else
{ {
ctx->fail_state = true; tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
ctx->error_code = CACHE_ERR_CURL;
tango_cache_ctx_destroy(ctx); tango_cache_ctx_destroy(ctx);
} }
} }
@@ -391,8 +388,7 @@ int cache_kick_upload_minio_end(struct tango_cache_ctx *ctx)
ret = http_put_bodypart_request_evbuf(ctx, false); ret = http_put_bodypart_request_evbuf(ctx, false);
if(ret <= 0) if(ret <= 0)
{ {
ctx->fail_state = true; tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
ctx->error_code = CACHE_ERR_CURL;
if(cache_cancel_upload_minio(ctx)) if(cache_cancel_upload_minio(ctx))
{ {
ctx->put.state = PUT_STATE_CANCEL; ctx->put.state = PUT_STATE_CANCEL;
@@ -422,8 +418,7 @@ void tango_cache_curl_put_done(struct tango_cache_ctx *ctx, CURLcode res, long r
if(res!=CURLE_OK||res_code!=200L|| ctx->fail_state || !parse_uploadID_xml(ctx->response.buff, ctx->response.len, &ctx->put.uploadID)) if(res!=CURLE_OK||res_code!=200L|| ctx->fail_state || !parse_uploadID_xml(ctx->response.buff, ctx->response.len, &ctx->put.uploadID))
{ {
easy_string_destroy(&ctx->response); easy_string_destroy(&ctx->response);
ctx->error_code = CACHE_ERR_CURL; tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
ctx->fail_state = true;
if(res != CURLE_OK) MESA_HANDLE_RUNTIME_LOGV2(ctx->instance->runtime_log, RLOG_LV_DEBUG, "%s", ctx->error); if(res != CURLE_OK) MESA_HANDLE_RUNTIME_LOGV2(ctx->instance->runtime_log, RLOG_LV_DEBUG, "%s", ctx->error);
if(ctx->put.close_state) if(ctx->put.close_state)
{ {
@@ -452,8 +447,7 @@ void tango_cache_curl_put_done(struct tango_cache_ctx *ctx, CURLcode res, long r
case PUT_STATE_PART: case PUT_STATE_PART:
if(res != CURLE_OK || res_code!=200L) if(res != CURLE_OK || res_code!=200L)
{ {
ctx->fail_state = true; tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
ctx->error_code = CACHE_ERR_CURL;
if(res != CURLE_OK) MESA_HANDLE_RUNTIME_LOGV2(ctx->instance->runtime_log, RLOG_LV_DEBUG, "%s", ctx->error); if(res != CURLE_OK) MESA_HANDLE_RUNTIME_LOGV2(ctx->instance->runtime_log, RLOG_LV_DEBUG, "%s", ctx->error);
} }
if(ctx->fail_state) if(ctx->fail_state)
@@ -491,8 +485,7 @@ void tango_cache_curl_put_done(struct tango_cache_ctx *ctx, CURLcode res, long r
case PUT_STATE_END: case PUT_STATE_END:
if(res != CURLE_OK || res_code!=200L) if(res != CURLE_OK || res_code!=200L)
{ {
ctx->fail_state = true; tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
ctx->error_code = CACHE_ERR_CURL;
if(res != CURLE_OK) MESA_HANDLE_RUNTIME_LOGV2(ctx->instance->runtime_log, RLOG_LV_DEBUG, "%s", ctx->error); if(res != CURLE_OK) MESA_HANDLE_RUNTIME_LOGV2(ctx->instance->runtime_log, RLOG_LV_DEBUG, "%s", ctx->error);
} }
tango_cache_ctx_destroy(ctx); tango_cache_ctx_destroy(ctx);
@@ -600,8 +593,8 @@ void tango_cache_curl_get_done(struct tango_cache_ctx *ctx, CURLcode res, long r
{ {
if(res!=CURLE_OK || res_code!=200L) if(res!=CURLE_OK || res_code!=200L)
{ {
ctx->error_code = (res!=CURLE_OK)?CACHE_ERR_CURL:CACHE_CACHE_MISS; 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, ctx->error); promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
} }
else else
{ {
@@ -641,10 +634,9 @@ static size_t curl_get_response_body_cb(void *ptr, size_t size, size_t count, vo
if(ctx->get.need_hdrs!=RESPONSE_HDR_ALL) //<2F><>Expiresʱ if(ctx->get.need_hdrs!=RESPONSE_HDR_ALL) //<2F><>Expiresʱ
{ {
ctx->fail_state = true; tango_cache_set_fail_state(ctx, CACHE_ERR_INTERNAL);
ctx->error_code = CACHE_ERR_CURL;
ctx->get.state = GET_STATE_DELETE; ctx->get.state = GET_STATE_DELETE;
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, "cache Expires or x-amz-meta-lm not found"); promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
return size*count; return size*count;
} }
@@ -680,11 +672,10 @@ static bool check_expires_header(struct tango_cache_ctx *ctx, const char *expire
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) //<2F><><EFBFBD><EFBFBD>ʧЧ<CAA7><D0A7>TODO relative_age<67>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD>ɶ
{ {
ctx->fail_state = true; tango_cache_set_fail_state(ctx, CACHE_TIMEOUT);
ctx->error_code = 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.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>
easy_string_destroy(&ctx->response); easy_string_destroy(&ctx->response);
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, "cache not fresh"); promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
return false; return false;
} }
return true; return true;
@@ -700,10 +691,9 @@ static bool check_fresh_header(struct tango_cache_ctx *ctx)
now_gmt = get_gmtime_timestamp(time(NULL)); now_gmt = get_gmtime_timestamp(time(NULL));
if(ctx->get.last_modify+ctx->get.max_age > now_gmt || now_gmt+ctx->get.min_fresh>ctx->get.expires) if(ctx->get.last_modify+ctx->get.max_age > now_gmt || now_gmt+ctx->get.min_fresh>ctx->get.expires)
{ {
ctx->fail_state = true; tango_cache_set_fail_state(ctx, CACHE_TIMEOUT);
ctx->error_code = CACHE_TIMEOUT;
easy_string_destroy(&ctx->response); easy_string_destroy(&ctx->response);
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, "cache not fresh"); promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
return false; return false;
} }
return true; return true;
@@ -716,9 +706,8 @@ static bool check_get_result_code(struct tango_cache_ctx *ctx)
code = curl_easy_getinfo(ctx->curl, CURLINFO_RESPONSE_CODE, &ctx->res_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 || ctx->res_code!=200L)
{ {
ctx->fail_state = true; tango_cache_set_fail_state(ctx, (code!=CURLE_OK)?CACHE_ERR_CURL:CACHE_CACHE_MISS);
ctx->error_code = (code!=CURLE_OK)?CACHE_ERR_CURL:CACHE_CACHE_MISS; promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, (code!=CURLE_OK)?ctx->error:"cache not hit");
return false; return false;
} }
return true; return true;