trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [trafficserver] branch master updated: Some tidying up of the global namespace.
Date Mon, 08 Apr 2019 14:25:41 GMT
This is an automated email from the ASF dual-hosted git repository.

amc 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 cdd6481  Some tidying up of the global namespace.
cdd6481 is described below

commit cdd6481aabb97bc1b620f5d668f04a168c246ea1
Author: Walter Karas <wkaras@verizonmedia.com>
AuthorDate: Mon Feb 11 18:03:19 2019 -0600

    Some tidying up of the global namespace.
---
 include/tscore/TSSystemState.h       | 92 ++++++++++++++++++++++++++++++++++++
 iocore/aio/AIO.cc                    |  4 +-
 iocore/aio/test_AIO.cc               |  3 +-
 iocore/eventsystem/I_EThread.h       |  2 -
 iocore/eventsystem/UnixEThread.cc    |  6 +--
 iocore/eventsystem/test_Event.cc     |  3 +-
 iocore/net/SSLNetVConnection.cc      |  5 +-
 iocore/net/UnixNetAccept.cc          |  4 +-
 iocore/net/UnixNetProcessor.cc       |  3 +-
 mgmt/ProcessManager.cc               |  5 +-
 proxy/ProxyClientSession.h           |  7 ++-
 proxy/logging/Log.cc                 |  5 +-
 src/traffic_server/traffic_server.cc | 22 ++++-----
 13 files changed, 126 insertions(+), 35 deletions(-)

diff --git a/include/tscore/TSSystemState.h b/include/tscore/TSSystemState.h
new file mode 100644
index 0000000..cc5bf3d
--- /dev/null
+++ b/include/tscore/TSSystemState.h
@@ -0,0 +1,92 @@
+/**
+  @file TSSystemState.h
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+*/
+
+#pragma once
+
+#include <tscore/ink_assert.h>
+#include <tscore/ink_defs.h>
+
+// Global status information for trafficserver
+//
+class TSSystemState
+{
+private:
+  struct Data {
+    bool ssl_handshaking_stopped;
+    bool event_system_shut_down;
+    bool draining;
+  };
+
+public:
+  static bool
+  is_ssl_handshaking_stopped()
+  {
+    return unlikely(_instance().ssl_handshaking_stopped);
+  }
+
+  static bool
+  is_event_system_shut_down()
+  {
+    return unlikely(_instance().event_system_shut_down);
+  }
+
+  // Keeps track if the server is in draining state, follows the proxy.node.config.draining
metric.
+  //
+  static bool
+  is_draining()
+  {
+    return unlikely(_instance().draining);
+  }
+
+  static void
+  stop_ssl_handshaking()
+  {
+    ink_assert(!_instance().ssl_handshaking_stopped);
+
+    _instance().ssl_handshaking_stopped = true;
+  }
+
+  static void
+  shut_down_event_system()
+  {
+    // For some reason this is triggered by the regression testing.
+    // ink_assert(_instance().ssl_handshaking_stopped && !_instance().event_system_shut_down);
+
+    _instance().event_system_shut_down = true;
+  }
+
+  static void
+  drain(bool enable)
+  {
+    _instance().draining = enable;
+  }
+
+private:
+  static Data &
+  _instance()
+  {
+    static Data d;
+
+    return d;
+  }
+};
diff --git a/iocore/aio/AIO.cc b/iocore/aio/AIO.cc
index ca7860c..29deaf6 100644
--- a/iocore/aio/AIO.cc
+++ b/iocore/aio/AIO.cc
@@ -25,6 +25,8 @@
  * Async Disk IO operations.
  */
 
+#include <tscore/TSSystemState.h>
+
 #include "P_AIO.h"
 
 #if AIO_MODE == AIO_MODE_NATIVE
