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


The following commit(s) were added to refs/heads/10.2.x by this push:
     new 937ceabeed Delay remap table publish until startup completes (#12988) 
(#13014)
937ceabeed is described below

commit 937ceabeedd6af760dc6d77f5377071d28c1bd49
Author: Brian Neradt <[email protected]>
AuthorDate: Mon Mar 23 17:36:04 2026 -0500

    Delay remap table publish until startup completes (#12988) (#13014)
    
    Build the initial remap table on a private pointer and publish it only
    after startup has finished any deferred @volume= initialization. This
    keeps the shared rewrite table hidden until startup-only remap walks are
    done.
    
    That ordering avoids touching the initial table after a reload can swap
    it out, while preserving the existing post-cache-init initialization
    path for cache volume records.
    
    
    (cherry picked from commit 7414299d2825c95cf36d1e8062a0ccf00160c972)
    
    Co-authored-by: bneradt <[email protected]>
---
 src/proxy/ReverseProxy.cc | 46 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 13 deletions(-)

diff --git a/src/proxy/ReverseProxy.cc b/src/proxy/ReverseProxy.cc
index 8deb9d0016..5972c20dac 100644
--- a/src/proxy/ReverseProxy.cc
+++ b/src/proxy/ReverseProxy.cc
@@ -30,6 +30,7 @@
 #include "tscore/ink_platform.h"
 #include "tscore/Filenames.h"
 #include <dlfcn.h>
+#include "iocore/cache/Cache.h"
 #include "iocore/eventsystem/ConfigProcessor.h"
 #include "proxy/ReverseProxy.h"
 #include "tscore/MatcherUtils.h"
@@ -61,6 +62,8 @@ thread_local PluginThreadContext *pluginThreadContext = 
nullptr;
 #define URL_REMAP_MODE_CHANGED        8
 #define HTTP_DEFAULT_REDIRECT_CHANGED 9
 
+static void init_table_volume_host_records(UrlRewrite &table);
+
 //
 // Begin API Functions
 //
@@ -68,17 +71,23 @@ int
 init_reverse_proxy()
 {
   ink_assert(rewrite_table.load() == nullptr);
-  reconfig_mutex = new_ProxyMutex();
-  rewrite_table.store(new UrlRewrite());
-
-  rewrite_table.load()->acquire();
+  reconfig_mutex      = new_ProxyMutex();
+  auto *initial_table = new UrlRewrite();
+  initial_table->acquire();
   Note("%s loading ...", ts::filename::REMAP);
-  if (!rewrite_table.load()->load()) {
+  if (!initial_table->load()) {
     Emergency("%s failed to load", ts::filename::REMAP);
   } else {
     Note("%s finished loading", ts::filename::REMAP);
   }
 
+  if (initial_table->is_valid() && CacheProcessor::IsCacheEnabled() == 
CacheInitState::INITIALIZED) {
+    // Initialize deferred @volume= mappings before publishing so startup-only
+    // remap walks cannot race a reload.
+    init_table_volume_host_records(*initial_table);
+  }
+
+  rewrite_table.store(initial_table, std::memory_order_release);
   RecRegisterConfigUpdateCb("proxy.config.url_remap.filename", url_rewrite_CB, 
(void *)FILE_CHANGED);
   RecRegisterConfigUpdateCb("proxy.config.proxy_name", url_rewrite_CB, (void 
*)TSNAME_CHANGED);
   RecRegisterConfigUpdateCb("proxy.config.reverse_proxy.enabled", 
url_rewrite_CB, (void *)REVERSE_CHANGED);
@@ -201,11 +210,27 @@ init_store_volume_host_records(UrlRewrite::MappingsStore 
&store)
   }
 }
 
+static void
+init_table_volume_host_records(UrlRewrite &table)
+{
+  Dbg(dbg_ctl_url_rewrite, "Initializing volume_host_rec for all remap rules 
after cache init");
+
+  init_store_volume_host_records(table.forward_mappings);
+  init_store_volume_host_records(table.reverse_mappings);
+  init_store_volume_host_records(table.permanent_redirects);
+  init_store_volume_host_records(table.temporary_redirects);
+  init_store_volume_host_records(table.forward_mappings_with_recv_port);
+}
+
 // This is called after the cache is initialized, since we may need the 
volume_host_records.
 // Must only be called during startup before any remap reload can occur.
 void
 init_remap_volume_host_records()
 {
+  if (CacheProcessor::IsCacheEnabled() != CacheInitState::INITIALIZED) {
+    return;
+  }
+
   UrlRewrite *table = rewrite_table.load(std::memory_order_acquire);
 
   if (!table) {
@@ -214,14 +239,9 @@ init_remap_volume_host_records()
 
   table->acquire();
 
-  Dbg(dbg_ctl_url_rewrite, "Initializing volume_host_rec for all remap rules 
after cache init");
-
-  // Initialize for all mapping stores
-  init_store_volume_host_records(table->forward_mappings);
-  init_store_volume_host_records(table->reverse_mappings);
-  init_store_volume_host_records(table->permanent_redirects);
-  init_store_volume_host_records(table->temporary_redirects);
-  init_store_volume_host_records(table->forward_mappings_with_recv_port);
+  if (table->is_valid()) {
+    init_table_volume_host_records(*table);
+  }
 
   table->release();
 }

Reply via email to