trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpe...@apache.org
Subject [1/6] trafficserver git commit: TS-3580: cache generation ID configuration
Date Mon, 15 Jun 2015 16:28:06 GMT
Repository: trafficserver
Updated Branches:
  refs/heads/master eb75a9d6d -> 2f8c94108


TS-3580: cache generation ID configuration

Add a new overrideable proxy.config.http.cache.generation configuration
option. This is a generation number that will be hashed into the
cache key before accessing the cache layer.

Update the X-Debug plugin to publish the generation ID into the
X-Cache-Generation header.


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

Branch: refs/heads/master
Commit: 643208d71e27274490bdcc2116f6060043855093
Parents: eb75a9d
Author: James Peach <jpeach@apache.org>
Authored: Fri Mar 13 21:07:50 2015 -0700
Committer: James Peach <jpeach@apache.org>
Committed: Mon Jun 15 09:09:31 2015 -0700

----------------------------------------------------------------------
 doc/reference/plugins/xdebug.en.rst   |  4 ++++
 lib/ts/apidefs.h.in                   |  1 +
 mgmt/RecordsConfig.cc                 |  2 ++
 plugins/experimental/xdebug/xdebug.cc | 25 +++++++++++++++++++++++++
 proxy/InkAPI.cc                       |  6 ++++++
 proxy/InkAPITest.cc                   |  3 ++-
 proxy/hdrs/URL.cc                     | 20 ++++++++++++++------
 proxy/hdrs/URL.h                      | 10 ++++++----
 proxy/http/HttpConfig.cc              |  2 ++
 proxy/http/HttpConfig.h               |  3 ++-
 10 files changed, 64 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/643208d7/doc/reference/plugins/xdebug.en.rst
----------------------------------------------------------------------
diff --git a/doc/reference/plugins/xdebug.en.rst b/doc/reference/plugins/xdebug.en.rst
index 0ee9197..16e0e76 100644
--- a/doc/reference/plugins/xdebug.en.rst
+++ b/doc/reference/plugins/xdebug.en.rst
@@ -59,6 +59,10 @@ X-Cache
     skipped     The cache lookup was skipped.
     ==========  ===========
 
+X-Cache-Generation
+  The cache generation ID for this transaction, as specified by the
+  :ts:cv:`proxy.config.http.cache.generation` configuration variable.
+
 X-Milestones
     The ``X-Milestones`` header contains detailed information about
     how long the transaction took to traverse portions of the HTTP

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/643208d7/lib/ts/apidefs.h.in
----------------------------------------------------------------------
diff --git a/lib/ts/apidefs.h.in b/lib/ts/apidefs.h.in
index bd847f2..e28f458 100644
--- a/lib/ts/apidefs.h.in
+++ b/lib/ts/apidefs.h.in
@@ -679,6 +679,7 @@ typedef enum {
   TS_CONFIG_HTTP_GLOBAL_USER_AGENT_HEADER,
   TS_CONFIG_HTTP_AUTH_SERVER_SESSION_PRIVATE,
   TS_CONFIG_HTTP_SLOW_LOG_THRESHOLD,
+  TS_CONFIG_HTTP_CACHE_GENERATION,
   TS_CONFIG_LAST_ENTRY
 } TSOverridableConfigKey;
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/643208d7/mgmt/RecordsConfig.cc
----------------------------------------------------------------------
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index c58c7fb..1e5d8e6 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -613,6 +613,8 @@ static const RecordElement RecordsConfig[] =
   //        #################
   {RECT_CONFIG, "proxy.config.http.cache.http", RECD_INT, "1", RECU_DYNAMIC, RR_NULL, RECC_INT,
"[0-1]", RECA_NULL}
   ,
+  {RECT_CONFIG, "proxy.config.http.cache.generation", RECD_INT, "-1", RECU_DYNAMIC, RR_NULL,
RECC_NULL, NULL, RECA_NULL}
+  ,
   // Enabling this setting allows the proxy to cache empty documents. This currently requires
   // that the response has a Content-Length: header, with a value of "0".
   {RECT_CONFIG, "proxy.config.http.cache.allow_empty_doc", RECD_INT, "1", RECU_DYNAMIC, RR_NULL,
RECC_NULL, "[0-1]", RECA_NULL }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/643208d7/plugins/experimental/xdebug/xdebug.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/xdebug/xdebug.cc b/plugins/experimental/xdebug/xdebug.cc
index 0fc38b6..ca45c30 100644
--- a/plugins/experimental/xdebug/xdebug.cc
+++ b/plugins/experimental/xdebug/xdebug.cc
@@ -28,6 +28,7 @@
 #define XHEADER_X_CACHE_KEY 0x0004u
 #define XHEADER_X_MILESTONES 0x0008u
 #define XHEADER_X_CACHE 0x0010u
