You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by sh...@apache.org on 2016/10/20 22:26:27 UTC

[trafficserver] branch master updated: TS-4972: Configure collapsed_forwarding plugin as global or remap.

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

shinrich pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

The following commit(s) were added to refs/heads/master by this push:
       new  b5a1a29   TS-4972: Configure collapsed_forwarding plugin as global or remap.
b5a1a29 is described below

commit b5a1a290c010f32dd15db9d6f15770a2e122249c
Author: Susan Hinrichs <sh...@ieee.org>
AuthorDate: Fri Oct 14 15:38:12 2016 +0000

    TS-4972: Configure collapsed_forwarding plugin as global or remap.
---
 .../plugins/collapsed_forwarding.en.rst            |   8 +-
 .../collapsed_forwarding/collapsed_forwarding.cc   | 118 ++++++++++++++++-----
 2 files changed, 97 insertions(+), 29 deletions(-)

diff --git a/doc/admin-guide/plugins/collapsed_forwarding.en.rst b/doc/admin-guide/plugins/collapsed_forwarding.en.rst
index e1451c0..181bbb3 100644
--- a/doc/admin-guide/plugins/collapsed_forwarding.en.rst
+++ b/doc/admin-guide/plugins/collapsed_forwarding.en.rst
@@ -53,7 +53,7 @@ and perform the following::
 Using the plugin
 ----------------
 
-This plugin functions as a per remap plugin, and it takes two optional
+This plugin can function as a per remap plugin or a global plugin, and it takes two optional
 arguments for specifying the delay between successive retries and a max
 number of retries.
 
@@ -62,6 +62,12 @@ below to the specific remap line::
 
   @plugin=collapsed_forwarding.so @pparam=--delay=<delay> @pparam=--retries=<retries>
 
+To activate the plugin globally, in :file:`plugin.config`, add the following line::
+
+  collapsed_forwarding.so --delay=<delay> --retries=<retries>
+
+If the plugin is enabled both globally and per remap, Traffic Server will issue an error on startup.
+
 Functionality
 -------------
 
diff --git a/plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc b/plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc
index fb2c5dc..9e2d82c 100644
--- a/plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc
+++ b/plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc
@@ -74,6 +74,8 @@ static const char *ATS_INTERNAL_MESSAGE = "@Ats-Internal";
 static int OPEN_WRITE_FAIL_MAX_REQ_DELAY_RETRIES = 5;
 static int OPEN_WRITE_FAIL_REQ_DELAY_TIMEOUT     = 500;
 
+static bool global_init = false;
+
 typedef struct _RequestData {
   TSHttpTxn txnp;
   int wl_retry; // write lock failure retry count
@@ -221,15 +223,47 @@ on_send_response_header(RequestData *req, TSHttpTxn &txnp, TSCont &contp)
     req->wl_retry = 0;
   }
 
+  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
+  TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
+  return TS_SUCCESS;
+}
+
+static int
+on_txn_close(RequestData *req, TSHttpTxn &txnp, TSCont &contp)
+{
   // done..cleanup
   delete req;
   TSContDestroy(contp);
-
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
   TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
   return TS_SUCCESS;
 }
 
