This is an automated email from the ASF dual-hosted git repository. masaori pushed a commit to branch 8.1.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/8.1.x by this push: new 70a0b77 Do not provide a stale negative cache (#7422) (#7659) 70a0b77 is described below commit 70a0b7703d0fa96d1ee61e12a405b924767d3d3f Author: Masaori Koshiba <masa...@apache.org> AuthorDate: Fri Apr 2 07:56:56 2021 +0900 Do not provide a stale negative cache (#7422) (#7659) (cherry picked from commit 7b560411b2949b0648c134019bce3731e2d8f056) Co-authored-by: Kazuhiko <kazuh...@fdiary.net> --- proxy/http/HttpTransact.cc | 98 ++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc index 3801774..10e2908 100644 --- a/proxy/http/HttpTransact.cc +++ b/proxy/http/HttpTransact.cc @@ -4141,61 +4141,65 @@ HttpTransact::handle_cache_operation_on_forward_server_response(State *s) server_response_code == HTTP_STATUS_BAD_GATEWAY || server_response_code == HTTP_STATUS_SERVICE_UNAVAILABLE) && s->cache_info.action == CACHE_DO_UPDATE && s->txn_conf->negative_revalidating_enabled && is_stale_cache_response_returnable(s)) { - TxnDebug("http_trans", "[hcoofsr] negative revalidating: revalidate stale object and serve from cache"); - - s->cache_info.object_store.create(); - s->cache_info.object_store.request_set(&s->hdr_info.client_request); - s->cache_info.object_store.response_set(s->cache_info.object_read->response_get()); - base_response = s->cache_info.object_store.response_get(); - time_t exp_time = s->txn_conf->negative_revalidating_lifetime + ink_local_time(); - base_response->set_expires(exp_time); - - SET_VIA_STRING(VIA_CACHE_FILL_ACTION, VIA_CACHE_UPDATED); - HTTP_INCREMENT_DYN_STAT(http_cache_updates_stat); - - // unset Cache-control: "need-revalidate-once" (if it's set) - // This directive is used internally by T.S. to invalidate - // documents so that an invalidated document needs to be - // revalidated again. - base_response->unset_cooked_cc_need_revalidate_once(); - - if (is_request_conditional(&s->hdr_info.client_request) && - HttpTransactCache::match_response_to_request_conditionals(&s->hdr_info.client_request, - s->cache_info.object_read->response_get(), - s->response_received_time) == HTTP_STATUS_NOT_MODIFIED) { - s->next_action = SM_ACTION_INTERNAL_CACHE_UPDATE_HEADERS; - client_response_code = HTTP_STATUS_NOT_MODIFIED; - } else { - if (s->method == HTTP_WKSIDX_HEAD) { - s->cache_info.action = CACHE_DO_UPDATE; - s->next_action = SM_ACTION_INTERNAL_CACHE_NOOP; + HTTPStatus cached_response_code = s->cache_info.object_read->response_get()->status_get(); + if (!(cached_response_code == HTTP_STATUS_INTERNAL_SERVER_ERROR || cached_response_code == HTTP_STATUS_GATEWAY_TIMEOUT || + cached_response_code == HTTP_STATUS_BAD_GATEWAY || cached_response_code == HTTP_STATUS_SERVICE_UNAVAILABLE)) { + TxnDebug("http_trans", "[hcoofsr] negative revalidating: revalidate stale object and serve from cache"); + + s->cache_info.object_store.create(); + s->cache_info.object_store.request_set(&s->hdr_info.client_request); + s->cache_info.object_store.response_set(s->cache_info.object_read->response_get()); + base_response = s->cache_info.object_store.response_get(); + time_t exp_time = s->txn_conf->negative_revalidating_lifetime + ink_local_time(); + base_response->set_expires(exp_time); + + SET_VIA_STRING(VIA_CACHE_FILL_ACTION, VIA_CACHE_UPDATED); + HTTP_INCREMENT_DYN_STAT(http_cache_updates_stat); + + // unset Cache-control: "need-revalidate-once" (if it's set) + // This directive is used internally by T.S. to invalidate + // documents so that an invalidated document needs to be + // revalidated again. + base_response->unset_cooked_cc_need_revalidate_once(); + + if (is_request_conditional(&s->hdr_info.client_request) && + HttpTransactCache::match_response_to_request_conditionals(&s->hdr_info.client_request, + s->cache_info.object_read->response_get(), + s->response_received_time) == HTTP_STATUS_NOT_MODIFIED) { + s->next_action = SM_ACTION_INTERNAL_CACHE_UPDATE_HEADERS; + client_response_code = HTTP_STATUS_NOT_MODIFIED; } else { - s->cache_info.action = CACHE_DO_SERVE_AND_UPDATE; - s->next_action = SM_ACTION_SERVE_FROM_CACHE; + if (s->method == HTTP_WKSIDX_HEAD) { + s->cache_info.action = CACHE_DO_UPDATE; + s->next_action = SM_ACTION_INTERNAL_CACHE_NOOP; + } else { + s->cache_info.action = CACHE_DO_SERVE_AND_UPDATE; + s->next_action = SM_ACTION_SERVE_FROM_CACHE; + } + + client_response_code = s->cache_info.object_read->response_get()->status_get(); } - client_response_code = s->cache_info.object_read->response_get()->status_get(); - } + ink_assert(base_response->valid()); - ink_assert(base_response->valid()); + if (client_response_code == HTTP_STATUS_NOT_MODIFIED) { + ink_assert(GET_VIA_STRING(VIA_CLIENT_REQUEST) != VIA_CLIENT_SIMPLE); + SET_VIA_STRING(VIA_CLIENT_REQUEST, VIA_CLIENT_IMS); + SET_VIA_STRING(VIA_PROXY_RESULT, VIA_PROXY_NOT_MODIFIED); + } else { + SET_VIA_STRING(VIA_PROXY_RESULT, VIA_PROXY_SERVED); + } - if (client_response_code == HTTP_STATUS_NOT_MODIFIED) { - ink_assert(GET_VIA_STRING(VIA_CLIENT_REQUEST) != VIA_CLIENT_SIMPLE); - SET_VIA_STRING(VIA_CLIENT_REQUEST, VIA_CLIENT_IMS); - SET_VIA_STRING(VIA_PROXY_RESULT, VIA_PROXY_NOT_MODIFIED); - } else { - SET_VIA_STRING(VIA_PROXY_RESULT, VIA_PROXY_SERVED); - } + ink_assert(client_response_code != HTTP_STATUS_NONE); - ink_assert(client_response_code != HTTP_STATUS_NONE); + if (s->next_action == SM_ACTION_SERVE_FROM_CACHE && s->state_machine->do_transform_open()) { + set_header_for_transform(s, base_response); + } else { + build_response(s, base_response, &s->hdr_info.client_response, s->client_info.http_version, client_response_code); + } - if (s->next_action == SM_ACTION_SERVE_FROM_CACHE && s->state_machine->do_transform_open()) { - set_header_for_transform(s, base_response); - } else { - build_response(s, base_response, &s->hdr_info.client_response, s->client_info.http_version, client_response_code); + return; } - - return; } s->next_action = SM_ACTION_SERVER_READ;