+#define XHEADER_X_GENERATION 0x0020u
 
 static int XArgIndex = 0;
 static TSCont XInjectHeadersCont = NULL;
@@ -56,6 +57,24 @@ FindOrMakeHdrField(TSMBuffer buffer, TSMLoc hdr, const char *name, unsigned
len)
 }
 
 static void
+InjectGenerationHeader(TSHttpTxn txn, TSMBuffer buffer, TSMLoc hdr)
+{
+  TSMgmtInt value;
+  TSMLoc dst = TS_NULL_MLOC;
+
+  if (TSHttpTxnConfigIntGet(txn, TS_CONFIG_HTTP_CACHE_GENERATION, &value) == TS_SUCCESS)
{
+    dst = FindOrMakeHdrField(buffer, hdr, "X-Cache-Generation", lengthof("X-Cache-Generation"));
+    if (dst != TS_NULL_MLOC) {
+      TSReleaseAssert(TSMimeHdrFieldValueInt64Set(buffer, hdr, dst, -1 /* idx */, value)
== TS_SUCCESS);
+    }
+  }
+
+  if (dst != TS_NULL_MLOC) {
+    TSHandleMLocRelease(buffer, hdr, dst);
+  }
+}
+
+static void
 InjectCacheKeyHeader(TSHttpTxn txn, TSMBuffer buffer, TSMLoc hdr)
 {
   TSMLoc url = TS_NULL_MLOC;
@@ -236,6 +255,10 @@ XInjectResponseHeaders(TSCont /* contp */, TSEvent event, void *edata)
     InjectMilestonesHeader(txn, buffer, hdr);
   }
 
+  if (xheaders & XHEADER_X_GENERATION) {
+    InjectGenerationHeader(txn, buffer, hdr);
+  }
+
 done:
   TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
   return TS_EVENT_NONE;
