支持Head获取对象元信息操作,支持从redis获取元信息;调整内部超时检查逻辑;
This commit is contained in:
85
cache/src/tango_cache_transfer.cpp
vendored
85
cache/src/tango_cache_transfer.cpp
vendored
@@ -174,7 +174,6 @@ int curl_get_minio_uploadID(struct tango_cache_ctx *ctx)
|
||||
|
||||
if(NULL == (ctx->curl=curl_easy_init()))
|
||||
{
|
||||
free(ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -209,6 +208,7 @@ int cache_delete_minio_object(struct tango_cache_ctx *ctx)
|
||||
ctx->instance->statistic.del_recv_num += 1;
|
||||
if(NULL == (ctx->curl=curl_easy_init()))
|
||||
{
|
||||
tango_cache_ctx_destroy(ctx); //<2F>ս<EFBFBD><D5BD><EFBFBD>
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ int cache_kick_upload_minio_end(struct tango_cache_ctx *ctx)
|
||||
switch(ctx->put.state)
|
||||
{
|
||||
case PUT_STATE_START:
|
||||
http_put_complete_part_evbuf(ctx);
|
||||
ret = http_put_complete_part_evbuf(ctx);
|
||||
break;
|
||||
|
||||
case PUT_STATE_PART:
|
||||
@@ -652,24 +652,16 @@ int tango_cache_multi_delete_start(struct tango_cache_ctx *ctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static size_t curl_get_response_body_cb(void *ptr, size_t size, size_t count, void *userp)
|
||||
bool fetch_header_over_biz(struct tango_cache_ctx *ctx)
|
||||
{
|
||||
struct tango_cache_ctx *ctx = (struct tango_cache_ctx *)userp;
|
||||
|
||||
if(ctx->fail_state || ctx->get.state==GET_STATE_DELETE)
|
||||
{
|
||||
return size*count;
|
||||
}
|
||||
|
||||
if(ctx->get.need_hdrs!=RESPONSE_HDR_ALL) //<2F><>Expiresʱ
|
||||
{
|
||||
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, tango_cache_get_errstring(ctx));
|
||||
return size*count;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if(ctx->get.response_tag.len > 0)
|
||||
{
|
||||
ctx->get.result.data_frag = ctx->get.response_tag.buff;
|
||||
@@ -686,6 +678,23 @@ static size_t curl_get_response_body_cb(void *ptr, size_t size, size_t count, vo
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
easy_string_destroy(&ctx->response);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if(ctx->fail_state || ctx->get.state==GET_STATE_DELETE)
|
||||
{
|
||||
return size*count;
|
||||
}
|
||||
|
||||
if(!fetch_header_over_biz(ctx))
|
||||
{
|
||||
return size*count;
|
||||
}
|
||||
|
||||
ctx->get.result.data_frag = (const char *)ptr;
|
||||
ctx->get.result.size = size * count;
|
||||
ctx->get.result.type = RESULT_TYPE_BODY;
|
||||
@@ -693,14 +702,16 @@ static size_t curl_get_response_body_cb(void *ptr, size_t size, size_t count, vo
|
||||
return size*count;
|
||||
}
|
||||
|
||||
static bool check_expires_header(struct tango_cache_ctx *ctx, const char *expires_val, size_t len)
|
||||
bool check_expires_fresh_header(struct tango_cache_ctx *ctx)
|
||||
{
|
||||
time_t time_gmt;
|
||||
time_t now_gmt;
|
||||
|
||||
ctx->get.expires = expires_hdr2timestamp(expires_val, len);
|
||||
time_gmt = get_gmtime_timestamp(time(NULL));
|
||||
if(ctx->get.need_hdrs != RESPONSE_HDR_ALL)
|
||||
return true;
|
||||
|
||||
now_gmt = get_gmtime_timestamp(time(NULL));
|
||||
|
||||
if(time_gmt > ctx->get.expires)
|
||||
if(now_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>
|
||||
@@ -709,17 +720,7 @@ static bool check_expires_header(struct tango_cache_ctx *ctx, const char *expire
|
||||
easy_string_destroy(&ctx->response);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool check_fresh_header(struct tango_cache_ctx *ctx)
|
||||
{
|
||||
time_t now_gmt;
|
||||
|
||||
if(ctx->get.need_hdrs != RESPONSE_HDR_ALL)
|
||||
return true;
|
||||
|
||||
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)
|
||||
{
|
||||
tango_cache_set_fail_state(ctx, CACHE_TIMEOUT);
|
||||
@@ -791,7 +792,8 @@ static size_t curl_get_response_header_cb(void *ptr, size_t size, size_t count,
|
||||
if(strcmp_one_word_mesa_equal_len("expires", "EXPIRES", start, 7))
|
||||
{
|
||||
ctx->get.need_hdrs |= RESPONSE_HDR_EXPIRES;
|
||||
if(!check_expires_header(ctx, pos_colon + 1, raw_len - datalen - 1) || !check_fresh_header(ctx))
|
||||
ctx->get.expires = expires_hdr2timestamp(pos_colon + 1, raw_len - datalen - 1);
|
||||
if(!check_expires_fresh_header(ctx))
|
||||
{
|
||||
return raw_len;
|
||||
}
|
||||
@@ -802,7 +804,7 @@ static size_t curl_get_response_header_cb(void *ptr, size_t size, size_t count,
|
||||
{
|
||||
ctx->get.need_hdrs |= RESPONSE_HDR_LAST_MOD;
|
||||
sscanf(pos_colon+1, "%lu", &ctx->get.last_modify);
|
||||
if(!check_fresh_header(ctx))
|
||||
if(!check_expires_fresh_header(ctx))
|
||||
{
|
||||
return raw_len;
|
||||
}
|
||||
@@ -839,21 +841,18 @@ void tango_cache_curl_get_done(struct tango_cache_ctx *ctx, CURLcode res, long r
|
||||
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);
|
||||
if(ctx->method!=CACHE_REQUEST_HEAD || fetch_header_over_biz(ctx)) //HEAD<41><44><EFBFBD>ֵ<EFBFBD><D6B5>ֶβ<D6B6>ȫ<EFBFBD>Ȳ<EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޣ<EFBFBD>
|
||||
{
|
||||
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);
|
||||
}
|
||||
ctx->get.state = GET_STATE_END;
|
||||
cache_delete_minio_object(ctx);
|
||||
break;
|
||||
|
||||
case GET_STATE_END:
|
||||
@@ -877,6 +876,10 @@ int tango_cache_fetch_start(struct tango_cache_ctx *ctx)
|
||||
|
||||
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);
|
||||
if(ctx->method == CACHE_REQUEST_HEAD)
|
||||
{
|
||||
curl_easy_setopt(ctx->curl, CURLOPT_NOBODY, 1L);
|
||||
}
|
||||
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_get_response_body_cb);
|
||||
|
||||
Reference in New Issue
Block a user