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

[trafficserver] 02/02: TS-4955: Allow Plugin VC accept continuation to be unlocked.

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

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

commit 3526b772efaa644e1bff1853d818b5792613e145
Author: James Peach <jp...@apache.org>
AuthorDate: Tue Oct 11 13:44:42 2016 -0700

    TS-4955: Allow Plugin VC accept continuation to be unlocked.
    
    We never need to hold the continuation lock when delivering
    NET_EVENT_ACCEPT, so allow a NULL continuation mutex in PluginVC to
    prevent lock contention on the plugin_http_accept object.
    
    We still hold the lock if it is present since in the intercept cases,
    the continuation can come from plugins that may be expecting us to
    lock. This lock is now optional, however, and it is not an error for
    the plugin to omit the mutex.
---
 proxy/InkAPI.cc                   | 26 ++++++--------------------
 proxy/PluginVC.cc                 | 29 +++++++++++++++++++----------
 proxy/http/HttpProxyServerMain.cc | 10 +++++-----
 3 files changed, 30 insertions(+), 35 deletions(-)

diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 8cd0645..17a07fd 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -664,12 +664,6 @@ sdk_sanity_check_null_ptr(void *ptr)
   return TS_SUCCESS;
 }
 
-static TSReturnCode
-sdk_sanity_check_mutex(Ptr<ProxyMutex> &m)
-{
-  return m ? TS_SUCCESS : TS_ERROR;
-}
-
 // Plugin metric IDs index the plugin RSB, so bounds check against that.
 static TSReturnCode
 sdk_sanity_check_stat_id(int id)
@@ -6651,33 +6645,25 @@ TSTransformOutputVConnGet(TSVConn connp)
 void
 TSHttpTxnServerIntercept(TSCont contp, TSHttpTxn txnp)
 {
+  HttpSM *http_sm = (HttpSM *)txnp;
+
   sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
   sdk_assert(sdk_sanity_check_continuation(contp) == TS_SUCCESS);
 
-  HttpSM *http_sm    = (HttpSM *)txnp;
-  INKContInternal *i = (INKContInternal *)contp;
-
-  // Must have a mutex
-  sdk_assert(sdk_sanity_check_mutex(i->mutex) == TS_SUCCESS);
-
   http_sm->plugin_tunnel_type = HTTP_PLUGIN_AS_SERVER;
-  http_sm->plugin_tunnel      = PluginVCCore::alloc(i);
+  http_sm->plugin_tunnel      = PluginVCCore::alloc((INKContInternal *)contp);
 }
 
 void
 TSHttpTxnIntercept(TSCont contp, TSHttpTxn txnp)
 {
+  HttpSM *http_sm = (HttpSM *)txnp;
+
   sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
   sdk_assert(sdk_sanity_check_continuation(contp) == TS_SUCCESS);
 
-  HttpSM *http_sm    = (HttpSM *)txnp;
-  INKContInternal *i = (INKContInternal *)contp;
-
-  // Must have a mutex
-  sdk_assert(sdk_sanity_check_mutex(i->mutex) == TS_SUCCESS);
-
   http_sm->plugin_tunnel_type = HTTP_PLUGIN_AS_INTERCEPT;
-  http_sm->plugin_tunnel      = PluginVCCore::alloc(i);
+  http_sm->plugin_tunnel      = PluginVCCore::alloc((INKContInternal *)contp);
 }
 
 // The API below require timer values as TSHRTime parameters
diff --git a/proxy/PluginVC.cc b/proxy/PluginVC.cc
index 77c4843..f0518ba 100644
--- a/proxy/PluginVC.cc
+++ b/proxy/PluginVC.cc
@@ -1102,14 +1102,19 @@ PluginVCCore::connect_re(Continuation *c)
 int
 PluginVCCore::state_send_accept_failed(int /* event ATS_UNUSED */, void * /* data ATS_UNUSED */)
 {
-  MUTEX_TRY_LOCK(lock, connect_to->mutex, this_ethread());
-
-  if (lock.is_locked()) {
+  if (connect_to->mutex == NULL) {
     connect_to->handleEvent(NET_EVENT_ACCEPT_FAILED, NULL);
     destroy();
   } else {
-    SET_HANDLER(&PluginVCCore::state_send_accept_failed);
-    eventProcessor.schedule_in(this, PVC_LOCK_RETRY_TIME);
+    MUTEX_TRY_LOCK(lock, connect_to->mutex, this_ethread());
+
+    if (lock.is_locked()) {
+      connect_to->handleEvent(NET_EVENT_ACCEPT_FAILED, NULL);
+      destroy();
+    } else {
+      SET_HANDLER(&PluginVCCore::state_send_accept_failed);
+      eventProcessor.schedule_in(this, PVC_LOCK_RETRY_TIME);
+    }
   }
 
   return 0;
@@ -1118,13 +1123,17 @@ PluginVCCore::state_send_accept_failed(int /* event ATS_UNUSED */, void * /* dat
 int
 PluginVCCore::state_send_accept(int /* event ATS_UNUSED */, void * /* data ATS_UNUSED */)
 {
-  MUTEX_TRY_LOCK(lock, connect_to->mutex, this_ethread());
-
-  if (lock.is_locked()) {
+  if (connect_to->mutex == NULL) {
     connect_to->handleEvent(NET_EVENT_ACCEPT, &passive_vc);
   } else {
-    SET_HANDLER(&PluginVCCore::state_send_accept);
-    eventProcessor.schedule_in(this, PVC_LOCK_RETRY_TIME);
+    MUTEX_TRY_LOCK(lock, connect_to->mutex, this_ethread());
+
+    if (lock.is_locked()) {
+      connect_to->handleEvent(NET_EVENT_ACCEPT, &passive_vc);
+    } else {
+      SET_HANDLER(&PluginVCCore::state_send_accept);
+      eventProcessor.schedule_in(this, PVC_LOCK_RETRY_TIME);
+    }
   }
 
   return 0;
diff --git a/proxy/http/HttpProxyServerMain.cc b/proxy/http/HttpProxyServerMain.cc
index b8e6a41..4a71f88 100644
--- a/proxy/http/HttpProxyServerMain.cc
+++ b/proxy/http/HttpProxyServerMain.cc
@@ -40,7 +40,7 @@
 #include "http2/Http2SessionAccept.h"
 
 HttpSessionAccept *plugin_http_accept             = NULL;
-HttpSessionAccept *plugin_http_transparent_accept = 0;
+HttpSessionAccept *plugin_http_transparent_accept = NULL;
 
 static SLL<SSLNextProtocolAccept> ssl_plugin_acceptors;
 static Ptr<ProxyMutex> ssl_plugin_mutex;
@@ -245,16 +245,16 @@ init_HttpProxyServer(int n_accept_threads)
   //   port but without going through the operating system
   //
   if (plugin_http_accept == NULL) {
-    plugin_http_accept        = new HttpSessionAccept;
-    plugin_http_accept->mutex = new_ProxyMutex();
+    plugin_http_accept = new HttpSessionAccept();
   }
+
   // Same as plugin_http_accept except outbound transparent.
   if (!plugin_http_transparent_accept) {
     HttpSessionAccept::Options ha_opt;
     ha_opt.setOutboundTransparent(true);
-    plugin_http_transparent_accept        = new HttpSessionAccept(ha_opt);
-    plugin_http_transparent_accept->mutex = new_ProxyMutex();
+    plugin_http_transparent_accept = new HttpSessionAccept(ha_opt);
   }
+
   if (!ssl_plugin_mutex) {
     ssl_plugin_mutex = new_ProxyMutex();
   }

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