Repository: trafficserver Updated Branches: refs/heads/master 5ae63a109 -> 3678a6e11
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/3678a6e1 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/3678a6e1 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/3678a6e1 Branch: refs/heads/master Commit: 3678a6e11b53520c35d06c7d8baed79f43f812e2 Parents: 5ae63a1 Author: Leif Hedstrom <[email protected]> Authored: Tue Jun 30 18:17:41 2015 -0600 Committer: Leif Hedstrom <[email protected]> Committed: Fri Jul 24 01:27:05 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/3678a6e1/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 */ }
