This is an automated email from the ASF dual-hosted git repository.
bneradt 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 f1b14c3744 multiplexer: debug logging and variable name updates
(#10964)
f1b14c3744 is described below
commit f1b14c3744218b086ff0c16c3457e7eaf2ed5861
Author: Brian Neradt <[email protected]>
AuthorDate: Thu Jan 4 16:15:51 2024 -0600
multiplexer: debug logging and variable name updates (#10964)
This is a multiplexer cleanup PR that adds debug logging to post.cc and
updates variable names for the transform in order to make their purpose
explicit (for the origin, for a copy, etc.). In post.cc, for instance,
both the incoming and outgoing VIO were named `vio`, with the difference
being whether it was called off of the state `s` variable or as a local
variable. This updates the names to clarify the purpose of each.
Other than logging changes, this patch makes no functional change to
multiplexer.
---
plugins/multiplexer/ats-multiplexer.cc | 2 +
plugins/multiplexer/dispatch.cc | 3 ++
plugins/multiplexer/fetcher.cc | 6 +--
plugins/multiplexer/fetcher.h | 9 ++--
plugins/multiplexer/post.cc | 80 ++++++++++++++++++++--------------
plugins/multiplexer/post.h | 7 +--
plugins/multiplexer/ts.cc | 5 +++
plugins/multiplexer/ts.h | 5 +++
8 files changed, 70 insertions(+), 47 deletions(-)
diff --git a/plugins/multiplexer/ats-multiplexer.cc
b/plugins/multiplexer/ats-multiplexer.cc
index 69121da8ec..6bc0fd7ca0 100644
--- a/plugins/multiplexer/ats-multiplexer.cc
+++ b/plugins/multiplexer/ats-multiplexer.cc
@@ -35,6 +35,8 @@
#error Please define a PLUGIN_TAG before including this file.
#endif
+using multiplexer_ns::dbg_ctl;
+
// 1s
const size_t DEFAULT_TIMEOUT = 1000000000000;
diff --git a/plugins/multiplexer/dispatch.cc b/plugins/multiplexer/dispatch.cc
index cb7356f394..55098c4799 100644
--- a/plugins/multiplexer/dispatch.cc
+++ b/plugins/multiplexer/dispatch.cc
@@ -31,6 +31,8 @@
#error Please define a PLUGIN_TAG before including this file.
#endif
+using multiplexer_ns::dbg_ctl;
+
extern Statistics statistics;
size_t timeout;
@@ -229,6 +231,7 @@ generateRequests(const Origins &o, const TSMBuffer buffer,
const TSMLoc location
const std::string &host = *iterator;
assert(!host.empty());
request.hostHeader(host);
+ Dbg(dbg_ctl, "Preparing request for \"%s\"", host.c_str());
r.push_back(Request(host, buffer, location));
}
}
diff --git a/plugins/multiplexer/fetcher.cc b/plugins/multiplexer/fetcher.cc
index a072ca026a..236cd7e73e 100644
--- a/plugins/multiplexer/fetcher.cc
+++ b/plugins/multiplexer/fetcher.cc
@@ -37,6 +37,7 @@ HttpParser::destroyParser()
bool
HttpParser::parse(io::IO &io)
{
+ using multiplexer_ns::dbg_ctl;
if (parsed_) {
return true;
}
@@ -62,8 +63,3 @@ HttpParser::parse(io::IO &io)
}
} // namespace ats
-
-namespace multiplexer_ns
-{
-DbgCtl dbg_ctl{PLUGIN_TAG};
-}
diff --git a/plugins/multiplexer/fetcher.h b/plugins/multiplexer/fetcher.h
index 48782b614b..14f78bf0ca 100644
--- a/plugins/multiplexer/fetcher.h
+++ b/plugins/multiplexer/fetcher.h
@@ -39,12 +39,6 @@
#define unlikely(x) __builtin_expect((x), 0)
-namespace multiplexer_ns
-{
-extern DbgCtl dbg_ctl;
-}
-using namespace multiplexer_ns;
-
namespace ats
{
struct HttpParser {
@@ -181,6 +175,8 @@ template <class T> struct HttpTransaction {
static int
handle(TSCont c, TSEvent e, void *data)
{
+ using multiplexer_ns::dbg_ctl;
+
Self *const self = static_cast<Self *const>(TSContDataGet(c));
assert(self != NULL);
switch (e) {
@@ -288,6 +284,7 @@ template <class T>
bool
get(const std::string &a, io::IO *const i, const int64_t l, const T &t, const
int64_t ti = 0)
{
+ using multiplexer_ns::dbg_ctl;
using Transaction = HttpTransaction<T>;
struct sockaddr_in socket;
socket.sin_family = AF_INET;
diff --git a/plugins/multiplexer/post.cc b/plugins/multiplexer/post.cc
index 969f966038..3e61cc6552 100644
--- a/plugins/multiplexer/post.cc
+++ b/plugins/multiplexer/post.cc
@@ -24,20 +24,24 @@
#include <limits>
#include "post.h"
+#include "ts/ts.h"
+#include "tsutil/DbgCtl.h"
#ifndef PLUGIN_TAG
#error Please define a PLUGIN_TAG before including this file.
#endif
+using multiplexer_ns::dbg_ctl;
+
PostState::~PostState()
{
- if (buffer != nullptr) {
- TSIOBufferDestroy(buffer);
- buffer = nullptr;
+ if (origin_buffer != nullptr) {
+ TSIOBufferDestroy(origin_buffer);
+ origin_buffer = nullptr;
}
}
-PostState::PostState(Requests &r) : buffer(nullptr), reader(nullptr),
vio(nullptr)
+PostState::PostState(Requests &r) : origin_buffer(nullptr),
clone_reader(nullptr), output_vio(nullptr)
{
assert(!r.empty());
requests.swap(r);
@@ -48,55 +52,65 @@ postTransform(const TSCont c, PostState &s)
{
assert(c != nullptr);
- const TSVConn vconnection = TSTransformOutputVConnGet(c);
- assert(vconnection != nullptr);
+ // As we collect data from the client, we need to write it to the origin.
This
+ // is for the original origin. The copies are handled via HttpTransaction
+ // logic in fetcher.h.
+ const TSVConn output_vconn = TSTransformOutputVConnGet(c);
+ assert(output_vconn != nullptr);
- const TSVIO vio = TSVConnWriteVIOGet(c);
- assert(vio != nullptr);
+ // The VIO from which we pull out the client's request.
+ const TSVIO input_vio = TSVConnWriteVIOGet(c);
+ assert(input_vio != nullptr);
- if (!s.buffer) {
- s.buffer = TSIOBufferCreate();
- assert(s.buffer != nullptr);
+ if (!s.origin_buffer) {
+ s.origin_buffer = TSIOBufferCreate();
+ assert(s.origin_buffer != nullptr);
- const TSIOBufferReader reader = TSIOBufferReaderAlloc(s.buffer);
- assert(reader != nullptr);
+ TSIOBufferReader origin_reader = TSIOBufferReaderAlloc(s.origin_buffer);
+ assert(origin_reader != nullptr);
- s.reader = TSIOBufferReaderClone(reader);
- assert(s.reader != nullptr);
+ s.clone_reader = TSIOBufferReaderClone(origin_reader);
+ assert(s.clone_reader != nullptr);
- s.vio = TSVConnWrite(vconnection, c, reader,
std::numeric_limits<int64_t>::max());
- assert(s.vio != nullptr);
+ s.output_vio = TSVConnWrite(output_vconn, c, origin_reader,
std::numeric_limits<int64_t>::max());
+ assert(s.output_vio != nullptr);
}
- if (!TSVIOBufferGet(vio)) {
- TSVIONBytesSet(s.vio, TSVIONDoneGet(vio));
- TSVIOReenable(s.vio);
+ if (!TSVIOBufferGet(input_vio)) {
+ if (s.output_vio) {
+ // This indicates that the request is done.
+ TSVIONBytesSet(s.output_vio, TSVIONDoneGet(input_vio));
+ TSVIOReenable(s.output_vio);
+ } else {
+ Dbg(dbg_ctl, "PostState::postTransform no input nor output VIO.
Returning.");
+ }
return;
}
- int64_t toWrite = TSVIONTodoGet(vio);
+ int64_t toWrite = TSVIONTodoGet(input_vio);
assert(toWrite >= 0);
if (toWrite > 0) {
- toWrite = std::min(toWrite, TSIOBufferReaderAvail(TSVIOReaderGet(vio)));
+ toWrite = std::min(toWrite,
TSIOBufferReaderAvail(TSVIOReaderGet(input_vio)));
assert(toWrite >= 0);
if (toWrite > 0) {
- TSIOBufferCopy(TSVIOBufferGet(s.vio), TSVIOReaderGet(vio), toWrite, 0);
- TSIOBufferReaderConsume(TSVIOReaderGet(vio), toWrite);
- TSVIONDoneSet(vio, TSVIONDoneGet(vio) + toWrite);
+ TSIOBufferCopy(TSVIOBufferGet(s.output_vio), TSVIOReaderGet(input_vio),
toWrite, 0);
+ TSIOBufferReaderConsume(TSVIOReaderGet(input_vio), toWrite);
+ TSVIONDoneSet(input_vio, TSVIONDoneGet(input_vio) + toWrite);
}
}
- if (TSVIONTodoGet(vio) > 0) {
+ if (TSVIONTodoGet(input_vio) > 0) {
if (toWrite > 0) {
- TSVIOReenable(s.vio);
- TSContCall(TSVIOContGet(vio), TS_EVENT_VCONN_WRITE_READY, vio);
+ assert(s.output_vio != nullptr);
+ TSVIOReenable(s.output_vio);
+ TSContCall(TSVIOContGet(input_vio), TS_EVENT_VCONN_WRITE_READY,
input_vio);
}
} else {
- TSVIONBytesSet(s.vio, TSVIONDoneGet(vio));
- TSVIOReenable(s.vio);
- TSContCall(TSVIOContGet(vio), TS_EVENT_VCONN_WRITE_COMPLETE, vio);
+ TSVIONBytesSet(s.output_vio, TSVIONDoneGet(input_vio));
+ TSVIOReenable(s.output_vio);
+ TSContCall(TSVIOContGet(input_vio), TS_EVENT_VCONN_WRITE_COMPLETE,
input_vio);
}
}
@@ -109,8 +123,8 @@ handlePost(TSCont c, TSEvent e, void *data)
assert(state != nullptr);
if (TSVConnClosedGet(c)) {
assert(data != nullptr);
- if (state->reader != nullptr) {
- addBody(state->requests, state->reader);
+ if (state->clone_reader != nullptr) {
+ addBody(state->requests, state->clone_reader);
}
dispatch(state->requests, timeout);
delete state;
diff --git a/plugins/multiplexer/post.h b/plugins/multiplexer/post.h
index 9534e8d2dd..800d1eec42 100644
--- a/plugins/multiplexer/post.h
+++ b/plugins/multiplexer/post.h
@@ -30,9 +30,10 @@
struct PostState {
Requests requests;
- TSIOBuffer buffer;
- TSIOBufferReader reader;
- TSVIO vio;
+ TSIOBuffer origin_buffer;
+ TSIOBufferReader clone_reader;
+ /// The VIO for the original (non-clone) origin.
+ TSVIO output_vio;
~PostState();
PostState(Requests &);
diff --git a/plugins/multiplexer/ts.cc b/plugins/multiplexer/ts.cc
index 6d176ca2e0..3f8629f27f 100644
--- a/plugins/multiplexer/ts.cc
+++ b/plugins/multiplexer/ts.cc
@@ -37,3 +37,8 @@ namespace io
} // namespace io
} // namespace ats
+
+namespace multiplexer_ns
+{
+DbgCtl dbg_ctl{PLUGIN_TAG};
+}
diff --git a/plugins/multiplexer/ts.h b/plugins/multiplexer/ts.h
index 5308652e3b..b8a4e57fb7 100644
--- a/plugins/multiplexer/ts.h
+++ b/plugins/multiplexer/ts.h
@@ -31,6 +31,11 @@
#include <string>
#include <ts/ts.h>
+namespace multiplexer_ns
+{
+extern DbgCtl dbg_ctl;
+}
+
namespace ats
{
namespace io