diff --git a/cache/src/tango_cache_pending.cpp b/cache/src/tango_cache_pending.cpp index 67b935d..2a5d928 100644 --- a/cache/src/tango_cache_pending.cpp +++ b/cache/src/tango_cache_pending.cpp @@ -95,7 +95,7 @@ const char* get_head_value(const struct tfe_http_field *http_fields, size_t n_fi enum cache_pending_action get_pragma_action(const char * value) { const char *pragma_value = "no-cache"; - if (memcmp(value, pragma_value, strlen(pragma_value)) == 0) + if (strcasecmp(value, pragma_value) == 0) { return VERIFY; } diff --git a/platform/src/key_keeper.cpp b/platform/src/key_keeper.cpp index 48f2390..bf59bee 100644 --- a/platform/src/key_keeper.cpp +++ b/platform/src/key_keeper.cpp @@ -393,7 +393,7 @@ static void certstore_rpc_on_succ(void* result, void* user) { struct promise * p = (struct promise *) user; struct key_keeper_promise_ctx* ctx = (struct key_keeper_promise_ctx*)promise_get_ctx(p); - TFE_LOG_INFO(ctx->logger, "certstore rpc success"); +// TFE_LOG_INFO(ctx->logger, "certstore rpc success"); future_destroy(ctx->f_certstore_rpc); MESA_htable_handle htable= ctx->htable; const uchar* key = ctx->key; @@ -459,7 +459,7 @@ static int __wrapper_MESA_htable_set_opt_func(MESA_htable_handle table, enum MES static void key_keeper_free_serialized(void* data) { - printf("call key_keeper_free_serialized\n"); +// printf("call key_keeper_free_serialized\n"); struct keyring_private* kyr = (struct keyring_private*)data; key_keeper_free_keyring(&(kyr->head)); } @@ -506,7 +506,7 @@ struct key_keeper* key_keeper_init(const char * profile, const char* section, vo keeper->logger = logger; char tmp[TFE_STRING_MAX]={0}; MESA_load_profile_string_def(profile, section, "mode", tmp, sizeof(tmp), "debug"); - if(strncmp(tmp, "debug", TFE_STRING_MAX) == 0) + if(strcasecmp(tmp, "debug") == 0) { keeper->work_mode = KK_MODE_DEBUG; } diff --git a/plugin/business/pangu-http/src/pangu_http.cpp b/plugin/business/pangu-http/src/pangu_http.cpp index 46936c3..0c37edb 100644 --- a/plugin/business/pangu-http/src/pangu_http.cpp +++ b/plugin/business/pangu-http/src/pangu_http.cpp @@ -522,7 +522,6 @@ static void cache_query_on_succ(future_result_t * result, void * user) case CACHE_QUERY_RESULT_END: assert(ctx->cached_response!=NULL); ctx->cache_query_status=WEB_CACHE_HIT; - printf("cache query hit: %s\n", ctx->ref_session->req->req_spec.url); tfe_http_half_write_body_end(ctx->cached_response); //ownership has been transferred to http session, set to NULL. ctx->cached_response=NULL; @@ -532,7 +531,6 @@ static void cache_query_on_succ(future_result_t * result, void * user) break; case CACHE_QUERY_RESULT_MISS: ctx->cache_query_status=WEB_CACHE_NOT_HIT; - printf("cache query miss: %s\n", ctx->ref_session->req->req_spec.url); ctx->resume_from_cache_query=1; tfe_http_session_resume(ctx->ref_session); future_destroy(ctx->f_cache_query); @@ -927,7 +925,7 @@ void enforce_control_policy(const struct tfe_stream * stream, const struct tfe_h } void cache_query(const struct tfe_http_session * session, unsigned int thread_id, struct pangu_http_ctx * ctx) { - ctx->f_cache_query=future_create("cache_down", cache_query_on_succ, cache_query_on_fail, ctx); + ctx->f_cache_query=future_create("cache_get", cache_query_on_succ, cache_query_on_fail, ctx); ctx->cache_query_status=async_web_cache_query(g_pangu_rt->cache, thread_id, session->req, ctx->f_cache_query); if(ctx->cache_query_status==WEB_CACHE_QUERING) { @@ -948,10 +946,6 @@ void cache_update(const struct tfe_http_session * session, enum tfe_http_event e if(events & EV_HTTP_RESP_BODY_BEGIN && ctx->cache_query_status == WEB_CACHE_NOT_HIT) { ctx->cache_update_ctx=web_cache_update_start(g_pangu_rt->cache, thread_id, session); - if(ctx->cache_update_ctx==NULL) - { - printf("cache update forbidden: %s\n", ctx->ref_session->req->req_spec.url); - } } if(events & EV_HTTP_RESP_BODY_CONT && ctx->cache_update_ctx!=NULL) { diff --git a/plugin/business/pangu-http/src/pangu_web_cache.cpp b/plugin/business/pangu-http/src/pangu_web_cache.cpp index 4147d0a..19d71b4 100644 --- a/plugin/business/pangu-http/src/pangu_web_cache.cpp +++ b/plugin/business/pangu-http/src/pangu_web_cache.cpp @@ -42,6 +42,7 @@ struct cache_handle { unsigned int thread_count; int cache_undefined_obj_enabled; + int query_undefined_obj_enabled; size_t cache_undefined_obj_min_size; int minimum_cache_seconds; struct tango_cache_instance **clients; @@ -51,6 +52,8 @@ struct cache_handle int fs_id[__CACHE_STAT_MAX]; struct event_base* gc_evbase; struct event* gcev; + + void* logger; }; struct cache_update_context { @@ -199,7 +202,8 @@ void cache_stat_init(struct cache_handle* cache) struct cache_handle* create_web_cache_handle(const char* profile_path, const char* section, struct event_base* gc_evbase, void *logger) { struct cache_handle* cache=ALLOC(struct cache_handle, 1); - int temp=0; + int temp=0; + cache->logger=logger; cache->thread_count=tfe_proxy_get_work_thread_count(); cache->clients=ALLOC(struct tango_cache_instance *, cache->thread_count); int i=0; @@ -211,7 +215,7 @@ struct cache_handle* create_web_cache_handle(const char* profile_path, const cha goto error_out; } } - + MESA_load_profile_int_def(profile_path, section, "query_undefined_obj", &(cache->query_undefined_obj_enabled), 1); MESA_load_profile_int_def(profile_path, section, "cache_undefined_obj", &(cache->cache_undefined_obj_enabled), 1); MESA_load_profile_int_def(profile_path, section, "cached_undefined_obj_minimum_size", &(temp), 100*1024); cache->cache_undefined_obj_min_size=temp; @@ -292,6 +296,7 @@ size_t cache_query_result_get_data(future_result_t * result, const unsigned char struct cache_query_context { struct cache_handle* ref_handle; + char* url; int is_undefined_obj; struct future* f_tango_cache_fetch; }; @@ -300,6 +305,7 @@ void cache_query_ctx_free_cb(void* p) struct cache_query_context* ctx=(struct cache_query_context*)p; future_destroy(ctx->f_tango_cache_fetch); ctx->f_tango_cache_fetch=NULL; + FREE(&(ctx->url)); free(ctx); } static void wrap_cache_query_on_succ(future_result_t * result, void * user) @@ -319,10 +325,12 @@ static void wrap_cache_query_on_succ(future_result_t * result, void * user) } ATOMIC_INC(&(ctx->ref_handle->stat_val[STAT_CACHE_QUERY_HIT])); FS_operate(ctx->ref_handle->fs_handle, ctx->ref_handle->fs_id[STAT_CACHE_QUERY_HIT_OJB_SIZE], 0, FS_OP_SET, _result->tlength/1024); + TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache query hit: %s", ctx->url); break; case RESULT_TYPE_END: case RESULT_TYPE_MISS: - //last call. + //last call. + TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache query miss: %s", ctx->url); promise_dettach_ctx(p); cache_query_ctx_free_cb(ctx); break; @@ -358,7 +366,7 @@ enum cache_query_status async_web_cache_query(struct cache_handle* handle, unsig switch(get_action) { case UNDEFINED: - if(!handle->cache_undefined_obj_enabled) + if(!handle->query_undefined_obj_enabled) { ATOMIC_INC(&(handle->stat_val[STAT_CACHE_QUERY_NOT_APPLICABLE])); return WEB_CACHE_NOT_APPLICABLE; @@ -383,21 +391,23 @@ enum cache_query_status async_web_cache_query(struct cache_handle* handle, unsig memcpy(&(meta.get), &req_fresshness, sizeof(meta.get)); query_ctx=ALLOC(struct cache_query_context, 1); query_ctx->ref_handle=handle; + query_ctx->url=tfe_strdup(request->req_spec.url); query_ctx->is_undefined_obj=is_undefined_obj; p=future_to_promise(f); promise_set_ctx(p, query_ctx, cache_query_ctx_free_cb); - query_ctx->f_tango_cache_fetch=future_create("_cache_qry", wrap_cache_query_on_succ, wrap_cache_query_on_fail, p); + query_ctx->f_tango_cache_fetch=future_create("_cache_get", wrap_cache_query_on_succ, wrap_cache_query_on_fail, p); ret=tango_cache_fetch_object(handle->clients[thread_id], query_ctx->f_tango_cache_fetch, &meta); assert(ret==0); return WEB_CACHE_QUERING; } -struct wrap_cache_up_ctx +struct wrap_cache_put_ctx { char* url; time_t start; struct future* f; + struct cache_handle* ref_handle; }; -void wrap_cache_up_ctx_free(struct wrap_cache_up_ctx* ctx) +void wrap_cache_put_ctx_free(struct wrap_cache_put_ctx* ctx) { FREE(&(ctx->url)); future_destroy(ctx->f); @@ -405,15 +415,15 @@ void wrap_cache_up_ctx_free(struct wrap_cache_up_ctx* ctx) } static void wrap_cache_update_on_succ(future_result_t * result, void * user) { - struct wrap_cache_up_ctx* ctx=(struct wrap_cache_up_ctx*)user; - printf("cache upload success: %s elapse: %d\n", ctx->url, time(NULL)-ctx->start); - wrap_cache_up_ctx_free(ctx); + struct wrap_cache_put_ctx* ctx=(struct wrap_cache_put_ctx*)user; + TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache upload success: %s elapse: %d", ctx->url, time(NULL)-ctx->start); + wrap_cache_put_ctx_free(ctx); } static void wrap_cache_update_on_fail(enum e_future_error err, const char * what, void * user) { - struct wrap_cache_up_ctx* ctx=(struct wrap_cache_up_ctx*)user; - printf("cache upload failed: %s elapse: %d\n", ctx->url, time(NULL)-ctx->start); - wrap_cache_up_ctx_free(ctx); + struct wrap_cache_put_ctx* ctx=(struct wrap_cache_put_ctx*)user; + TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache upload failed: %s elapse: %d", ctx->url, time(NULL)-ctx->start); + wrap_cache_put_ctx_free(ctx); } struct cache_update_context* web_cache_update_start(struct cache_handle* handle, unsigned int thread_id, @@ -438,12 +448,14 @@ struct cache_update_context* web_cache_update_start(struct cache_handle* handle, case FORBIDDEN: case VERIFY: ATOMIC_INC(&(handle->stat_val[STAT_CACHE_UPLOAD_FORBIDEN])); + TFE_LOG_DEBUG(handle->logger, "cache update forbiden: %s", session->req->req_spec.url); return NULL; case ALLOWED: break; case UNDEFINED: if(handle->cache_undefined_obj_enabled && content_lencache_undefined_obj_min_size) { + TFE_LOG_DEBUG(handle->logger, "cache update forbiden: %s", session->req->req_spec.url); return NULL; } is_undefined_obj=1; @@ -461,15 +473,16 @@ struct cache_update_context* web_cache_update_start(struct cache_handle* handle, i++; memcpy(&meta.put, &resp_freshness, sizeof(resp_freshness)); - struct wrap_cache_up_ctx* wrap_cache_up_ctx=ALLOC(struct wrap_cache_up_ctx, 1); - wrap_cache_up_ctx->url=tfe_strdup(session->req->req_spec.url); - wrap_cache_up_ctx->start=time(NULL); - wrap_cache_up_ctx->f=future_create("cache_up", wrap_cache_update_on_succ, wrap_cache_update_on_fail, wrap_cache_up_ctx); - printf("cache update start: %s\n", wrap_cache_up_ctx->url); - write_ctx=tango_cache_update_start(handle->clients[thread_id], wrap_cache_up_ctx->f, &meta); + struct wrap_cache_put_ctx* _cache_put_ctx=ALLOC(struct wrap_cache_put_ctx, 1); + _cache_put_ctx->url=tfe_strdup(session->req->req_spec.url); + _cache_put_ctx->start=time(NULL); + _cache_put_ctx->ref_handle=handle; + _cache_put_ctx->f=future_create("cache_put", wrap_cache_update_on_succ, wrap_cache_update_on_fail, _cache_put_ctx); + TFE_LOG_DEBUG(handle->logger, "cache update allowed: %s", _cache_put_ctx->url); + write_ctx=tango_cache_update_start(handle->clients[thread_id], _cache_put_ctx->f, &meta); if(write_ctx==NULL)//exceed maximum cache memory size. { - wrap_cache_up_ctx_free(wrap_cache_up_ctx); + wrap_cache_put_ctx_free(_cache_put_ctx); return NULL; } if(is_undefined_obj)