HTTP业务层适配新的tango cache client API。
This commit is contained in:
@@ -446,27 +446,38 @@ static void cache_query_on_succ(future_result_t * result, void * user)
|
|||||||
{
|
{
|
||||||
struct pangu_http_ctx * ctx = (struct pangu_http_ctx *)user;
|
struct pangu_http_ctx * ctx = (struct pangu_http_ctx *)user;
|
||||||
struct cached_meta* meta=NULL;
|
struct cached_meta* meta=NULL;
|
||||||
if(result==NULL)
|
enum cache_query_result_type type=cache_query_result_get_type(result);
|
||||||
|
switch(type)
|
||||||
{
|
{
|
||||||
assert(ctx->cached_body!=NULL);
|
case CACHE_QUERY_RESULT_MISS:
|
||||||
ctx->cache_query_status=WEB_CACHE_HIT;
|
ctx->cache_query_status=WEB_CACHE_NOT_HIT;
|
||||||
future_destroy(ctx->f_cache_query);
|
printf("cache query miss: %s\n", ctx->ref_session->req->req_spec.url);
|
||||||
ctx->f_cache_query=NULL;
|
goto __cleanup;
|
||||||
tfe_http_session_resume(ctx->ref_session);
|
break;
|
||||||
ctx->resume_from_cache_query=1;
|
case CACHE_QUERY_RESULT_END:
|
||||||
printf("cache query success: %s\n", ctx->ref_session->req->req_spec.url);
|
assert(ctx->cached_body!=NULL);
|
||||||
return;
|
ctx->cache_query_status=WEB_CACHE_HIT;
|
||||||
}
|
printf("cache query hit: %s\n", ctx->ref_session->req->req_spec.url);
|
||||||
if(cache_query_result_is_header(result))
|
goto __cleanup;
|
||||||
{
|
break;
|
||||||
ctx->cached_header=cache_query_result_get_header(result);
|
case CACHE_QUERY_RESULT_META:
|
||||||
ctx->cached_body=evbuffer_new();
|
ctx->cached_header=cache_query_result_get_header(result);
|
||||||
}
|
ctx->cached_body=evbuffer_new();
|
||||||
if(cache_query_result_is_body(result))
|
break;
|
||||||
{
|
case CACHE_QUERY_RESULT_DATA:
|
||||||
cache_query_result_append_data(ctx->cached_body, result);
|
cache_query_result_append_data(ctx->cached_body, result);;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
__cleanup:
|
||||||
|
future_destroy(ctx->f_cache_query);
|
||||||
|
ctx->f_cache_query=NULL;
|
||||||
|
tfe_http_session_resume(ctx->ref_session);
|
||||||
|
ctx->resume_from_cache_query=1;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
static void cache_query_on_fail(enum e_future_error err, const char * what, void * user)
|
static void cache_query_on_fail(enum e_future_error err, const char * what, void * user)
|
||||||
{
|
{
|
||||||
@@ -476,7 +487,7 @@ static void cache_query_on_fail(enum e_future_error err, const char * what, void
|
|||||||
tfe_http_session_resume(ctx->ref_session);
|
tfe_http_session_resume(ctx->ref_session);
|
||||||
ctx->cache_query_status=WEB_CACHE_NOT_HIT;
|
ctx->cache_query_status=WEB_CACHE_NOT_HIT;
|
||||||
ctx->resume_from_cache_query=1;
|
ctx->resume_from_cache_query=1;
|
||||||
printf("cache query failed: %s\n", ctx->ref_session->req->req_spec.url);
|
printf("cache query failed: %s %s\n", ctx->ref_session->req->req_spec.url, what);
|
||||||
}
|
}
|
||||||
void http_replace(const struct tfe_stream * stream, const struct tfe_http_session * session,
|
void http_replace(const struct tfe_stream * stream, const struct tfe_http_session * session,
|
||||||
enum tfe_http_event events, const unsigned char * body_frag, size_t frag_size, struct pangu_http_ctx * ctx)
|
enum tfe_http_event events, const unsigned char * body_frag, size_t frag_size, struct pangu_http_ctx * ctx)
|
||||||
@@ -961,7 +972,8 @@ void pangu_on_http_data(const struct tfe_stream * stream, const struct tfe_http_
|
|||||||
{
|
{
|
||||||
//resume from cache query.
|
//resume from cache query.
|
||||||
assert(ctx->action==PG_ACTION_NONE);
|
assert(ctx->action==PG_ACTION_NONE);
|
||||||
cache_make_response(session, ctx);
|
cache_make_response(session, ctx);
|
||||||
|
tfe_http_session_detach(session);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!ctx->resume_from_cache_query)
|
if(!ctx->resume_from_cache_query)
|
||||||
|
|||||||
@@ -66,31 +66,20 @@ void cache_query_free_meta(struct cached_meta* meta)
|
|||||||
FREE(&meta);
|
FREE(&meta);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int cache_query_result_is_header(future_result_t * result)
|
|
||||||
|
enum cache_query_result_type cache_query_result_get_type(future_result_t * result)
|
||||||
{
|
{
|
||||||
struct tango_cache_result* cache_result=tango_cache_read_result(result);
|
struct tango_cache_result* cache_result=tango_cache_read_result(result);
|
||||||
if(cache_result->type==RESULT_TYPE_HEADER)
|
enum cache_query_result_type map[__CACHE_QUERY_RESULT_MAX];
|
||||||
{
|
map[RESULT_TYPE_BODY]=CACHE_QUERY_RESULT_DATA;
|
||||||
return 1;
|
map[RESULT_TYPE_HEADER]=CACHE_QUERY_RESULT_META;
|
||||||
}
|
map[RESULT_TYPE_USERTAG]=CACHE_QUERY_RESULT_IRRELEVANT;
|
||||||
else
|
map[RESULT_TYPE_END]=CACHE_QUERY_RESULT_END;
|
||||||
{
|
map[RESULT_TYPE_MISS]=CACHE_QUERY_RESULT_MISS;
|
||||||
return 0;
|
return map[cache_result->type];
|
||||||
}
|
|
||||||
}
|
|
||||||
int cache_query_result_is_body(future_result_t * result)
|
|
||||||
{
|
|
||||||
struct tango_cache_result* cache_result=tango_cache_read_result(result);
|
|
||||||
if(cache_result->type==RESULT_TYPE_BODY)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct cached_meta* cache_query_result_get_header(future_result_t * result)
|
struct cached_meta* cache_query_result_get_header(future_result_t * result)
|
||||||
{
|
{
|
||||||
struct tango_cache_result* cache_result=tango_cache_read_result(result);
|
struct tango_cache_result* cache_result=tango_cache_read_result(result);
|
||||||
@@ -132,10 +121,10 @@ enum cache_query_status async_web_cache_query(struct cache_handle* handle, unsig
|
|||||||
return WEB_CACHE_NOT_APPLICABLE;
|
return WEB_CACHE_NOT_APPLICABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tango_cache_meta meta;
|
struct tango_cache_meta_get meta;
|
||||||
memset(&meta, 0, sizeof(meta));
|
memset(&meta, 0, sizeof(meta));
|
||||||
meta.url=request->req_spec.url;
|
meta.url=request->req_spec.url;
|
||||||
memcpy(&(meta.put), &req_fresshness, sizeof(meta.put));
|
memcpy(&(meta.get), &req_fresshness, sizeof(meta.get));
|
||||||
ret=tango_cache_fetch_object(handle->clients[thread_id], f, &meta);
|
ret=tango_cache_fetch_object(handle->clients[thread_id], f, &meta);
|
||||||
assert(ret==0);
|
assert(ret==0);
|
||||||
return WEB_CACHE_QUERING;
|
return WEB_CACHE_QUERING;
|
||||||
@@ -157,7 +146,7 @@ struct cache_update_context* web_cache_update_start(struct cache_handle* handle,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tango_cache_meta meta;
|
struct tango_cache_meta_put meta;
|
||||||
memset(&meta, 0, sizeof(meta));
|
memset(&meta, 0, sizeof(meta));
|
||||||
meta.url=session->req->req_spec.url;
|
meta.url=session->req->req_spec.url;
|
||||||
i=0;
|
i=0;
|
||||||
|
|||||||
@@ -24,9 +24,17 @@ void cache_query_result_append_data(struct evbuffer* buf, future_result_t * resu
|
|||||||
|
|
||||||
enum cache_query_status async_web_cache_query(struct cache_handle* handle, unsigned int thread_id,
|
enum cache_query_status async_web_cache_query(struct cache_handle* handle, unsigned int thread_id,
|
||||||
const struct tfe_http_half * request, struct future* f);
|
const struct tfe_http_half * request, struct future* f);
|
||||||
|
enum cache_query_result_type
|
||||||
|
{
|
||||||
|
CACHE_QUERY_RESULT_MISS,
|
||||||
|
CACHE_QUERY_RESULT_META,
|
||||||
|
CACHE_QUERY_RESULT_DATA,
|
||||||
|
CACHE_QUERY_RESULT_END,
|
||||||
|
CACHE_QUERY_RESULT_IRRELEVANT,
|
||||||
|
__CACHE_QUERY_RESULT_MAX
|
||||||
|
};
|
||||||
|
enum cache_query_result_type cache_query_result_get_type(future_result_t * result);
|
||||||
|
|
||||||
int cache_query_result_is_header(future_result_t * result);
|
|
||||||
int cache_query_result_is_body(future_result_t * result);
|
|
||||||
|
|
||||||
|
|
||||||
struct cache_update_context;
|
struct cache_update_context;
|
||||||
|
|||||||
Reference in New Issue
Block a user