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

masaori 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 32021ff2fb Cleanup: StripeSM (#11732)
32021ff2fb is described below

commit 32021ff2fbab643a60eb5800b25f2aad99d97752
Author: Masaori Koshiba <[email protected]>
AuthorDate: Fri Aug 23 10:37:18 2024 +0900

    Cleanup: StripeSM (#11732)
    
    * Move struct CacheVol into Stripe.h
    
    * Move struct AIO_failure_handler into P_CacheInternal.h
    
    * Rename P_CacheVol.h to StripeSM.h
    
    * Remove StripeSM:: functions from P_CacheInternal.h
    
    * Remove unused headers
    
    * Fix Docs
    
    * Remove unused foward declarations
---
 .../cache-architecture/data-structures.en.rst      |  2 +-
 src/iocore/cache/CacheDisk.cc                      |  2 +-
 src/iocore/cache/CacheEvacuateDocVC.cc             |  2 +-
 src/iocore/cache/CacheProcessor.cc                 |  2 +-
 src/iocore/cache/P_Cache.h                         |  2 +-
 src/iocore/cache/P_CacheInternal.h                 | 97 ++--------------------
 src/iocore/cache/Stripe.cc                         |  3 +-
 src/iocore/cache/Stripe.h                          | 19 ++++-
 src/iocore/cache/StripeSM.cc                       | 49 ++++++++++-
 src/iocore/cache/{P_CacheVol.h => StripeSM.h}      | 36 +-------
 10 files changed, 76 insertions(+), 138 deletions(-)

diff --git a/doc/developer-guide/cache-architecture/data-structures.en.rst 
b/doc/developer-guide/cache-architecture/data-structures.en.rst
index 2f113ec8cf..a511d1c6a4 100644
--- a/doc/developer-guide/cache-architecture/data-structures.en.rst
+++ b/doc/developer-guide/cache-architecture/data-structures.en.rst
@@ -183,7 +183,7 @@ Data Structures
 
 .. class:: Doc
 
-   Defined in :ts:git:`iocore/cache/P_CacheVol.h`.
+   Defined in :ts:git:`iocore/cache/StripeSM.h`.
 
    .. member:: uint32_t magic
 
diff --git a/src/iocore/cache/CacheDisk.cc b/src/iocore/cache/CacheDisk.cc
index 484a0ae631..df584460da 100644
--- a/src/iocore/cache/CacheDisk.cc
+++ b/src/iocore/cache/CacheDisk.cc
@@ -22,7 +22,7 @@
  */
 
 #include "P_Cache.h"
-#include "P_CacheVol.h"
+#include "StripeSM.h"
 
 void
 CacheDisk::incrErrors(const AIOCallback *io)
diff --git a/src/iocore/cache/CacheEvacuateDocVC.cc 
b/src/iocore/cache/CacheEvacuateDocVC.cc
index ad245ba74f..b8edde9e76 100644
--- a/src/iocore/cache/CacheEvacuateDocVC.cc
+++ b/src/iocore/cache/CacheEvacuateDocVC.cc
@@ -31,7 +31,7 @@
 #include "P_CacheDoc.h"
 #include "P_CacheHttp.h"
 #include "P_CacheInternal.h"
-#include "P_CacheVol.h"
+#include "StripeSM.h"
 #include "CacheEvacuateDocVC.h"
 #include "PreservationTable.h"
 
diff --git a/src/iocore/cache/CacheProcessor.cc 
b/src/iocore/cache/CacheProcessor.cc
index 1645b0e889..d1c80ba73c 100644
--- a/src/iocore/cache/CacheProcessor.cc
+++ b/src/iocore/cache/CacheProcessor.cc
@@ -26,7 +26,7 @@
 #include "iocore/cache/Store.h"
 #include "P_CacheDisk.h"
 #include "P_CacheInternal.h"
-#include "P_CacheVol.h"
+#include "StripeSM.h"
 #include "Stripe.h"
 
 // Must be included after P_CacheInternal.h.
diff --git a/src/iocore/cache/P_Cache.h b/src/iocore/cache/P_Cache.h
index 8a64009a96..bc33c9819d 100644
--- a/src/iocore/cache/P_Cache.h
+++ b/src/iocore/cache/P_Cache.h
@@ -36,7 +36,7 @@
 #include "P_CacheDisk.h"
 #include "P_CacheDir.h"
 #include "P_RamCache.h"
-#include "P_CacheVol.h"
+#include "StripeSM.h"
 #include "P_CacheInternal.h"
 #include "P_CacheHosting.h"
 #include "P_CacheHttp.h"
diff --git a/src/iocore/cache/P_CacheInternal.h 
b/src/iocore/cache/P_CacheInternal.h
index fa78d1009d..4102daacd0 100644
--- a/src/iocore/cache/P_CacheInternal.h
+++ b/src/iocore/cache/P_CacheInternal.h
@@ -151,6 +151,12 @@ int                 cache_write(CacheVC *, 
CacheHTTPInfoVector *);
 int                 get_alternate_index(CacheHTTPInfoVector *cache_vector, 
CacheKey key);
 CacheEvacuateDocVC *new_DocEvacuator(int nbytes, StripeSM *stripe);
 
+struct AIO_failure_handler : public Continuation {
+  int handle_disk_failure(int event, void *data);
+
+  AIO_failure_handler() : Continuation(new_ProxyMutex()) { 
SET_HANDLER(&AIO_failure_handler::handle_disk_failure); }
+};
+
 // inline Functions
 
 inline CacheVC *
@@ -376,97 +382,6 @@ CacheVC::writer_done()
   return false;
 }
 
-inline int
-StripeSM::close_write(CacheVC *cont)
-{
-  return open_dir.close_write(cont);
-}
-
-// Returns 0 on success or a positive error code on failure
-inline int
-StripeSM::open_write(CacheVC *cont, int allow_if_writers, int max_writers)
-{
-  StripeSM *stripe    = this;
-  bool      agg_error = false;
-  if (!cont->f.remove) {
-    agg_error = (!cont->f.update && 
this->_write_buffer.get_bytes_pending_aggregation() > 
cache_config_agg_write_backlog);
-#ifdef CACHE_AGG_FAIL_RATE
-    agg_error = agg_error || 
((uint32_t)mutex->thread_holding->generator.random() < (uint32_t)(UINT_MAX * 
CACHE_AGG_FAIL_RATE));
-#endif
-  }
-
-  if (agg_error) {
-    Metrics::Counter::increment(cache_rsb.write_backlog_failure);
-    
Metrics::Counter::increment(stripe->cache_vol->vol_rsb.write_backlog_failure);
-
-    return ECACHE_WRITE_FAIL;
-  }
-
-  if (open_dir.open_write(cont, allow_if_writers, max_writers)) {
-    return 0;
-  }
-  return ECACHE_DOC_BUSY;
-}
-
-inline int
-StripeSM::close_write_lock(CacheVC *cont)
-{
-  EThread *t = cont->mutex->thread_holding;
-  CACHE_TRY_LOCK(lock, mutex, t);
-  if (!lock.is_locked()) {
-    return -1;
-  }
-  return close_write(cont);
-}
-
-inline int
-StripeSM::open_write_lock(CacheVC *cont, int allow_if_writers, int max_writers)
-{
-  EThread *t = cont->mutex->thread_holding;
-  CACHE_TRY_LOCK(lock, mutex, t);
-  if (!lock.is_locked()) {
-    return -1;
-  }
-  return open_write(cont, allow_if_writers, max_writers);
-}
-
-inline OpenDirEntry *
-StripeSM::open_read_lock(CryptoHash *key, EThread *t)
-{
-  CACHE_TRY_LOCK(lock, mutex, t);
-  if (!lock.is_locked()) {
-    return nullptr;
-  }
-  return open_dir.open_read(key);
-}
-
-inline int
-StripeSM::begin_read_lock(CacheVC *cont)
-{
-  // no need for evacuation as the entire document is already in memory
-  if (cont->f.single_fragment) {
-    return 0;
-  }
-
-  EThread *t = cont->mutex->thread_holding;
-  CACHE_TRY_LOCK(lock, mutex, t);
-  if (!lock.is_locked()) {
-    return -1;
-  }
-  return begin_read(cont);
-}
-
-inline int
-StripeSM::close_read_lock(CacheVC *cont)
-{
-  EThread *t = cont->mutex->thread_holding;
-  CACHE_TRY_LOCK(lock, mutex, t);
-  if (!lock.is_locked()) {
-    return -1;
-  }
-  return close_read(cont);
-}
-
 inline int
 dir_delete_lock(CacheKey *key, StripeSM *stripe, ProxyMutex *m, Dir *del)
 {
diff --git a/src/iocore/cache/Stripe.cc b/src/iocore/cache/Stripe.cc
index b01cbfaf10..d6e784e7b9 100644
--- a/src/iocore/cache/Stripe.cc
+++ b/src/iocore/cache/Stripe.cc
@@ -21,9 +21,8 @@
   limitations under the License.
  */
 
-#include "P_CacheDoc.h"
 #include "P_CacheInternal.h"
-#include "P_CacheVol.h"
+#include "StripeSM.h"
 
 #include "tscore/ink_assert.h"
 #include "tscore/ink_memory.h"
diff --git a/src/iocore/cache/Stripe.h b/src/iocore/cache/Stripe.h
index 807c8bb001..d155468234 100644
--- a/src/iocore/cache/Stripe.h
+++ b/src/iocore/cache/Stripe.h
@@ -26,12 +26,12 @@
 #include "AggregateWriteBuffer.h"
 #include "P_CacheDir.h"
 #include "P_CacheDisk.h"
+#include "P_CacheStats.h"
 
 #include "iocore/cache/Store.h"
 
 #include "tscore/ink_align.h"
 #include "tscore/ink_memory.h"
-#include "tscore/ink_platform.h"
 
 #include <cstdint>
 
@@ -42,10 +42,23 @@
 #define ROUND_TO_SECTOR(_p, _x)  INK_ALIGN((_x), _p->sector_size)
 #define ROUND_TO(_x, _y)         INK_ALIGN((_x), (_y))
 
-// This is defined here so CacheVC can avoid including P_CacheVol.h.
+// This is defined here so CacheVC can avoid including StripeSM.h.
 #define RECOVERY_SIZE EVACUATION_SIZE // 8MB
 
-struct CacheVol;
+struct CacheVol {
+  int          vol_number       = -1;
+  int          scheme           = 0;
+  off_t        size             = 0;
+  int          num_vols         = 0;
+  bool         ramcache_enabled = true;
+  StripeSM   **stripes          = nullptr;
+  DiskStripe **disk_stripes     = nullptr;
+  LINK(CacheVol, link);
+  // per volume stats
+  CacheStatsBlock vol_rsb;
+
+  CacheVol() {}
+};
 
 struct StripteHeaderFooter {
   unsigned int      magic;
diff --git a/src/iocore/cache/StripeSM.cc b/src/iocore/cache/StripeSM.cc
index 72251b58b0..d590f31e65 100644
--- a/src/iocore/cache/StripeSM.cc
+++ b/src/iocore/cache/StripeSM.cc
@@ -25,7 +25,7 @@
 #include "P_CacheDoc.h"
 #include "P_CacheInternal.h"
 #include "P_CacheStats.h"
-#include "P_CacheVol.h"
+#include "StripeSM.h"
 #include "P_CacheDir.h"
 
 #include "CacheEvacuateDocVC.h"
@@ -35,8 +35,6 @@
 #include "iocore/cache/CacheDefs.h"
 #include "iocore/cache/CacheVC.h"
 
-#include "proxy/hdrs/HTTP.h"
-
 #include "iocore/aio/AIO.h"
 
 #include "iocore/eventsystem/Continuation.h"
@@ -48,11 +46,11 @@
 #include "tsutil/DbgCtl.h"
 #include "tsutil/Metrics.h"
 
+#include "tscore/InkErrno.h"
 #include "tscore/Diags.h"
 #include "tscore/hugepages.h"
 #include "tscore/ink_assert.h"
 #include "tscore/ink_hrtime.h"
-#include "tscore/ink_platform.h"
 #include "tscore/List.h"
 
 #include <cinttypes>
@@ -1385,3 +1383,46 @@ StripeSM::shutdown(EThread *shutdown_thread)
   ink_assert(B == dirlen);
   Dbg(dbg_ctl_cache_dir_sync, "done syncing dir for vol %s", 
this->hash_text.get());
 }
+
+// Returns 0 on success or a positive error code on failure
+int
+StripeSM::open_write(CacheVC *cont, int allow_if_writers, int max_writers)
+{
+  StripeSM *stripe    = this;
+  bool      agg_error = false;
+  if (!cont->f.remove) {
+    agg_error = (!cont->f.update && 
this->_write_buffer.get_bytes_pending_aggregation() > 
cache_config_agg_write_backlog);
+#ifdef CACHE_AGG_FAIL_RATE
+    agg_error = agg_error || 
((uint32_t)mutex->thread_holding->generator.random() < (uint32_t)(UINT_MAX * 
CACHE_AGG_FAIL_RATE));
+#endif
+  }
+
+  if (agg_error) {
+    Metrics::Counter::increment(cache_rsb.write_backlog_failure);
+    
Metrics::Counter::increment(stripe->cache_vol->vol_rsb.write_backlog_failure);
+
+    return ECACHE_WRITE_FAIL;
+  }
+
+  if (open_dir.open_write(cont, allow_if_writers, max_writers)) {
+    return 0;
+  }
+  return ECACHE_DOC_BUSY;
+}
+
+int
+StripeSM::open_write_lock(CacheVC *cont, int allow_if_writers, int max_writers)
+{
+  EThread *t = cont->mutex->thread_holding;
+  CACHE_TRY_LOCK(lock, mutex, t);
+  if (!lock.is_locked()) {
+    return -1;
+  }
+  return open_write(cont, allow_if_writers, max_writers);
+}
+
+int
+StripeSM::close_write(CacheVC *cont)
+{
+  return open_dir.close_write(cont);
+}
diff --git a/src/iocore/cache/P_CacheVol.h b/src/iocore/cache/StripeSM.h
similarity index 90%
rename from src/iocore/cache/P_CacheVol.h
rename to src/iocore/cache/StripeSM.h
index 47423598d4..415dc9f1f6 100644
--- a/src/iocore/cache/P_CacheVol.h
+++ b/src/iocore/cache/StripeSM.h
@@ -24,8 +24,6 @@
 #pragma once
 
 #include "P_CacheDir.h"
-#include "P_CacheDoc.h"
-#include "P_CacheStats.h"
 #include "P_RamCache.h"
 #include "AggregateWriteBuffer.h"
 #include "PreservationTable.h"
@@ -60,11 +58,7 @@
 // Documents
 
 struct Cache;
-class StripeSM;
-struct CacheDisk;
 struct StripeInitInfo;
-struct DiskStripe;
-struct CacheVol;
 class CacheEvacuateDocVC;
 
 class StripeSM : public Continuation, public Stripe
@@ -108,15 +102,11 @@ public:
   int open_write(CacheVC *cont, int allow_if_writers, int max_writers);
   int open_write_lock(CacheVC *cont, int allow_if_writers, int max_writers);
   int close_write(CacheVC *cont);
-  int close_write_lock(CacheVC *cont);
   int begin_read(CacheVC *cont) const;
-  int begin_read_lock(CacheVC *cont);
   // unused read-write interlock code
   // currently http handles a write-lock failure by retrying the read
   OpenDirEntry *open_read(const CryptoHash *key) const;
-  OpenDirEntry *open_read_lock(CryptoHash *key, EThread *t);
   int           close_read(CacheVC *cont) const;
-  int           close_read_lock(CacheVC *cont);
 
   int clear_dir_aio();
   int clear_dir();
@@ -238,27 +228,6 @@ private:
   int _copy_evacuator_to_aggregation(CacheVC *vc);
 };
 
-struct AIO_failure_handler : public Continuation {
-  int handle_disk_failure(int event, void *data);
-
-  AIO_failure_handler() : Continuation(new_ProxyMutex()) { 
SET_HANDLER(&AIO_failure_handler::handle_disk_failure); }
-};
-
-struct CacheVol {
-  int          vol_number       = -1;
-  int          scheme           = 0;
-  off_t        size             = 0;
-  int          num_vols         = 0;
-  bool         ramcache_enabled = true;
-  StripeSM   **stripes          = nullptr;
-  DiskStripe **disk_stripes     = nullptr;
-  LINK(CacheVol, link);
-  // per volume stats
-  CacheStatsBlock vol_rsb;
-
-  CacheVol() {}
-};
-
 // Global Data
 
 extern StripeSM                   **gstripes;
@@ -307,8 +276,9 @@ StripeSM::within_hit_evacuate_window(Dir const *xdir) const
   off_t oft       = dir_offset(xdir) - 1;
   off_t write_off = (header->write_pos + AGG_SIZE - start) / CACHE_BLOCK_SIZE;
   off_t delta     = oft - write_off;
-  if (delta >= 0)
+  if (delta >= 0) {
     return delta < hit_evacuate_window;
-  else
+  } else {
     return -delta > (data_blocks - hit_evacuate_window) && -delta < 
data_blocks;
+  }
 }

Reply via email to