trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jrushf...@apache.org
Subject [trafficserver] branch master updated: Patch to catch and invalidate an HTTP asset with negative bytes after cache_seek.
Date Tue, 07 Apr 2020 21:37:30 GMT
This is an automated email from the ASF dual-hosted git repository.

jrushford 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 a885dc6  Patch to catch and invalidate an HTTP asset with negative bytes after cache_seek.
a885dc6 is described below

commit a885dc63896e972bcde388c32019d258a6148398
Author: Brian Olsen <brian_olsen2@comcast.com>
AuthorDate: Wed Mar 11 17:31:42 2020 +0000

    Patch to catch and invalidate an HTTP asset with negative bytes after cache_seek.
---
 iocore/cache/CacheRead.cc      | 57 ++++++++++++++++++++++++++++++++++++++++--
 iocore/cache/P_CacheInternal.h |  1 +
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/iocore/cache/CacheRead.cc b/iocore/cache/CacheRead.cc
index 5dc267b..6c89987 100644
--- a/iocore/cache/CacheRead.cc
+++ b/iocore/cache/CacheRead.cc
@@ -717,8 +717,46 @@ CacheVC::openReadMain(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED
*/)
     bytes     = doc->len - doc_pos;
     if (is_debug_tag_set("cache_seek")) {
       char target_key_str[CRYPTO_HEX_SIZE];
-      key.toHexStr(target_key_str);
-      Debug("cache_seek", "Read # %d @ %" PRId64 "/%d for %" PRId64, fragment, doc_pos, doc->len,
bytes);
+      Debug("cache_seek", "Read # %d @ %" PRId64 "/%d for %" PRId64 " %s", fragment, doc_pos,
doc->len, bytes,
+            key.toHexStr(target_key_str));
+    }
+
+    // This shouldn't happen for HTTP assets but it does
+    // occasionally in production. This is a temporary fix
+    // to clean up broken objects until the root cause can
+    // be found. It must be the case that either the fragment
+    // offsets are incorrect or a fragment table isn't being
+    // created when it should be.
+    if (frag_type == CACHE_FRAG_TYPE_HTTP && bytes < 0) {
+      char xt[CRYPTO_HEX_SIZE];
+      char yt[CRYPTO_HEX_SIZE];
+
+      int url_length       = 0;
+      char const *url_text = nullptr;
+      if (request.valid()) {
+        url_text = request.url_get()->string_get_ref(&url_length);
+      }
+
+      int64_t prev_frag_size = 0;
+      if (fragment && frags) {
+        prev_frag_size = static_cast<int64_t>(frags[fragment - 1]);
+      }
+
+      Warning("cache_seek range request bug: read %s targ %s - %s frag # %d (prev_frag %"
PRId64 ") @ %" PRId64 "/%d for %" PRId64
+              " tot %" PRId64 " url '%.*s'",
+              doc->key.toHexStr(xt), key.toHexStr(yt), f.single_fragment ? "single" :
"multi", fragment, prev_frag_size, doc_pos,
+              doc->len, bytes, doc->total_len, url_length, url_text);
+
+      doc->magic = DOC_CORRUPT;
+
+      CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding);
+      if (!lock.is_locked()) {
+        SET_HANDLER(&CacheVC::openReadDirDelete);
+        VC_SCHED_LOCK_RETRY();
+      }
+
+      dir_delete(&earliest_key, vol, &earliest_dir);
+      goto Lerror;
     }
   }
   if (ntodo <= 0) {
@@ -1218,3 +1256,18 @@ Learliest:
   SET_HANDLER(&CacheVC::openReadStartEarliest);
   return openReadStartEarliest(event, e);
 }
+
+/*
+   Handle a directory delete event in case of some detected corruption.
+*/
+int
+CacheVC::openReadDirDelete(int event, Event *e)
+{
+  MUTEX_TRY_LOCK(lock, vol->mutex, mutex->thread_holding);
+  if (!lock.is_locked()) {
+    VC_SCHED_LOCK_RETRY();
+  }
+
+  dir_delete(&earliest_key, vol, &earliest_dir);
+  return calluser(VC_EVENT_ERROR);
+}
diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h
index eb9a72c..3e05f2c 100644
--- a/iocore/cache/P_CacheInternal.h
+++ b/iocore/cache/P_CacheInternal.h
@@ -326,6 +326,7 @@ struct CacheVC : public CacheVConnection {
   int openReadFromWriterMain(int event, Event *e);
   int openReadFromWriterFailure(int event, Event *);
   int openReadChooseWriter(int event, Event *e);
+  int openReadDirDelete(int event, Event *e);
 
   int openWriteCloseDir(int event, Event *e);
   int openWriteCloseHeadDone(int event, Event *e);


Mime
View raw message