You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2015/07/29 01:40:29 UTC

[51/62] [abbrv] trafficserver git commit: TS-3729 cache_promote: defer TSHttpTxnServerRespNoStoreSet() to a global continuation, saves a possible race condition

TS-3729 cache_promote: defer TSHttpTxnServerRespNoStoreSet() to a global continuation, saves a possible race condition


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

Branch: refs/heads/6.0.x
Commit: bfddad17cec3ef9facf406f74c1963cb80e56d71
Parents: c14f874
Author: Leif Hedstrom <zw...@apache.org>
Authored: Fri Jul 24 01:52:53 2015 -0600
Committer: Leif Hedstrom <zw...@apache.org>
Committed: Fri Jul 24 01:52:53 2015 -0600

----------------------------------------------------------------------
 .../experimental/cache_promote/cache_promote.cc | 25 +++++++++++++++-----
 1 file changed, 19 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bfddad17/plugins/experimental/cache_promote/cache_promote.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/cache_promote/cache_promote.cc b/plugins/experimental/cache_promote/cache_promote.cc
index 9c2edb6..dab961d 100644
--- a/plugins/experimental/cache_promote/cache_promote.cc
+++ b/plugins/experimental/cache_promote/cache_promote.cc
@@ -34,6 +34,8 @@
 
 
 static const char *PLUGIN_NAME = "cache_promote";
+TSCont gNocacheCont;
+
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 // Note that all options for all policies has to go here. Not particularly pretty...
@@ -372,6 +374,20 @@ private:
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////
+// Little helper continuation, to turn off writing to the cache. ToDo: when we have proper
+// APIs to make requests / responses, we can remove this completely.
+static int
+cont_nocache_response(TSCont contp, TSEvent event, void *edata)
+{
+  TSHttpTxn txnp = static_cast<TSHttpTxn>(edata);
+
+  TSHttpTxnServerRespNoStoreSet(txnp, 1);
+  // Reenable and continue with the state machine.
+  TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
+  return 0;
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////
 // Main "plugin", a TXN hook in the TS_HTTP_READ_CACHE_HDR_HOOK. Unless the policy allows
 // caching, we will turn off the cache from here on for the TXN.
 //
@@ -399,7 +415,7 @@ cont_handle_policy(TSCont contp, TSEvent event, void *edata)
             TSDebug(PLUGIN_NAME, "cache-status is %d, and leaving cache on (promoted)", obj_status);
           } else {
             TSDebug(PLUGIN_NAME, "cache-status is %d, and turning off the cache (not promoted)", obj_status);
-            TSHttpTxnHookAdd(txnp, TS_HTTP_READ_RESPONSE_HDR_HOOK, contp);
+            TSHttpTxnHookAdd(txnp, TS_HTTP_READ_RESPONSE_HDR_HOOK, gNocacheCont);
           }
           break;
         default:
@@ -413,11 +429,6 @@ cont_handle_policy(TSCont contp, TSEvent event, void *edata)
     }
     break;
 
-  // Temporaray hack, to deal with the fact that we can turn off the cache earlier
-  case TS_EVENT_HTTP_READ_RESPONSE_HDR:
-    TSHttpTxnServerRespNoStoreSet(txnp, 1);
-    break;
-
   // Should not happen
   default:
     TSDebug(PLUGIN_NAME, "Unhandled event %d", (int)event);
@@ -447,6 +458,8 @@ TSRemapInit(TSRemapInterface *api_info, char *errbuf, int errbuf_size)
     return TS_ERROR;
   }
 
+  gNocacheCont = TSContCreate(cont_nocache_response, NULL);
+
   TSDebug(PLUGIN_NAME, "remap plugin is successfully initialized");
   return TS_SUCCESS; /* success */
 }