You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by su...@apache.org on 2015/08/28 01:43:49 UTC

trafficserver git commit: [TS-3872] Enhance open_write_fail_action feature to support returning error on revalidation.

Repository: trafficserver
Updated Branches:
  refs/heads/master 2a5893a10 -> 55d57be2b


[TS-3872] Enhance open_write_fail_action feature to support returning error on revalidation.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/55d57be2
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/55d57be2
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/55d57be2

Branch: refs/heads/master
Commit: 55d57be2b348e49d490859fe60a2a8cb1bf83351
Parents: 2a5893a
Author: Sudheer Vinukonda <su...@yahoo-inc.com>
Authored: Thu Aug 27 23:43:00 2015 +0000
Committer: Sudheer Vinukonda <su...@yahoo-inc.com>
Committed: Thu Aug 27 23:43:38 2015 +0000

----------------------------------------------------------------------
 mgmt/RecordsConfig.cc      |  2 ++
 proxy/http/HttpSM.cc       |  9 ++++++---
 proxy/http/HttpTransact.cc | 23 ++++++++++++++---------
 proxy/http/HttpTransact.h  | 10 ++++++----
 4 files changed, 28 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/55d57be2/mgmt/RecordsConfig.cc
----------------------------------------------------------------------
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index 2db3c66..d5f6c25 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -653,6 +653,8 @@ static const RecordElement RecordsConfig[] =
   //       #  0 - default. disable cache and goto origin
   //       #  1 - return error if cache miss
   //       #  2 - serve stale until proxy.config.http.cache.max_stale_age, then goto origin, if refresh_miss
+  //       #  3 - return error if cache miss or serve stale until proxy.config.http.cache.max_stale_age, then goto origin, if refresh_miss
+  //       #  4 - return error if cache miss or error on stale until proxy.config.http.cache.max_stale_age, then goto origin, if refresh_miss
   {RECT_CONFIG, "proxy.config.http.cache.open_write_fail_action", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_NULL, NULL, RECA_NULL}
   ,
   //       #  when_to_revalidate has 4 options:

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/55d57be2/proxy/http/HttpSM.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index 2fab41c..4fce169 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -2374,17 +2374,20 @@ HttpSM::state_cache_open_write(int event, void *data)
     //  for reading
     if (t_state.redirect_info.redirect_in_process) {
       DebugSM("http_redirect", "[%" PRId64 "] CACHE_EVENT_OPEN_WRITE_FAILED during redirect follow", sm_id);
-      t_state.cache_open_write_fail_action = HttpTransact::CACHE_OPEN_WRITE_FAIL_DEFAULT;
+      t_state.cache_open_write_fail_action = HttpTransact::CACHE_WL_FAIL_ACTION_DEFAULT;
       t_state.cache_info.write_lock_state = HttpTransact::CACHE_WL_FAIL;
       break;
     }
