This is an automated email from the ASF dual-hosted git repository.
zwoop 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 8ecad69415 First cut at header heap genIDs and new API (#11780)
8ecad69415 is described below
commit 8ecad69415a51d07c4b73f839b9b142fa536ca73
Author: Leif Hedstrom <[email protected]>
AuthorDate: Tue Oct 1 10:54:34 2024 -0700
First cut at header heap genIDs and new API (#11780)
---
include/proxy/hdrs/HdrHeap.h | 4 +++-
include/ts/ts.h | 6 ++++++
src/api/InkAPI.cc | 48 +++++++++++++++++++++++++++++++++++++++++++-
src/proxy/hdrs/HdrHeap.cc | 3 +++
4 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/include/proxy/hdrs/HdrHeap.h b/include/proxy/hdrs/HdrHeap.h
index 27f70248b4..7357a76f8f 100644
--- a/include/proxy/hdrs/HdrHeap.h
+++ b/include/proxy/hdrs/HdrHeap.h
@@ -274,6 +274,7 @@ public:
char *m_free_start;
char *m_data_start;
uint32_t m_size;
+ uint32_t m_genid;
bool m_writeable;
@@ -484,7 +485,8 @@ public:
void set(const HdrHeapSDKHandle *from);
const char *make_sdk_string(const char *raw_str, int raw_str_len);
- HdrHeap *m_heap = nullptr;
+ HdrHeap *m_heap = nullptr;
+ uint32_t m_genid = 0;
// In order to prevent gratitous refcounting,
// automatic C++ copies are disabled!
diff --git a/include/ts/ts.h b/include/ts/ts.h
index 76030df541..6db04d894e 100644
--- a/include/ts/ts.h
+++ b/include/ts/ts.h
@@ -332,6 +332,12 @@ TSMBuffer TSMBufferCreate(void);
*/
TSReturnCode TSMBufferDestroy(TSMBuffer bufp);
+/**
+ Check to see if an MBuffer is still valid, from since the time
+ it was acquired.
+ */
+bool TSMBufferIsValid(TSMBuffer bufp);
+
/* --------------------------------------------------------------------------
URLs */
/**
diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc
index b5ba00adfe..84eccca72d 100644
--- a/src/api/InkAPI.cc
+++ b/src/api/InkAPI.cc
@@ -393,9 +393,28 @@ sdk_sanity_check_mbuffer(TSMBuffer bufp)
return TS_ERROR;
}
+ // ToDo: Can we safely check here that TSMbufferIsValid() is true?
+
return TS_SUCCESS;
}
+// This will reset the TSMBuffer's genid to the current genid of the heap. Any
TS API
+// that returns a TSMBuffer should call this function before returning the
buffer to the user.
+// The user (plugin) is responsible for calling TSMBufferIsValid() before
using any previous
+// values returned by the TS API for the TSMBuffer.
+inline void
+sdk_revalidate_mbuffer(TSMBuffer bufp)
+{
+ HdrHeapSDKHandle *sdk_heap = (HdrHeapSDKHandle *)bufp;
+
+ // Lets not segfault in here, even though the bufp should have been
validated before calling this function.
+ if (unlikely(bufp == nullptr || sdk_heap->m_heap == nullptr)) {
+ return;
+ }
+
+ sdk_heap->m_genid = sdk_heap->m_heap->m_genid;
+}
+
TSReturnCode
sdk_sanity_check_mime_hdr_handle(TSMLoc field)
{
@@ -886,6 +905,15 @@ TSMBufferDestroy(TSMBuffer bufp)
return TS_SUCCESS;
}
+bool
+TSMBufferIsValid(TSMBuffer bufp)
+{
+ sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS);
+ HdrHeapSDKHandle *sdk_heap = (HdrHeapSDKHandle *)bufp;
+
+ return (sdk_heap->m_heap->m_genid == sdk_heap->m_genid);
+}
+
////////////////////////////////////////////////////////////////////
//
// URLs
@@ -3086,6 +3114,7 @@ TSCacheHttpInfoReqGet(TSCacheHttpInfo infop, TSMBuffer
*bufp, TSMLoc *obj)
*(reinterpret_cast<HTTPHdr **>(bufp)) = info->request_get();
*obj =
reinterpret_cast<TSMLoc>(info->request_get()->m_http);
sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
+ sdk_revalidate_mbuffer(*bufp);
}
void
@@ -3096,6 +3125,7 @@ TSCacheHttpInfoRespGet(TSCacheHttpInfo infop, TSMBuffer
*bufp, TSMLoc *obj)
*(reinterpret_cast<HTTPHdr **>(bufp)) = info->response_get();
*obj =
reinterpret_cast<TSMLoc>(info->response_get()->m_http);
sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
+ sdk_revalidate_mbuffer(*bufp);
}
time_t
@@ -3868,8 +3898,9 @@ TSHttpTxnClientReqGet(TSHttpTxn txnp, TSMBuffer *bufp,
TSMLoc *obj)
*obj =
reinterpret_cast<TSMLoc>(hptr->m_http);
if (sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS) {
hptr->mark_target_dirty();
+ sdk_revalidate_mbuffer(*bufp);
+
return TS_SUCCESS;
- ;
}
}
return TS_ERROR;
@@ -3891,6 +3922,7 @@ TSHttpTxnPristineUrlGet(TSHttpTxn txnp, TSMBuffer *bufp,
TSMLoc *url_loc)
*url_loc =
(TSMLoc)sm->t_state.unmapped_url.m_url_impl;
if (sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS) {
+ sdk_revalidate_mbuffer(*bufp);
if (*url_loc == nullptr) {
*url_loc = (TSMLoc)hptr->m_http->u.req.m_url_impl;
}
@@ -3976,6 +4008,8 @@ TSHttpTxnClientRespGet(TSHttpTxn txnp, TSMBuffer *bufp,
TSMLoc *obj)
*(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
*obj =
reinterpret_cast<TSMLoc>(hptr->m_http);
sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
+ sdk_revalidate_mbuffer(*bufp);
+
return TS_SUCCESS;
}
@@ -3996,6 +4030,8 @@ TSHttpTxnServerReqGet(TSHttpTxn txnp, TSMBuffer *bufp,
TSMLoc *obj)
*(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
*obj =
reinterpret_cast<TSMLoc>(hptr->m_http);
sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
+ sdk_revalidate_mbuffer(*bufp);
+
return TS_SUCCESS;
}
@@ -4016,6 +4052,8 @@ TSHttpTxnServerRespGet(TSHttpTxn txnp, TSMBuffer *bufp,
TSMLoc *obj)
*(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
*obj =
reinterpret_cast<TSMLoc>(hptr->m_http);
sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
+ sdk_revalidate_mbuffer(*bufp);
+
return TS_SUCCESS;
}
@@ -4056,6 +4094,7 @@ TSHttpTxnCachedReqGet(TSHttpTxn txnp, TSMBuffer *bufp,
TSMLoc *obj)
*(reinterpret_cast<HdrHeapSDKHandle **>(bufp)) = *handle;
*obj =
reinterpret_cast<TSMLoc>(cached_hdr->m_http);
sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
+ sdk_revalidate_mbuffer(*bufp);
return TS_SUCCESS;
}
@@ -4095,6 +4134,7 @@ TSHttpTxnCachedRespGet(TSHttpTxn txnp, TSMBuffer *bufp,
TSMLoc *obj)
*(reinterpret_cast<HdrHeapSDKHandle **>(bufp)) = *handle;
*obj =
reinterpret_cast<TSMLoc>(cached_hdr->m_http);
sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
+ sdk_revalidate_mbuffer(*bufp);
return TS_SUCCESS;
}
@@ -4131,6 +4171,7 @@ TSHttpTxnCachedRespModifiableGet(TSHttpTxn txnp,
TSMBuffer *bufp, TSMLoc *obj)
*(reinterpret_cast<HTTPHdr **>(bufp)) = c_resp;
*obj =
reinterpret_cast<TSMLoc>(c_resp->m_http);
sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
+ sdk_revalidate_mbuffer(*bufp);
return TS_SUCCESS;
}
@@ -4563,6 +4604,7 @@ TSHttpTxnTransformRespGet(TSHttpTxn txnp, TSMBuffer
*bufp, TSMLoc *obj)
if (hptr->valid()) {
*(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
*obj =
reinterpret_cast<TSMLoc>(hptr->m_http);
+ sdk_revalidate_mbuffer(*bufp);
return sdk_sanity_check_mbuffer(*bufp);
}
@@ -5496,6 +5538,7 @@ TSHttpAltInfoClientReqGet(TSHttpAltInfo infop, TSMBuffer
*bufp, TSMLoc *obj)
*(reinterpret_cast<HTTPHdr **>(bufp)) = &info->m_client_req;
*obj =
reinterpret_cast<TSMLoc>(info->m_client_req.m_http);
+ sdk_revalidate_mbuffer(*bufp);
return sdk_sanity_check_mbuffer(*bufp);
}
@@ -5509,6 +5552,7 @@ TSHttpAltInfoCachedReqGet(TSHttpAltInfo infop, TSMBuffer
*bufp, TSMLoc *obj)
*(reinterpret_cast<HTTPHdr **>(bufp)) = &info->m_cached_req;
*obj =
reinterpret_cast<TSMLoc>(info->m_cached_req.m_http);
+ sdk_revalidate_mbuffer(*bufp);
return sdk_sanity_check_mbuffer(*bufp);
}
@@ -5522,6 +5566,7 @@ TSHttpAltInfoCachedRespGet(TSHttpAltInfo infop, TSMBuffer
*bufp, TSMLoc *obj)
*(reinterpret_cast<HTTPHdr **>(bufp)) = &info->m_cached_resp;
*obj =
reinterpret_cast<TSMLoc>(info->m_cached_resp.m_http);
+ sdk_revalidate_mbuffer(*bufp);
return sdk_sanity_check_mbuffer(*bufp);
}
@@ -6567,6 +6612,7 @@ TSFetchPageRespGet(TSHttpTxn txnp, TSMBuffer *bufp,
TSMLoc *obj)
if (hptr->valid()) {
*(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
*obj =
reinterpret_cast<TSMLoc>(hptr->m_http);
+ sdk_revalidate_mbuffer(*bufp);
return sdk_sanity_check_mbuffer(*bufp);
}
diff --git a/src/proxy/hdrs/HdrHeap.cc b/src/proxy/hdrs/HdrHeap.cc
index 03ad762728..ccdcfe7d61 100644
--- a/src/proxy/hdrs/HdrHeap.cc
+++ b/src/proxy/hdrs/HdrHeap.cc
@@ -92,6 +92,7 @@ HdrHeap::init()
{
m_data_start = m_free_start = (reinterpret_cast<char *>(this)) +
HDR_HEAP_HDR_SIZE;
m_magic = HDR_BUF_MAGIC_ALIVE;
+ m_genid = 0;
m_writeable = true;
m_next = nullptr;
@@ -370,6 +371,8 @@ HdrHeap::coalesce_str_heaps(int incoming_size)
ink_assert(incoming_size >= 0);
ink_assert(m_writeable);
+ ++m_genid;
+
new_heap_size += required_space_for_evacuation();
HdrStrHeap *new_heap = HdrStrHeap::alloc(new_heap_size);