GET时HEADER只回调一次;增加CACHE MISS统计;

This commit is contained in:
zhangchengwei
2018-09-23 18:13:46 +08:00
committed by zhengchao
parent 282eca63bd
commit dc6a6331d3
7 changed files with 65 additions and 77 deletions

View File

@@ -158,7 +158,7 @@ static size_t curl_write_uploadID_cb(void *ptr, size_t size, size_t count, void
if(code != CURLE_OK || ctx->res_code!=200L)
{
ctx->fail_state = true;
ctx->error_code = CACHE_CACHE_MISS;
ctx->error_code = CACHE_ERR_CURL;
if(code != CURLE_OK) MESA_HANDLE_RUNTIME_LOGV2(ctx->instance->runtime_log, RLOG_LV_DEBUG, "%s", ctx->error);
return size*count;
}
@@ -339,6 +339,7 @@ int http_put_complete_part_evbuf(struct tango_cache_ctx *ctx)
if(ret <= 0)
{
ctx->fail_state = true;
ctx->error_code = CACHE_ERR_CURL;
tango_cache_ctx_destroy(ctx);
}
}
@@ -380,6 +381,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_ctx_destroy(ctx);
}
}
@@ -389,6 +391,7 @@ int cache_kick_upload_minio_end(struct tango_cache_ctx *ctx)
if(ret <= 0)
{
ctx->fail_state = true;
ctx->error_code = CACHE_ERR_CURL;
if(cache_cancel_upload_minio(ctx))
{
ctx->put_state = PUT_STATE_CANCEL;
@@ -421,6 +424,10 @@ void tango_cache_curl_put_done(CURL *easy, struct tango_cache_ctx *ctx, CURLcode
ctx->error_code = 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(ctx->close_state)
{
tango_cache_ctx_destroy(ctx);
}
}
else
{
@@ -445,6 +452,7 @@ void tango_cache_curl_put_done(CURL *easy, struct tango_cache_ctx *ctx, CURLcode
if(res != CURLE_OK || res_code!=200L)
{
ctx->fail_state = true;
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(ctx->fail_state)
@@ -483,6 +491,7 @@ void tango_cache_curl_put_done(CURL *easy, struct tango_cache_ctx *ctx, CURLcode
if(res != CURLE_OK || res_code!=200L)
{
ctx->fail_state = true;
ctx->error_code = 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);
@@ -577,7 +586,7 @@ void tango_cache_curl_get_done(CURL *easy, struct tango_cache_ctx *ctx, CURLcode
{
if(res!=CURLE_OK || res_code!=200L)
{
ctx->error_code = CACHE_ERR_CURL;
ctx->error_code = (res!=CURLE_OK)?CACHE_ERR_CURL:CACHE_CACHE_MISS;
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, ctx->error);
}
else
@@ -619,17 +628,32 @@ static size_t curl_get_response_body_cb(void *ptr, size_t size, size_t count, vo
if(ctx->need_hdrs!=RESPONSE_HDR_ALL) //<2F><>Expiresʱ
{
ctx->fail_state = true;
ctx->error_code = CACHE_CACHE_MISS;
ctx->error_code = CACHE_ERR_CURL;
ctx->get_state = GET_STATE_DELETE;
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, "cache Expires or last-modify not found");
return size*count;
}
else
if(ctx->response_tag.len > 0)
{
result.data_frag = ptr;
result.size = size * count;
result.type = RESULT_TYPE_BODY;
result.data_frag = ctx->response_tag.buff;
result.size = ctx->response_tag.len;
result.type = RESULT_TYPE_USERTAG;
promise_success(future_to_promise(ctx->future), &result);
easy_string_destroy(&ctx->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);
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);
return size*count;
}
@@ -654,7 +678,6 @@ static bool check_expires_header(struct tango_cache_ctx *ctx, const char *expire
static bool check_fresh_header(struct tango_cache_ctx *ctx)
{
struct tango_cache_result result;
time_t now_gmt;
if(ctx->need_hdrs != RESPONSE_HDR_ALL)
@@ -669,23 +692,6 @@ static bool check_fresh_header(struct tango_cache_ctx *ctx)
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, "cache not fresh");
return false;
}
if(ctx->response_tag.len > 0)
{
result.data_frag = ctx->response_tag.buff;
result.size = ctx->response_tag.len;
result.type = RESULT_TYPE_USERTAG;
promise_success(future_to_promise(ctx->future), &result);
easy_string_destroy(&ctx->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);
easy_string_destroy(&ctx->response);
}
return true;
}
@@ -697,7 +703,7 @@ static bool check_get_result_code(struct tango_cache_ctx *ctx)
if(code != CURLE_OK || ctx->res_code!=200L)
{
ctx->fail_state = true;
ctx->error_code = 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, (code!=CURLE_OK)?ctx->error:"cache not hit");
return false;
}
@@ -707,9 +713,7 @@ static bool check_get_result_code(struct tango_cache_ctx *ctx)
static size_t curl_get_response_header_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;
char *start=(char *)ptr, *pos_colon, *hdrdata=(char*)ptr;
bool ptr_valid=false;
char *start=(char *)ptr, *pos_colon;
size_t raw_len = size*count, hdrlen=size*count;
char usertag[2048];
@@ -722,8 +726,6 @@ static size_t curl_get_response_header_cb(void *ptr, size_t size, size_t count,
return raw_len;
}
result.type = RESULT_TYPE_HEADER;
if((pos_colon=(char*)memchr(start, ':', raw_len))!=NULL)
{
size_t datalen = pos_colon - start;
@@ -755,41 +757,18 @@ static size_t curl_get_response_header_cb(void *ptr, size_t size, size_t count,
{
if((hdrlen = Base64_DecodeBlock((unsigned char*)pos_colon+1, raw_len-datalen-1, (unsigned char*)usertag, 2048))>0)
{
if(ctx->need_hdrs == RESPONSE_HDR_ALL)
{
ptr_valid = true;
result.type = RESULT_TYPE_USERTAG;
hdrdata = usertag;
}
else
{
easy_string_savedata(&ctx->response_tag, usertag, hdrlen);
}
easy_string_savedata(&ctx->response_tag, usertag, hdrlen);
}
}
break;
case 11: if(strcmp_one_word_mesa_equal_len("content-md5", "CONTENT-MD5", start, 11)) ptr_valid = true; break;
case 12: if(strcmp_one_word_mesa_equal_len("content-type", "CONTENT-TYPE", start, 12)) ptr_valid = true; break;
case 14: if(strcmp_one_word_mesa_equal_len("content-length", "CONTENT-LENGTH", start, 14)) ptr_valid = true; break;
case 16: if(strcmp_one_word_mesa_equal_len("content-encoding", "CONTENT-ENCODING", start, 16)) ptr_valid = true; break;
case 19: if(strcmp_one_word_mesa_equal_len("content-disposition", "CONTENT-DISPOSITION", start, 19)) ptr_valid = true; 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;
}
}
if(ptr_valid)
{
if(ctx->need_hdrs == RESPONSE_HDR_ALL)
{
result.data_frag = hdrdata;
result.size = hdrlen;
promise_success(future_to_promise(ctx->future), &result);
}
else if(result.type == RESULT_TYPE_HEADER)
{
easy_string_savedata(&ctx->response, hdrdata, hdrlen);
}
}
return raw_len;
}