+static int collapsed_cont(TSCont contp, TSEvent event, void *edata);
+
+void
+setup_transaction_cont(TSHttpTxn rh)
+{
+  TSCont cont = TSContCreate(collapsed_cont, TSMutexCreate());
+
+  RequestData *req_data = new RequestData();
+
+  req_data->txnp     = rh;
+  req_data->wl_retry = 0;
+
+  int url_len = 0;
+  char *url   = TSHttpTxnEffectiveUrlStringGet(rh, &url_len);
+  req_data->req_url.assign(url, url_len);
+
+  TSfree(url);
+  TSContDataSet(cont, req_data);
+
+  TSHttpTxnHookAdd(rh, TS_HTTP_SEND_REQUEST_HDR_HOOK, cont);
+  TSHttpTxnHookAdd(rh, TS_HTTP_SEND_RESPONSE_HDR_HOOK, cont);
+  TSHttpTxnHookAdd(rh, TS_HTTP_READ_RESPONSE_HDR_HOOK, cont);
+  TSHttpTxnHookAdd(rh, TS_HTTP_OS_DNS_HOOK, cont);
+  TSHttpTxnHookAdd(rh, TS_HTTP_TXN_CLOSE_HOOK, cont);
+}
+
 static int
 collapsed_cont(TSCont contp, TSEvent event, void *edata)
 {
@@ -237,6 +271,11 @@ collapsed_cont(TSCont contp, TSEvent event, void *edata)
   RequestData *my_req = static_cast<RequestData *>(TSContDataGet(contp));
 
   switch (event) {
+  case TS_EVENT_HTTP_READ_REQUEST_HDR:
+    // Create per transaction state
+    setup_transaction_cont(txnp);
+    break;
+
   case TS_EVENT_HTTP_OS_DNS: {
     return on_OS_DNS(my_req, txnp);
   }
@@ -255,6 +294,9 @@ collapsed_cont(TSCont contp, TSEvent event, void *edata)
   case TS_EVENT_HTTP_SEND_RESPONSE_HDR: {
     return on_send_response_header(my_req, txnp, contp);
   }
+  case TS_EVENT_HTTP_TXN_CLOSE: {
+    return on_txn_close(my_req, txnp, contp);
+  }
   default: {
     TSDebug(DEBUG_TAG, "Unexpected event: %d", event);
     break;
@@ -265,49 +307,69 @@ collapsed_cont(TSCont contp, TSEvent event, void *edata)
   return TS_SUCCESS;
 }
 
-TSReturnCode
-TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* errbuf_size */)
-{
-  TSDebug(DEBUG_TAG, "plugin is succesfully initialized");
-  return TS_SUCCESS;
-}
-
-TSReturnCode
-TSRemapNewInstance(int argc, char *argv[], void ** /* ih */, char * /* errbuf */, int /* errbuf_size */)
+void
+process_args(int argc, const char **argv)
 {
   // basic argv processing..
-  for (int i = 2; i < argc; ++i) {
+  for (int i = 1; i < argc; ++i) {
     if (strncmp(argv[i], "--delay=", 8) == 0) {
       OPEN_WRITE_FAIL_REQ_DELAY_TIMEOUT = atoi((char *)(argv[i] + 8));
     } else if (strncmp(argv[i], "--retries=", 10) == 0) {
       OPEN_WRITE_FAIL_MAX_REQ_DELAY_RETRIES = atoi((char *)(argv[i] + 10));
     }
   }
-
-  return TS_SUCCESS;
 }
 
-TSRemapStatus
-TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
+/*
+ * Initialize globally
+ */
+void
+TSPluginInit(int argc, const char *argv[])
 {
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name   = (char *)DEBUG_TAG;
+  info.vendor_name   = (char *)"Apache Software Foundation";
+  info.support_email = (char *)"dev@trafficserver.apache.org";
+
+  if (TS_SUCCESS != TSPluginRegister(&info)) {
+    TSError("[%s] Plugin registration failed.", DEBUG_TAG);
+  }
+
+  process_args(argc, argv);
+
   TSCont cont = TSContCreate(collapsed_cont, TSMutexCreate());
 
-  RequestData *req_data = new RequestData();
+  TSDebug(DEBUG_TAG, "Global Initialized");
+  // Set up the per transaction state in the READ_REQUEST event
+  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, cont);
 
-  req_data->txnp     = rh;
-  req_data->wl_retry = 0;
+  global_init = true;
+}
 
-  int url_len = 0;
-  char *url   = TSHttpTxnEffectiveUrlStringGet(rh, &url_len);
-  req_data->req_url.assign(url, url_len);
+TSReturnCode
+TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* errbuf_size */)
+{
+  if (global_init) {
+    TSError("Cannot initialize %s as both global and remap plugin", DEBUG_TAG);
+    return TS_ERROR;
+  } else {
+    TSDebug(DEBUG_TAG, "plugin is succesfully initialized for remap");
+    return TS_SUCCESS;
+  }
+}
 
-  TSfree(url);
-  TSContDataSet(cont, req_data);
+TSReturnCode
+TSRemapNewInstance(int argc, char *argv[], void ** /* ih */, char * /* errbuf */, int /* errbuf_size */)
+{
+  process_args(argc - 1, const_cast<const char **>(argv + 1));
+  return TS_SUCCESS;
+}
 
-  TSHttpTxnHookAdd(rh, TS_HTTP_SEND_REQUEST_HDR_HOOK, cont);
-  TSHttpTxnHookAdd(rh, TS_HTTP_SEND_RESPONSE_HDR_HOOK, cont);
-  TSHttpTxnHookAdd(rh, TS_HTTP_READ_RESPONSE_HDR_HOOK, cont);
-  TSHttpTxnHookAdd(rh, TS_HTTP_OS_DNS_HOOK, cont);
+TSRemapStatus
+TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
+{
+  setup_transaction_cont(rh);
 
   return TSREMAP_NO_REMAP;
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].