-    if (t_state.txn_conf->cache_open_write_fail_action == HttpTransact::CACHE_OPEN_WRITE_FAIL_DEFAULT) {
+    if (t_state.txn_conf->cache_open_write_fail_action == HttpTransact::CACHE_WL_FAIL_ACTION_DEFAULT) {
       t_state.cache_info.write_lock_state = HttpTransact::CACHE_WL_FAIL;
       break;
     } else {
       t_state.cache_open_write_fail_action = t_state.txn_conf->cache_open_write_fail_action;
-      if (!t_state.cache_info.object_read) {
+      if (!t_state.cache_info.object_read ||
+          (t_state.cache_open_write_fail_action == HttpTransact::CACHE_WL_FAIL_ACTION_ERROR_ON_MISS_OR_REVALIDATE)) {
         // cache miss, set wl_state to fail
+        DebugSM("http", "[%" PRId64 "] cache object read %p, cache_wl_fail_action %d", sm_id, t_state.cache_info.object_read,
+                t_state.cache_open_write_fail_action);
         t_state.cache_info.write_lock_state = HttpTransact::CACHE_WL_FAIL;
         break;
       }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/55d57be2/proxy/http/HttpTransact.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 5e62a9d..ed20174 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -2951,29 +2951,34 @@ HttpTransact::handle_cache_write_lock(State *s)
     // No write lock, ignore the cache and proxy only;
     // FIX: Should just serve from cache if this is a revalidate
     s->cache_info.action = CACHE_DO_NO_ACTION;
-    if (s->cache_open_write_fail_action & CACHE_OPEN_WRITE_FAIL_ERROR_ON_MISS) {
-      DebugTxn("http_error", "cache_open_write_fail_action, cache miss, return error");
+    switch (s->cache_open_write_fail_action) {
+    case CACHE_WL_FAIL_ACTION_ERROR_ON_MISS:
+    case CACHE_WL_FAIL_ACTION_ERROR_ON_MISS_STALE_ON_REVALIDATE:
+    case CACHE_WL_FAIL_ACTION_ERROR_ON_MISS_OR_REVALIDATE:
+      DebugTxn("http_error", "cache_open_write_fail_action %d, cache miss, return error", s->cache_open_write_fail_action);
       s->cache_info.write_status = CACHE_WRITE_ERROR;
       build_error_response(s, HTTP_STATUS_BAD_GATEWAY, "Connection Failed", "connect#failed_connect", NULL);
       MIMEField *ats_field;
-      HTTPHdr *header = &(s->hdr_info.client_response);
-
+      HTTPHdr *header;
+      header = &(s->hdr_info.client_response);
       if ((ats_field = header->field_find(MIME_FIELD_ATS_INTERNAL, MIME_LEN_ATS_INTERNAL)) == NULL) {
         if (likely((ats_field = header->field_create(MIME_FIELD_ATS_INTERNAL, MIME_LEN_ATS_INTERNAL)) != NULL))
           header->field_attach(ats_field);
       }
       if (likely(ats_field)) {
-        Debug("http_error", "Adding Ats-Internal-Messages: %d", CACHE_WL_FAIL);
-        header->field_value_set_int(ats_field, CACHE_WL_FAIL);
+        int value = (s->cache_info.object_read) ? 1 : 0;
+        Debug("http_error", "Adding Ats-Internal-Messages: %d", value);
+        header->field_value_set_int(ats_field, value);
       } else {
-        Debug("http_error", "failed to add Ats-Internal-Messages: %d", CACHE_WL_FAIL);
+        Debug("http_error", "failed to add Ats-Internal-Messages");
       }
 
       TRANSACT_RETURN(SM_ACTION_SEND_ERROR_CACHE_NOOP, NULL);
       return;
-    } else {
+    default:
       s->cache_info.write_status = CACHE_WRITE_LOCK_MISS;
       remove_ims = true;
+      break;
     }
     break;
   case CACHE_WL_READ_RETRY:
@@ -7301,7 +7306,7 @@ HttpTransact::what_is_document_freshness(State *s, HTTPHdr *client_request, HTTP
   uint32_t cc_mask, cooked_cc_mask;
   uint32_t os_specifies_revalidate;
 
-  if (s->cache_open_write_fail_action & CACHE_OPEN_WRITE_FAIL_STALE_OR_REVALIDATE) {
+  if (s->cache_open_write_fail_action & CACHE_WL_FAIL_ACTION_STALE_ON_REVALIDATE) {
     if (is_stale_cache_response_returnable(s)) {
       DebugTxn("http_match", "[what_is_document_freshness] cache_serve_stale_on_write_lock_fail, return FRESH");
       return (FRESHNESS_FRESH);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/55d57be2/proxy/http/HttpTransact.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransact.h b/proxy/http/HttpTransact.h
index e2deecc..c5a9100 100644
--- a/proxy/http/HttpTransact.h
+++ b/proxy/http/HttpTransact.h
@@ -301,10 +301,12 @@ public:
   };
 
   enum CacheOpenWriteFailAction_t {
-    CACHE_OPEN_WRITE_FAIL_DEFAULT = 0,
-    CACHE_OPEN_WRITE_FAIL_ERROR_ON_MISS = 1,
-    CACHE_OPEN_WRITE_FAIL_STALE_OR_REVALIDATE = 2,
-    TOTAL_OPEN_WRITE_FAIL_ACTION_TYPES
+    CACHE_WL_FAIL_ACTION_DEFAULT = 0x00,
+    CACHE_WL_FAIL_ACTION_ERROR_ON_MISS = 0x01,
+    CACHE_WL_FAIL_ACTION_STALE_ON_REVALIDATE = 0x02,
+    CACHE_WL_FAIL_ACTION_ERROR_ON_MISS_STALE_ON_REVALIDATE = 0x03,
+    CACHE_WL_FAIL_ACTION_ERROR_ON_MISS_OR_REVALIDATE = 0x04,
+    TOTAL_CACHE_WL_FAIL_ACTION_TYPES
   };
 
   enum CacheWriteLock_t {