@@ -282,6 +305,8 @@ XScanRequestHeaders(TSCont /* contp */, TSEvent event, void *edata)
         xheaders |= XHEADER_X_MILESTONES;
       } else if (header_field_eq("x-cache", value, vsize)) {
         xheaders |= XHEADER_X_CACHE;
+      } else if (header_field_eq("x-cache-generation", value, vsize)) {
+        xheaders |= XHEADER_X_GENERATION;
       } else if (header_field_eq("via", value, vsize)) {
         // If the client requests the Via header, enable verbose Via debugging for this transaction.
         TSHttpTxnConfigIntSet(txn, TS_CONFIG_HTTP_INSERT_RESPONSE_VIA_STR, 3);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/643208d7/proxy/InkAPI.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 31afa4c..295ae00 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -7958,6 +7958,10 @@ _conf_to_memberp(TSOverridableConfigKey conf, OverridableHttpConfigParams
*overr
   case TS_CONFIG_HTTP_CACHE_RANGE_WRITE:
     ret = &overridableHttpConfig->cache_range_write;
     break;
+  case TS_CONFIG_HTTP_CACHE_GENERATION:
+    typ = OVERRIDABLE_TYPE_INT;
+    ret = &overridableHttpConfig->cache_generation_number;
+    break;
   case TS_CONFIG_HTTP_POST_CHECK_CONTENT_LENGTH_ENABLED:
     ret = &overridableHttpConfig->post_check_content_length_enabled;
     break;
@@ -8228,6 +8232,8 @@ TSHttpTxnConfigFind(const char *name, int length, TSOverridableConfigKey
*conf,
   case 34:
     if (!strncmp(name, "proxy.config.http.chunking_enabled", length))
       cnf = TS_CONFIG_HTTP_CHUNKING_ENABLED;
+    else if (!strncmp(name, "proxy.config.http.cache.generation", length))
+      cnf = TS_CONFIG_HTTP_CACHE_GENERATION;
     break;
 
   case 35:

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/643208d7/proxy/InkAPITest.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPITest.cc b/proxy/InkAPITest.cc
index 9952225..2b744e8 100644
--- a/proxy/InkAPITest.cc
+++ b/proxy/InkAPITest.cc
@@ -7211,7 +7211,8 @@ const char *SDK_Overridable_Configs[TS_CONFIG_LAST_ENTRY] = {
   "proxy.config.ssl.hsts_max_age", "proxy.config.ssl.hsts_include_subdomains", "proxy.config.http.cache.open_read_retry_time",
   "proxy.config.http.cache.max_open_read_retries", "proxy.config.http.cache.range.write",
   "proxy.config.http.post.check.content_length.enabled", "proxy.config.http.global_user_agent_header",
-  "proxy.config.http.auth_server_session_private", "proxy.config.http.slow.log.threshold"};
+  "proxy.config.http.auth_server_session_private", "proxy.config.http.slow.log.threshold",
+  "proxy.config.http.cache.generation"};
 
 REGRESSION_TEST(SDK_API_OVERRIDABLE_CONFIGS)(RegressionTest *test, int /* atype ATS_UNUSED
*/, int *pstatus)
 {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/643208d7/proxy/hdrs/URL.cc
----------------------------------------------------------------------
diff --git a/proxy/hdrs/URL.cc b/proxy/hdrs/URL.cc
index a0529c8..e6cde0b 100644
--- a/proxy/hdrs/URL.cc
+++ b/proxy/hdrs/URL.cc
@@ -1572,7 +1572,7 @@ memcpy_tolower(char *d, const char *s, int n)
 // no buffer overflow, no unescaping needed
 
 static inline void
-url_MD5_get_fast(URLImpl *url, CryptoContext &ctx, CryptoHash *hash)
+url_MD5_get_fast(const URLImpl *url, CryptoContext &ctx, CryptoHash *hash, cache_generation_t
generation)
 {
   char buffer[BUFSIZE];
   char *p;
@@ -1603,12 +1603,16 @@ url_MD5_get_fast(URLImpl *url, CryptoContext &ctx, CryptoHash
*hash)
   *p++ = ((char *)&port)[1];
 
   ctx.update(buffer, p - buffer);
+  if (generation != -1) {
+    ctx.update(&generation, sizeof(generation));
+  }
+
   ctx.finalize(hash);
 }
 
 
 static inline void
-url_MD5_get_general(URLImpl *url, CryptoContext &ctx, CryptoHash &hash)
+url_MD5_get_general(const URLImpl *url, CryptoContext &ctx, CryptoHash &hash, cache_generation_t
generation)
 {
   char buffer[BUFSIZE];
   char *p, *e;
@@ -1675,25 +1679,29 @@ url_MD5_get_general(URLImpl *url, CryptoContext &ctx, CryptoHash
&hash)
   port = url_canonicalize_port(url->m_url_type, url->m_port);
 
   ctx.update(&port, sizeof(port));
+  if (generation != -1) {
+    ctx.update(&generation, sizeof(generation));
+  }
+
   ctx.finalize(hash);
 }
 
 void
-url_MD5_get(URLImpl *url, CryptoHash *hash)
+url_MD5_get(const URLImpl *url, CryptoHash *hash, cache_generation_t generation)
 {
   URLHashContext ctx;
   if ((url_hash_method != 0) && (url->m_url_type == URL_TYPE_HTTP) &&
       ((url->m_len_user + url->m_len_password + url->m_len_params + url->m_len_query)
== 0) &&
       (3 + 1 + 1 + 1 + 1 + 1 + 2 + url->m_len_scheme + url->m_len_host + url->m_len_path
< BUFSIZE) &&
       (memchr(url->m_ptr_host, '%', url->m_len_host) == NULL) && (memchr(url->m_ptr_path,
'%', url->m_len_path) == NULL)) {
-    url_MD5_get_fast(url, ctx, hash);
+    url_MD5_get_fast(url, ctx, hash, generation);
 #ifdef DEBUG
     CryptoHash md5_general;
-    url_MD5_get_general(url, ctx, md5_general);
+    url_MD5_get_general(url, ctx, md5_general, generation);
     ink_assert(*hash == md5_general);
 #endif
   } else {
-    url_MD5_get_general(url, ctx, *hash);
+    url_MD5_get_general(url, ctx, *hash, generation);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/643208d7/proxy/hdrs/URL.h
----------------------------------------------------------------------
diff --git a/proxy/hdrs/URL.h b/proxy/hdrs/URL.h
index 4d362ce..de82af1 100644
--- a/proxy/hdrs/URL.h
+++ b/proxy/hdrs/URL.h
@@ -33,6 +33,8 @@
 
 #include "ink_apidefs.h"
 
+typedef int64_t cache_generation_t;
+
 enum URLType {
   URL_TYPE_NONE,
   URL_TYPE_HTTP,
@@ -212,7 +214,7 @@ void url_called_set(URLImpl *url);
 char *url_string_get_buf(URLImpl *url, char *dstbuf, int dstbuf_size, int *length);
 
 const char *url_scheme_get(URLImpl *url, int *length);
-void url_MD5_get(URLImpl *url, CryptoHash *md5);
+void url_MD5_get(const URLImpl *url, CryptoHash *md5, cache_generation_t generation = -1);
 void url_host_MD5_get(URLImpl *url, CryptoHash *md5);
 const char *url_scheme_set(HdrHeap *heap, URLImpl *url, const char *value, int value_wks_idx,
int length, bool copy_string);
 
@@ -283,7 +285,7 @@ public:
   char *string_get(Arena *arena, int *length = NULL);
   char *string_get_ref(int *length = NULL);
   char *string_get_buf(char *dstbuf, int dsbuf_size, int *length = NULL);
-  void hash_get(CryptoHash *md5);
+  void hash_get(CryptoHash *md5, cache_generation_t generation = -1) const;
   void host_hash_get(CryptoHash *md5);
 
   const char *scheme_get(int *length);
@@ -470,10 +472,10 @@ URL::string_get_buf(char *dstbuf, int dsbuf_size, int *length)
   -------------------------------------------------------------------------*/
 
 inline void
-URL::hash_get(CryptoHash *md5)
+URL::hash_get(CryptoHash *md5, cache_generation_t generation) const
 {
   ink_assert(valid());
-  url_MD5_get(m_url_impl, md5);
+  url_MD5_get(m_url_impl, md5, generation);
 }
 
 /*-------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/643208d7/proxy/http/HttpConfig.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpConfig.cc b/proxy/http/HttpConfig.cc
index 02115bf..e3c5e17 100644
--- a/proxy/http/HttpConfig.cc
+++ b/proxy/http/HttpConfig.cc
@@ -1066,6 +1066,7 @@ HttpConfig::startup()
   // open read failure retries
   HttpEstablishStaticConfigLongLong(c.oride.max_cache_open_read_retries, "proxy.config.http.cache.max_open_read_retries");
   HttpEstablishStaticConfigLongLong(c.oride.cache_open_read_retry_time, "proxy.config.http.cache.open_read_retry_time");
+  HttpEstablishStaticConfigLongLong(c.oride.cache_generation_number, "proxy.config.http.cache.generation");
 
   // open write failure retries
   HttpEstablishStaticConfigLongLong(c.max_cache_open_write_retries, "proxy.config.http.cache.max_open_write_retries");
@@ -1329,6 +1330,7 @@ HttpConfig::reconfigure()
   // open read failure retries
   params->oride.max_cache_open_read_retries = m_master.oride.max_cache_open_read_retries;
   params->oride.cache_open_read_retry_time = m_master.oride.cache_open_read_retry_time;
+  params->oride.cache_generation_number = m_master.oride.cache_generation_number;
 
   // open write failure retries
   params->max_cache_open_write_retries = m_master.max_cache_open_write_retries;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/643208d7/proxy/http/HttpConfig.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpConfig.h b/proxy/http/HttpConfig.h
index aaf48fa..3bbba9f 100644
--- a/proxy/http/HttpConfig.h
+++ b/proxy/http/HttpConfig.h
@@ -381,7 +381,7 @@ struct OverridableHttpConfigParams {
       transaction_active_timeout_out(0), origin_max_connections(0), connect_attempts_max_retries(0),
       connect_attempts_max_retries_dead_server(3), connect_attempts_rr_retries(3), connect_attempts_timeout(30),
       post_connect_attempts_timeout(1800), down_server_timeout(300), client_abort_threshold(10),
freshness_fuzz_time(240),
-      freshness_fuzz_min_time(0), max_cache_open_read_retries(-1), cache_open_read_retry_time(10),
+      freshness_fuzz_min_time(0), max_cache_open_read_retries(-1), cache_open_read_retry_time(10),
cache_generation_number(-1),
       background_fill_active_timeout(60), http_chunking_size(4096), flow_high_water_mark(0),
flow_low_water_mark(0),
       default_buffer_size_index(8), default_buffer_water_mark(32768), slow_log_threshold(0),
 
@@ -546,6 +546,7 @@ struct OverridableHttpConfigParams {
   // open read failure retries.
   MgmtInt max_cache_open_read_retries;
   MgmtInt cache_open_read_retry_time; // time is in mseconds
+  MgmtInt cache_generation_number;
 
   MgmtInt background_fill_active_timeout;
 


Mime
View raw message