修改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

@@ -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);
if(code != CURLE_OK || ctx->res_code!=200L)
{
ctx->fail_state = true;
ctx->error_code = CACHE_ERR_CURL;
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
if(code != CURLE_OK) MESA_HANDLE_RUNTIME_LOGV2(ctx->instance->runtime_log, RLOG_LV_DEBUG, "%s", ctx->error);
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);
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");
curl_easy_setopt(ctx->curl, CURLOPT_NOSIGNAL,1L);
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)
{
ctx->fail_state = true;
ctx->error_code = CACHE_ERR_CURL;
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
return false;
}
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);
if(ret <= 0)
{
ctx->fail_state = true;
ctx->error_code = CACHE_ERR_CURL;
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
tango_cache_ctx_destroy(ctx);
}
}
@@ -381,8 +379,7 @@ int cache_kick_upload_minio_end(struct tango_cache_ctx *ctx)
}
else
{
ctx->fail_state = true;
ctx->error_code = CACHE_ERR_CURL;
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
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);
if(ret <= 0)
{
ctx->fail_state = true;
ctx->error_code = CACHE_ERR_CURL;
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
if(cache_cancel_upload_minio(ctx))
{
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))
{
easy_string_destroy(&ctx->response);
ctx->error_code = CACHE_ERR_CURL;
ctx->fail_state = true;
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
if(res != CURLE_OK) MESA_HANDLE_RUNTIME_LOGV2(ctx->instance->runtime_log, RLOG_LV_DEBUG, "%s", ctx->error);
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:
if(res != CURLE_OK || res_code!=200L)
{
ctx->fail_state = true;
ctx->error_code = CACHE_ERR_CURL;
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
if(res != CURLE_OK) MESA_HANDLE_RUNTIME_LOGV2(ctx->instance->runtime_log, RLOG_LV_DEBUG, "%s", ctx->error);
}
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:
if(res != CURLE_OK || res_code!=200L)
{
ctx->fail_state = true;
ctx->error_code = CACHE_ERR_CURL;
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
if(res != CURLE_OK) MESA_HANDLE_RUNTIME_LOGV2(ctx->instance->runtime_log, RLOG_LV_DEBUG, "%s", ctx->error);
}
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)
{
ctx->error_code = (res!=CURLE_OK)?CACHE_ERR_CURL:CACHE_CACHE_MISS;
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, ctx->error);
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
{
@@ -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ʱ
{
ctx->fail_state = true;
ctx->error_code = CACHE_ERR_CURL;
tango_cache_set_fail_state(ctx, CACHE_ERR_INTERNAL);
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;
}
@@ -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>ɶ
{
ctx->fail_state = true;
ctx->error_code = CACHE_TIMEOUT;
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>
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 true;
@@ -700,10 +691,9 @@ static bool check_fresh_header(struct tango_cache_ctx *ctx)
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)
{
ctx->fail_state = true;
ctx->error_code = CACHE_TIMEOUT;
tango_cache_set_fail_state(ctx, CACHE_TIMEOUT);
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 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);
if(code != CURLE_OK || ctx->res_code!=200L)
{
ctx->fail_state = true;
ctx->error_code = (code!=CURLE_OK)?CACHE_ERR_CURL:CACHE_CACHE_MISS;
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, (code!=CURLE_OK)?ctx->error:"cache not hit");
tango_cache_set_fail_state(ctx, (code!=CURLE_OK)?CACHE_ERR_CURL:CACHE_CACHE_MISS);
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
return false;
}
return true;