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

cmcfarlen pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 76a360cef2eec9abe9c07834bc1273d7d6f57d55
Author: Leif Hedstrom <[email protected]>
AuthorDate: Wed Jul 23 09:19:55 2025 +0200

    cache_promote: Bugfix, don't repurpose policies without labels (#12374)
    
    (cherry picked from commit bcc3d6ca6b66b0c86fa52c8b6dba002f006b53c7)
---
 plugins/cache_promote/cache_promote.cc |  4 ++--
 plugins/cache_promote/configs.cc       |  2 +-
 plugins/cache_promote/lru_policy.h     |  6 +++++-
 plugins/cache_promote/policy.h         | 15 +++++++--------
 4 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/plugins/cache_promote/cache_promote.cc 
b/plugins/cache_promote/cache_promote.cc
index 37daceefa3..21cba7cadc 100644
--- a/plugins/cache_promote/cache_promote.cc
+++ b/plugins/cache_promote/cache_promote.cc
@@ -77,13 +77,13 @@ cont_handle_policy(TSCont contp, TSEvent event, void *edata)
           // Do nothing, just let it handle the lookup.
           DBG("cache-status is %d (hit), nothing to do", obj_status);
 
-          if (config->getPolicy()->_stats_enabled) {
+          if (!config->getPolicy()->_stats_id.empty()) {
             TSStatIntIncrement(config->getPolicy()->_cache_hits_id, 1);
           }
           break;
         }
       }
-      if (config->getPolicy()->_stats_enabled) {
+      if (!config->getPolicy()->_stats_id.empty()) {
         TSStatIntIncrement(config->getPolicy()->_total_requests_id, 1);
       }
     } else {
diff --git a/plugins/cache_promote/configs.cc b/plugins/cache_promote/configs.cc
index 471f467835..58907125c3 100644
--- a/plugins/cache_promote/configs.cc
+++ b/plugins/cache_promote/configs.cc
@@ -74,7 +74,7 @@ PromotionConfig::factory(int argc, char *argv[])
         return false;
       } else {
         if (_policy && _policy->stats_add(optarg)) {
-          _policy->_stats_enabled = true;
+          _policy->_stats_id = optarg;
           DBG("stats collection is enabled");
         }
       }
diff --git a/plugins/cache_promote/lru_policy.h 
b/plugins/cache_promote/lru_policy.h
index c64ca31ee2..8632a7827a 100644
--- a/plugins/cache_promote/lru_policy.h
+++ b/plugins/cache_promote/lru_policy.h
@@ -120,8 +120,12 @@ public:
   const std::string
   id() const override
   {
+    if (_label.empty()) {
+      return ""; // This will prevent the policy factory from coalescing this 
policy
+    }
+
     return _label + ";LRU=b:" + std::to_string(_buckets) + ",h:" + 
std::to_string(_hits) + ",B:" + std::to_string(_bytes) +
-           ",i:" + std::to_string(_internal_enabled);
+           ",i:" + std::to_string(_internal_enabled) + ",e:" + _stats_id;
   }
 
   void
diff --git a/plugins/cache_promote/policy.h b/plugins/cache_promote/policy.h
index b0cbfef15f..95fa1de752 100644
--- a/plugins/cache_promote/policy.h
+++ b/plugins/cache_promote/policy.h
@@ -63,7 +63,7 @@ public:
   void
   decrementStat(const int stat, const int amount)
   {
-    if (_stats_enabled) {
+    if (!_stats_id.empty()) {
       TSStatIntDecrement(stat, amount);
     }
   }
@@ -71,7 +71,7 @@ public:
   void
   incrementStat(const int stat, const int amount)
   {
-    if (_stats_enabled) {
+    if (!_stats_id.empty()) {
       TSStatIntIncrement(stat, amount);
     }
   }
@@ -127,12 +127,11 @@ public:
   virtual void        usage() const                   = 0;
   virtual bool        stats_add(const char *remap_id) = 0;
 
-  // when true stats are incremented.
-  bool _stats_enabled     = false;
-  bool _internal_enabled  = false;
-  int  _cache_hits_id     = -1;
-  int  _promoted_id       = -1;
-  int  _total_requests_id = -1;
+  bool        _internal_enabled  = false;
+  int         _cache_hits_id     = -1;
+  int         _promoted_id       = -1;
+  int         _total_requests_id = -1;
+  std::string _stats_id          = "";
 
 private:
   float _sample = 0.0;

Reply via email to