This is an automated email from the ASF dual-hosted git repository.

scw00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new cb2382d  Fixed the compatibility with previous cache verison
cb2382d is described below

commit cb2382dbcaf0a3be8fd0ca391d3aa24343f69614
Author: scw00 <[email protected]>
AuthorDate: Tue Feb 26 16:38:17 2019 +0800

    Fixed the compatibility with previous cache verison
---
 iocore/cache/Cache.cc      | 12 ++++++-
 iocore/cache/I_CacheDefs.h |  2 +-
 proxy/hdrs/HTTP.cc         | 81 ++++++++++++++++++++++++++++++++++++++++++++++
 proxy/hdrs/HTTP.h          |  1 +
 4 files changed, 94 insertions(+), 2 deletions(-)

diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index 87b6f18..dd408c9 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -2139,10 +2139,20 @@ CacheVC::is_pread_capable()
 static void
 unmarshal_helper(Doc *doc, Ptr<IOBufferData> &buf, int &okay)
 {
+  using UnmarshalFunc           = int(char *buf, int len, RefCountObj 
*block_ref);
+  UnmarshalFunc *unmarshal_func = &HTTPInfo::unmarshal;
+  ts::VersionNumber version(doc->v_major, doc->v_minor);
+
+  // introduced by https://github.com/apache/trafficserver/pull/4874, this is 
used to distinguish the doc version
+  // before and after #4847
+  if (version < CACHE_DB_VERSION) {
+    unmarshal_func = &HTTPInfo::unmarshal_v24_1;
+  }
+
   char *tmp = doc->hdr();
   int len   = doc->hlen;
   while (len > 0) {
-    int r = HTTPInfo::unmarshal(tmp, len, buf.get());
+    int r = unmarshal_func(tmp, len, buf.get());
     if (r < 0) {
       ink_assert(!"CacheVC::handleReadDone unmarshal failed");
       okay = 0;
diff --git a/iocore/cache/I_CacheDefs.h b/iocore/cache/I_CacheDefs.h
index 619d20c..cdd39bb 100644
--- a/iocore/cache/I_CacheDefs.h
+++ b/iocore/cache/I_CacheDefs.h
@@ -33,7 +33,7 @@
 #define CACHE_ALT_REMOVED -2
 
 static const uint8_t CACHE_DB_MAJOR_VERSION = 24;
-static const uint8_t CACHE_DB_MINOR_VERSION = 1;
+static const uint8_t CACHE_DB_MINOR_VERSION = 2;
 // This is used in various comparisons because otherwise if the minor version 
is 0,
 // the compile fails because the condition is always true or false. Running it 
through
 // VersionNumber prevents that.
diff --git a/proxy/hdrs/HTTP.cc b/proxy/hdrs/HTTP.cc
index 8faf57e..50726d0 100644
--- a/proxy/hdrs/HTTP.cc
+++ b/proxy/hdrs/HTTP.cc
@@ -2136,6 +2136,87 @@ HTTPInfo::unmarshal(char *buf, int len, RefCountObj 
*block_ref)
   return alt->m_unmarshal_len;
 }
 
+int
+HTTPInfo::unmarshal_v24_1(char *buf, int len, RefCountObj *block_ref)
+{
+  HTTPCacheAlt *alt = (HTTPCacheAlt *)buf;
+  int orig_len      = len;
+
+  if (alt->m_magic == CACHE_ALT_MAGIC_ALIVE) {
+    // Already unmarshaled, must be a ram cache
+    //  it
+    ink_assert(alt->m_unmarshal_len > 0);
+    ink_assert(alt->m_unmarshal_len <= len);
+    return alt->m_unmarshal_len;
+  } else if (alt->m_magic != CACHE_ALT_MAGIC_MARSHALED) {
+    ink_assert(!"HTTPInfo::unmarshal bad magic");
+    return -1;
+  }
+
+  ink_assert(alt->m_unmarshal_len < 0);
+  alt->m_magic = CACHE_ALT_MAGIC_ALIVE;
+  ink_assert(alt->m_writeable == 0);
+  len -= HTTP_ALT_MARSHAL_SIZE;
+
+  if (alt->m_frag_offset_count > HTTPCacheAlt::N_INTEGRAL_FRAG_OFFSETS) {
+    // stuff that didn't fit in the integral slots.
+    int extra       = sizeof(FragOffset) * alt->m_frag_offset_count - 
sizeof(alt->m_integral_frag_offsets);
+    char *extra_src = buf + reinterpret_cast<intptr_t>(alt->m_frag_offsets);
+    // Actual buffer size, which must be a power of two.
+    // Well, technically not, because we never modify an unmarshalled fragment
+    // offset table, but it would be a nasty bug should that be done in the
+    // future.
+    int bcount = HTTPCacheAlt::N_INTEGRAL_FRAG_OFFSETS * 2;
+
+    while (bcount < alt->m_frag_offset_count) {
+      bcount *= 2;
+    }
+    alt->m_frag_offsets =
+      static_cast<FragOffset *>(ats_malloc(bcount * sizeof(FragOffset))); // 
WRONG - must round up to next power of 2.
+    memcpy(alt->m_frag_offsets, alt->m_integral_frag_offsets, 
sizeof(alt->m_integral_frag_offsets));
+    memcpy(alt->m_frag_offsets + HTTPCacheAlt::N_INTEGRAL_FRAG_OFFSETS, 
extra_src, extra);
+    len -= extra;
+  } else if (alt->m_frag_offset_count > 0) {
+    alt->m_frag_offsets = alt->m_integral_frag_offsets;
+  } else {
+    alt->m_frag_offsets = nullptr; // should really already be zero.
+  }
+
+  HdrHeap *heap   = (HdrHeap *)(alt->m_request_hdr.m_heap ? (buf + 
(intptr_t)alt->m_request_hdr.m_heap) : nullptr);
+  HTTPHdrImpl *hh = nullptr;
+  int tmp;
+  if (heap != nullptr) {
+    tmp = heap->unmarshal(len, HDR_HEAP_OBJ_HTTP_HEADER, (HdrHeapObjImpl 
**)&hh, block_ref);
+    if (hh == nullptr || tmp < 0) {
+      ink_assert(!"HTTPInfo::request unmarshal failed");
+      return -1;
+    }
+    len -= tmp;
+    alt->m_request_hdr.m_heap              = heap;
+    alt->m_request_hdr.m_http              = hh;
+    alt->m_request_hdr.m_mime              = hh->m_fields_impl;
+    alt->m_request_hdr.m_url_cached.m_heap = heap;
+  }
+
+  heap = (HdrHeap *)(alt->m_response_hdr.m_heap ? (buf + 
(intptr_t)alt->m_response_hdr.m_heap) : nullptr);
+  if (heap != nullptr) {
+    tmp = heap->unmarshal(len, HDR_HEAP_OBJ_HTTP_HEADER, (HdrHeapObjImpl 
**)&hh, block_ref);
+    if (hh == nullptr || tmp < 0) {
+      ink_assert(!"HTTPInfo::response unmarshal failed");
+      return -1;
+    }
+    len -= tmp;
+
+    alt->m_response_hdr.m_heap = heap;
+    alt->m_response_hdr.m_http = hh;
+    alt->m_response_hdr.m_mime = hh->m_fields_impl;
+  }
+
+  alt->m_unmarshal_len = orig_len - len;
+
+  return alt->m_unmarshal_len;
+}
+
 // bool HTTPInfo::check_marshalled(char* buf, int len)
 //  Checks a marhshalled HTTPInfo buffer to make
 //    sure it's sane.  Returns true if sane, false otherwise
diff --git a/proxy/hdrs/HTTP.h b/proxy/hdrs/HTTP.h
index a5fc4e6..a3adb75 100644
--- a/proxy/hdrs/HTTP.h
+++ b/proxy/hdrs/HTTP.h
@@ -1375,6 +1375,7 @@ public:
   inkcoreapi int marshal_length();
   inkcoreapi int marshal(char *buf, int len);
   static int unmarshal(char *buf, int len, RefCountObj *block_ref);
+  static int unmarshal_v24_1(char *buf, int len, RefCountObj *block_ref);
   void set_buffer_reference(RefCountObj *block_ref);
   int get_handle(char *buf, int len);
 

Reply via email to