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
The following commit(s) were added to refs/heads/10.1.x by this push:
new 59f9b901b0 HRW: Better txn slot management (#12566) (#12589)
59f9b901b0 is described below
commit 59f9b901b080244956b3cc01b4ef3dc4b6df0a4d
Author: Chris McFarlen <[email protected]>
AuthorDate: Tue Oct 21 09:43:20 2025 -0400
HRW: Better txn slot management (#12566) (#12589)
* HRW: Better txn slot management
This also fixes a real bug, where the txn slot for the state variables could
overlap / conflict with the control mechanism and its txn slot. They need
to have different names.
* Add some docs to clarify slots naming
(cherry picked from commit 4af1b1cc8b82030440850fcd454c5028a7c248e6)
Co-authored-by: Leif Hedstrom <[email protected]>
---
.../api/functions/TSUserArgs.en.rst | 3 ++-
plugins/header_rewrite/statement.cc | 23 +++++++---------------
plugins/header_rewrite/statement.h | 15 +++++++++-----
3 files changed, 19 insertions(+), 22 deletions(-)
diff --git a/doc/developer-guide/api/functions/TSUserArgs.en.rst
b/doc/developer-guide/api/functions/TSUserArgs.en.rst
index a0b917ba40..aacf9ead1a 100644
--- a/doc/developer-guide/api/functions/TSUserArgs.en.rst
+++ b/doc/developer-guide/api/functions/TSUserArgs.en.rst
@@ -61,7 +61,8 @@ plugin can reserve a slot of a particular type by calling
:func:`TSUserArgIndexR
The type for which the plugin intend to reserve a slot. See
:code:`TSUserArgType` above.
:arg:`name`
- An identifying name for the plugin that reserved the index. Required.
+ An unique and identifying name for the reserved slot index. A plugin
registering
+ multiple slots (not recommended!) must make sure the identifier is unique.
:arg:`description`
An optional description of the use of the arg. This can be :code:`nullptr`.
diff --git a/plugins/header_rewrite/statement.cc
b/plugins/header_rewrite/statement.cc
index 979eb8f146..ca840d7a9b 100644
--- a/plugins/header_rewrite/statement.cc
+++ b/plugins/header_rewrite/statement.cc
@@ -73,14 +73,9 @@ Statement::initialize_hooks()
add_allowed_hook(TS_HTTP_TXN_CLOSE_HOOK);
}
-void
+int
Statement::acquire_txn_slot()
{
- // Don't do anything if we don't need it
- if (!need_txn_slot() || _txn_slot >= 0) {
- return;
- }
-
// Only call the index reservation once per plugin load
static int txn_slot_index = []() -> int {
int index = -1;
@@ -92,29 +87,25 @@ Statement::acquire_txn_slot()
return index;
}();
- _txn_slot = txn_slot_index;
+ return txn_slot_index;
}
-void
+int
Statement::acquire_txn_private_slot()
{
- // Don't do anything if we don't need it
- if (!need_txn_private_slot() || _txn_private_slot >= 0) {
- return;
- }
-
// Only call the index reservation once per plugin load
static int txn_private_slot_index = []() -> int {
- int index = -1;
+ int index = -1;
+ std::string name = std::string(PLUGIN_NAME) + "_priv";
- if (TS_ERROR == TSUserArgIndexReserve(TS_USER_ARGS_TXN, PLUGIN_NAME, "HRW
txn private variables", &index)) {
+ if (TS_ERROR == TSUserArgIndexReserve(TS_USER_ARGS_TXN, name.c_str(), "HRW
txn private variables", &index)) {
TSError("[%s] failed to reserve user arg index", PLUGIN_NAME);
return -1; // Fallback value
}
return index;
}();
- _txn_private_slot = txn_private_slot_index;
+ return txn_private_slot_index;
}
// Parse NextHop qualifiers
diff --git a/plugins/header_rewrite/statement.h
b/plugins/header_rewrite/statement.h
index acbdcd69d0..ce187b5cec 100644
--- a/plugins/header_rewrite/statement.h
+++ b/plugins/header_rewrite/statement.h
@@ -154,8 +154,13 @@ public:
{
TSReleaseAssert(_initialized == false);
initialize_hooks();
- acquire_txn_slot();
- acquire_txn_private_slot();
+
+ if (need_txn_slot()) {
+ _txn_slot = acquire_txn_slot();
+ }
+ if (need_txn_private_slot()) {
+ _txn_private_slot = acquire_txn_private_slot();
+ }
_initialized = true;
}
@@ -166,6 +171,9 @@ public:
return _initialized;
}
+ static int acquire_txn_slot();
+ static int acquire_txn_private_slot();
+
protected:
virtual void initialize_hooks();
@@ -196,9 +204,6 @@ protected:
int _txn_private_slot = -1;
private:
- void acquire_txn_slot();
- void acquire_txn_private_slot();
-
ResourceIDs _rsrc = RSRC_NONE;
TSHttpHookID _hook = TS_HTTP_READ_RESPONSE_HDR_HOOK;
std::vector<TSHttpHookID> _allowed_hooks;