@@ -457,7 +459,7 @@ aio_thread_main(void *arg)
   ink_mutex_acquire(&my_aio_req->aio_mutex);
   for (;;) {
     do {
-      if (unlikely(shutdown_event_system == true)) {
+      if (TSSystemState::is_event_system_shut_down()) {
         ink_mutex_release(&my_aio_req->aio_mutex);
         return nullptr;
       }
diff --git a/iocore/aio/test_AIO.cc b/iocore/aio/test_AIO.cc
index 4292e6d..4bc2c23 100644
--- a/iocore/aio/test_AIO.cc
+++ b/iocore/aio/test_AIO.cc
@@ -24,6 +24,7 @@
 #include "P_AIO.h"
 #include "InkAPIInternal.h"
 #include "tscore/I_Layout.h"
+#include "tscore/TSSystemState.h"
 #include <iostream>
 #include <fstream>
 
@@ -469,7 +470,7 @@ main(int /* argc ATS_UNUSED */, char *argv[])
     }
   }
 
-  while (!shutdown_event_system) {
+  while (!TSSystemState::is_event_system_shut_down()) {
     sleep(1);
   }
   delete main_thread;
diff --git a/iocore/eventsystem/I_EThread.h b/iocore/eventsystem/I_EThread.h
index 9a1bbcd..a0518fd 100644
--- a/iocore/eventsystem/I_EThread.h
+++ b/iocore/eventsystem/I_EThread.h
@@ -51,8 +51,6 @@ enum ThreadType {
   DEDICATED,
 };
 
-extern bool shutdown_event_system;
-
 /**
   Event System specific type of thread.
 
diff --git a/iocore/eventsystem/UnixEThread.cc b/iocore/eventsystem/UnixEThread.cc
index 06920db..d0f896d 100644
--- a/iocore/eventsystem/UnixEThread.cc
+++ b/iocore/eventsystem/UnixEThread.cc
@@ -21,6 +21,8 @@
   limitations under the License.
  */
 
+#include <tscore/TSSystemState.h>
+
 //////////////////////////////////////////////////////////////////////
 //
 // The EThread Class
@@ -45,8 +47,6 @@ char const *const EThread::STAT_NAME[] = {"proxy.process.eventloop.count",
 
 int const EThread::SAMPLE_COUNT[N_EVENT_TIMESCALES] = {10, 100, 1000};
 
-bool shutdown_event_system = false;
-
 int thread_max_heartbeat_mseconds = THREAD_MAX_HEARTBEAT_MSECONDS;
 
 EThread::EThread()
@@ -209,7 +209,7 @@ EThread::execute_regular()
 
   // give priority to immediate events
   for (;;) {
-    if (unlikely(shutdown_event_system == true)) {
+    if (TSSystemState::is_event_system_shut_down()) {
       return;
     }
 
diff --git a/iocore/eventsystem/test_Event.cc b/iocore/eventsystem/test_Event.cc
index 714aff5..78c47bb 100644
--- a/iocore/eventsystem/test_Event.cc
+++ b/iocore/eventsystem/test_Event.cc
@@ -23,6 +23,7 @@
 
 #include "I_EventSystem.h"
 #include "tscore/I_Layout.h"
+#include "tscore/TSSystemState.h"
 
 #include "diags.i"
 
@@ -75,7 +76,7 @@ main(int /* argc ATS_UNUSED */, const char * /* argv ATS_UNUSED */ [])
   process_killer *killer = new process_killer(new_ProxyMutex());
   eventProcessor.schedule_in(killer, HRTIME_SECONDS(10));
   eventProcessor.schedule_every(alrm, HRTIME_SECONDS(1));
-  while (!shutdown_event_system) {
+  while (!TSSystemState::is_event_system_shut_down()) {
     sleep(1);
   }
   return 0;
diff --git a/iocore/net/SSLNetVConnection.cc b/iocore/net/SSLNetVConnection.cc
index bc3cd8e..070e414 100644
--- a/iocore/net/SSLNetVConnection.cc
+++ b/iocore/net/SSLNetVConnection.cc
@@ -24,6 +24,7 @@
 #include "tscore/ink_config.h"
 #include "tscore/EventNotify.h"
 #include "tscore/I_Layout.h"
+#include "tscore/TSSystemState.h"
 #include "records/I_RecHttp.h"
 
 #include "InkAPIInternal.h" // Added to include the ssl_hook definitions
@@ -77,8 +78,6 @@ void SSL_set0_rbio(SSL *ssl, BIO *rbio);
 
 ClassAllocator<SSLNetVConnection> sslNetVCAllocator("sslNetVCAllocator");
 
-bool stop_ssl_handshake = false;
-
 namespace
 {
 /// Callback to get two locks.
@@ -961,7 +960,7 @@ SSLNetVConnection::free(EThread *t)
 int
 SSLNetVConnection::sslStartHandShake(int event, int &err)
 {
-  if (stop_ssl_handshake) {
+  if (TSSystemState::is_ssl_handshaking_stopped()) {
     Debug("ssl", "Stopping handshake due to server shutting down.");
     return EVENT_ERROR;
   }
diff --git a/iocore/net/UnixNetAccept.cc b/iocore/net/UnixNetAccept.cc
index a1141e4..2a2c2f7 100644
--- a/iocore/net/UnixNetAccept.cc
+++ b/iocore/net/UnixNetAccept.cc
@@ -21,6 +21,8 @@
   limitations under the License.
  */
 
+#include <tscore/TSSystemState.h>
+
 #include "P_Net.h"
 
 #ifdef ROUNDUP
@@ -333,7 +335,7 @@ NetAccept::do_blocking_accept(EThread *t)
       return -1;
     }
 
-    if (unlikely(shutdown_event_system == true)) {
+    if (TSSystemState::is_event_system_shut_down()) {
       return -1;
     }
 
diff --git a/iocore/net/UnixNetProcessor.cc b/iocore/net/UnixNetProcessor.cc
index e9896d5..488f6db 100644
--- a/iocore/net/UnixNetProcessor.cc
+++ b/iocore/net/UnixNetProcessor.cc
@@ -24,6 +24,7 @@
 #include "P_Net.h"
 #include "tscore/InkErrno.h"
 #include "tscore/ink_sock.h"
+#include "tscore/TSSystemState.h"
 #include "P_SSLNextProtocolAccept.h"
 
 // For Stat Pages
@@ -205,7 +206,7 @@ NetProcessor::stop_accept()
 Action *
 UnixNetProcessor::connect_re_internal(Continuation *cont, sockaddr const *target, NetVCOptions
*opt)
 {
-  if (unlikely(shutdown_event_system == true)) {
+  if (TSSystemState::is_event_system_shut_down()) {
     return ACTION_RESULT_NONE;
   }
   EThread *t             = cont->mutex->thread_holding;
diff --git a/mgmt/ProcessManager.cc b/mgmt/ProcessManager.cc
index 35d2b3c..abfcb9e 100644
--- a/mgmt/ProcessManager.cc
+++ b/mgmt/ProcessManager.cc
@@ -25,6 +25,7 @@
 #include "ProcessManager.h"
 
 #include "tscore/ink_apidefs.h"
+#include "tscore/TSSystemState.h"
 #include "MgmtSocket.h"
 #include "tscore/I_Layout.h"
 
@@ -166,13 +167,13 @@ ProcessManager::processManagerThread(void *arg)
 
     if (pmgmt->require_lm) {
       ret = pmgmt->pollLMConnection();
-      if (ret < 0 && pmgmt->running && !shutdown_event_system) {
+      if (ret < 0 && pmgmt->running && !TSSystemState::is_event_system_shut_down())
{
         Alert("exiting with read error from process manager: %s", strerror(-ret));
       }
     }
 
     ret = pmgmt->processSignalQueue();
-    if (ret < 0 && pmgmt->running && !shutdown_event_system) {
+    if (ret < 0 && pmgmt->running && !TSSystemState::is_event_system_shut_down())
{
       Alert("exiting with write error from process manager: %s", strerror(-ret));
     }
   }
diff --git a/proxy/ProxyClientSession.h b/proxy/ProxyClientSession.h
index 241da9b..7c6acf9 100644
--- a/proxy/ProxyClientSession.h
+++ b/proxy/ProxyClientSession.h
@@ -25,6 +25,7 @@
 
 #include "tscore/ink_platform.h"
 #include "tscore/ink_resolver.h"
+#include "tscore/TSSystemState.h"
 #include <string_view>
 #include "P_Net.h"
 #include "InkAPIInternal.h"
@@ -69,9 +70,7 @@ struct ProxyError {
   uint32_t code       = 0;
 };
 
-// A little ugly, but this global is tracked by traffic_server.
-extern bool ts_is_draining;
-
+/// Abstract class for HttpSM to interface with any session
 class ProxyClientSession : public VConnection
 {
 public:
@@ -149,7 +148,7 @@ public:
   bool
   is_draining() const
   {
-    return ts_is_draining;
+    return TSSystemState::is_draining();
   }
 
   // Initiate an API hook invocation.
diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
index 04038f1..e3870ac 100644
--- a/proxy/logging/Log.cc
+++ b/proxy/logging/Log.cc
@@ -33,6 +33,7 @@
 
  ***************************************************************************/
 #include "tscore/ink_platform.h"
+#include "tscore/TSSystemState.h"
 #include "P_EventSystem.h"
 #include "P_Net.h"
 #include "I_Machine.h"
@@ -1248,7 +1249,7 @@ Log::preproc_thread_main(void *args)
   Log::preproc_notify[idx].lock();
 
   while (true) {
-    if (unlikely(shutdown_event_system == true)) {
+    if (TSSystemState::is_event_system_shut_down()) {
       return nullptr;
     }
     size_t buffers_preproced = 0;
@@ -1291,7 +1292,7 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */)
   Log::flush_notify->lock();
 
   while (true) {
-    if (unlikely(shutdown_event_system == true)) {
+    if (TSSystemState::is_event_system_shut_down()) {
       return nullptr;
     }
     fdata = (LogFlushData *)ink_atomiclist_popall(flush_data_list);
diff --git a/src/traffic_server/traffic_server.cc b/src/traffic_server/traffic_server.cc
index 0927450..689a2ee 100644
--- a/src/traffic_server/traffic_server.cc
+++ b/src/traffic_server/traffic_server.cc
@@ -171,12 +171,6 @@ static bool signal_received[NSIG];
 // -1: cache is already initialized, don't delay.
 static int delay_listen_for_cache_p;
 
-// Keeps track if the server is in draining state, follows the proxy.node.config.draining
metric
-bool ts_is_draining = false;
-
-// Flag to stop ssl handshakes during shutdown.
-extern bool stop_ssl_handshake;
-
 AppVersionInfo appVersionInfo; // Build info for this application
 
 static ArgumentDescription argument_descriptions[] = {
@@ -226,7 +220,7 @@ struct AutoStopCont : public Continuation {
   int
   mainEvent(int /* event */, Event * /* e */)
   {
-    stop_ssl_handshake = true;
+    TSSystemState::stop_ssl_handshaking();
 
     APIHook *hook = lifecycle_hooks->get(TS_LIFECYCLE_SHUTDOWN_HOOK);
     while (hook) {
@@ -236,7 +230,7 @@ struct AutoStopCont : public Continuation {
     }
 
     pmgmt->stop();
-    shutdown_event_system = true;
+    TSSystemState::shut_down_event_system();
     delete this;
     return EVENT_CONT;
   }
@@ -294,7 +288,7 @@ public:
       RecInt timeout = 0;
       if (RecGetRecordInt("proxy.config.stop.shutdown_timeout", &timeout) == REC_ERR_OKAY
&& timeout) {
         RecSetRecordInt("proxy.node.config.draining", 1, REC_SOURCE_DEFAULT);
-        ts_is_draining = true;
+        TSSystemState::drain(true);
         if (!remote_management_flag) {
           // Close listening sockets here only if TS is running standalone
           RecInt close_sockets = 0;
@@ -1365,7 +1359,7 @@ struct RegressionCont : public Continuation {
       return EVENT_CONT;
     }
 
-    shutdown_event_system = true;
+    TSSystemState::shut_down_event_system();
     fprintf(stderr, "REGRESSION_TEST DONE: %s\n", regression_status_string(res));
     ::exit(res == REGRESSION_TEST_PASSED ? 0 : 1);
     return EVENT_CONT;
@@ -2002,7 +1996,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
   }
 #endif
 
-  while (!shutdown_event_system) {
+  while (!TSSystemState::is_event_system_shut_down()) {
     sleep(1);
   }
 
@@ -2032,9 +2026,9 @@ static void mgmt_restart_shutdown_callback(ts::MemSpan)
 static void
 mgmt_drain_callback(ts::MemSpan span)
 {
-  char *arg      = static_cast<char *>(span.data());
-  ts_is_draining = (span.size() == 2 && arg[0] == '1');
-  RecSetRecordInt("proxy.node.config.draining", ts_is_draining ? 1 : 0, REC_SOURCE_DEFAULT);
+  char *arg = static_cast<char *>(span.data());
+  TSSystemState::drain(span.size() == 2 && arg[0] == '1');
+  RecSetRecordInt("proxy.node.config.draining", TSSystemState::is_draining() ? 1 : 0, REC_SOURCE_DEFAULT);
 }
 
 static void


Mime
View raw message