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

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

commit 9a250e6b6b7956328a6930c765c68da7464dbc41
Author: Leif Hedstrom <[email protected]>
AuthorDate: Fri May 29 12:47:10 2026 -0600

    slice: Avoid redundant prefetch re-scheduling (#13215)
    
    * slice: Avoid redundant prefetch re-scheduling
    
    schedule_prefetch() ran on every server response and re-issued blocks
    already scheduled this request, which the in-flight dedup set does not
    catch. Track a per-request high-water mark so each block is prefetched
    at most once; update the slice_prefetch gold. Supersedes #13212.
    
    Co-authored-by: Masaori Koshiba <[email protected]>
    
    * slice: Address Copilot review (m_prefetch_hwm -> int)
    
    * slice: Use int64_t for prefetch block math
    
    Block numbers are int64_t (Range, Data::m_blocknum); widen the
    prefetch high-water mark and loop accordingly and narrow only at the
    BgBlockFetch::schedule() boundary. Addresses Copilot review.
    
    ---------
    
    Co-authored-by: Masaori Koshiba <[email protected]>
    (cherry picked from commit bcddd98bc1ffda715615d070b1eea21010436102)
---
 plugins/slice/Data.h                                    |  2 ++
 plugins/slice/util.cc                                   | 17 ++++++++++++++---
 .../pluginTest/slice/gold/slice_prefetch.gold           |  1 +
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/plugins/slice/Data.h b/plugins/slice/Data.h
index d298ebc817..0c19dfaafa 100644
--- a/plugins/slice/Data.h
+++ b/plugins/slice/Data.h
@@ -94,6 +94,8 @@ struct Data {
 
   bool m_prefetchable{false};
 
+  int64_t m_prefetch_hwm{-1}; // highest block this request has scheduled for 
prefetch
+
   HdrMgr m_req_hdrmgr;  // manager for server request
   HdrMgr m_resp_hdrmgr; // manager for client response
 
diff --git a/plugins/slice/util.cc b/plugins/slice/util.cc
index 6792a1969b..2f3a578629 100644
--- a/plugins/slice/util.cc
+++ b/plugins/slice/util.cc
@@ -61,15 +61,22 @@ schedule_prefetch(Data *const data)
   }
 
   std::string_view const url(urlstr, urllen);
-  int                    nextblocknum = data->m_blocknum + 1;
+  int64_t                nextblocknum = data->m_blocknum + 1;
 
   if (data->m_blocknum > 
data->m_req_range.firstBlockFor(data->m_config->m_blockbytes) + 1) {
     nextblocknum = data->m_blocknum + data->m_config->m_prefetchcount;
   }
 
-  for (int i = nextblocknum; i <= data->m_blocknum + 
data->m_config->m_prefetchcount; i++) {
+  int64_t const lastblocknum = data->m_blocknum + 
data->m_config->m_prefetchcount;
+
+  // Skip blocks already scheduled this request; re-issuing them races the 
inline reads.
+  if (nextblocknum <= data->m_prefetch_hwm) {
+    nextblocknum = data->m_prefetch_hwm + 1;
+  }
+
+  for (int64_t i = nextblocknum; i <= lastblocknum; i++) {
     if (data->m_req_range.blockIsInside(data->m_config->m_blockbytes, i)) {
-      if (BgBlockFetch::schedule(data, i, url)) {
+      if (BgBlockFetch::schedule(data, static_cast<int>(i), url)) {
         DEBUG_LOG("Background fetch requested");
       } else {
         DEBUG_LOG("Background fetch not requested");
@@ -77,6 +84,10 @@ schedule_prefetch(Data *const data)
     }
   }
 
+  if (lastblocknum > data->m_prefetch_hwm) {
+    data->m_prefetch_hwm = lastblocknum;
+  }
+
   TSfree(urlstr);
 }
 
diff --git a/tests/gold_tests/pluginTest/slice/gold/slice_prefetch.gold 
b/tests/gold_tests/pluginTest/slice/gold/slice_prefetch.gold
index 3445708de2..60a398b009 100644
--- a/tests/gold_tests/pluginTest/slice/gold/slice_prefetch.gold
+++ b/tests/gold_tests/pluginTest/slice/gold/slice_prefetch.gold
@@ -20,6 +20,7 @@ bytes 0-4/18 miss
 bytes ``/18 miss
 bytes ``/18 miss
 bytes ``/18 miss
+bytes 10-14/18 hit-fresh
 bytes 15-17/18 hit-fresh
 bytes 5-16/18 miss, none
 bytes 0-6/18 hit-fresh

Reply via email to