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

kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 284a6a8b787a2a023755efc45c5fc590eadfe020
Author: Kit Chan <[email protected]>
AuthorDate: Mon Jan 6 19:45:26 2020 -0800

    Improvements on ESI plugin
---
 plugins/esi/Makefile.inc                   |   2 -
 plugins/esi/combo_handler.cc               |   6 --
 plugins/esi/esi.cc                         |  31 ++------
 plugins/esi/fetcher/HttpDataFetcherImpl.cc |  23 +++++-
 plugins/esi/fetcher/HttpDataFetcherImpl.h  |   2 +-
 plugins/esi/lib/EsiProcessor.cc            | 121 +----------------------------
 plugins/esi/lib/EsiProcessor.h             |   2 -
 plugins/esi/lib/FailureInfo.cc             | 105 -------------------------
 plugins/esi/lib/FailureInfo.h              | 112 --------------------------
 plugins/esi/test/docnode_test.cc           |   3 -
 plugins/esi/test/gzip_test.cc              |   3 -
 plugins/esi/test/parser_test.cc            |   3 -
 plugins/esi/test/processor_test.cc         |   3 -
 plugins/esi/test/utils_test.cc             |   3 -
 plugins/esi/test/vars_test.cc              |   3 -
 15 files changed, 33 insertions(+), 389 deletions(-)

diff --git a/plugins/esi/Makefile.inc b/plugins/esi/Makefile.inc
index 81622d5..03fb333 100644
--- a/plugins/esi/Makefile.inc
+++ b/plugins/esi/Makefile.inc
@@ -57,8 +57,6 @@ esi_libesicore_la_SOURCES = \
        esi/lib/EsiProcessor.h \
        esi/lib/Expression.cc \
        esi/lib/Expression.h \
-       esi/lib/FailureInfo.cc \
-       esi/lib/FailureInfo.h \
        esi/lib/HandlerManager.h \
        esi/lib/HttpHeader.h \
        esi/lib/IncludeHandlerFactory.h \
diff --git a/plugins/esi/combo_handler.cc b/plugins/esi/combo_handler.cc
index 7cc317f..4ca62a0 100644
--- a/plugins/esi/combo_handler.cc
+++ b/plugins/esi/combo_handler.cc
@@ -29,7 +29,6 @@
 #include <algorithm>
 #include <ctime>
 #include <fstream>
-#include <pthread.h>
 #include <arpa/inet.h>
 #include <limits>
 #include <getopt.h>
@@ -340,9 +339,6 @@ static bool writeStandardHeaderFields(InterceptData 
&int_data, int &n_bytes_writ
 static void prepareResponse(InterceptData &int_data, ByteBlockList 
&body_blocks, string &resp_header_fields);
 static bool getDefaultBucket(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc hdr_obj, 
ClientRequest &creq);
 
-// libesi TLS key.
-pthread_key_t threadKey = 0;
-
 void
 TSPluginInit(int argc, const char *argv[])
 {
@@ -434,8 +430,6 @@ TSPluginInit(int argc, const char *argv[])
   }
   ++optind;
 
-  TSReleaseAssert(pthread_key_create(&threadKey, nullptr) == 0);
-
   TSCont rrh_contp = TSContCreate(handleReadRequestHeader, nullptr);
   if (!rrh_contp) {
     LOG_ERROR("Could not create read request header continuation");
diff --git a/plugins/esi/esi.cc b/plugins/esi/esi.cc
index cf02b3b..d158983 100644
--- a/plugins/esi/esi.cc
+++ b/plugins/esi/esi.cc
@@ -30,7 +30,6 @@
 #include <string>
 #include <list>
 #include <arpa/inet.h>
-#include <pthread.h>
 #include <getopt.h>
 
 #include "ts/ts.h"
@@ -47,7 +46,6 @@
 #include "serverIntercept.h"
 #include "Stats.h"
 #include "HttpDataFetcherImpl.h"
-#include "FailureInfo.h"
 using std::string;
 using std::list;
 using namespace EsiLib;
@@ -1493,7 +1491,6 @@ lFail:
   return false;
 }
 
-pthread_key_t threadKey = 0;
 static int
 globalHookHandler(TSCont contp, TSEvent event, void *edata)
 {
@@ -1629,28 +1626,14 @@ esiPluginInit(int argc, const char *argv[], struct 
OptionInfo *pOptionInfo)
     }
   }
 
-  int result = 0;
-  bool bKeySet;
-  if (threadKey == 0) {
-    bKeySet = true;
-    if ((result = pthread_key_create(&threadKey, nullptr)) != 0) {
-      TSError("[esi][%s] Could not create key", __FUNCTION__);
-      TSDebug(DEBUG_TAG, "[%s] Could not create key", __FUNCTION__);
-    }
-  } else {
-    bKeySet = false;
-  }
+  TSDebug(DEBUG_TAG,
+          "[%s] Plugin started, "
+          "packed-node-support: %d, private-response: %d, "
+          "disable-gzip-output: %d, first-byte-flush: %d ",
+          __FUNCTION__, pOptionInfo->packed_node_support, 
pOptionInfo->private_response, pOptionInfo->disable_gzip_output,
+          pOptionInfo->first_byte_flush);
 
-  if (result == 0) {
-    TSDebug(DEBUG_TAG,
-            "[%s] Plugin started%s, "
-            "packed-node-support: %d, private-response: %d, "
-            "disable-gzip-output: %d, first-byte-flush: %d ",
-            __FUNCTION__, bKeySet ? " and key is set" : "", 
pOptionInfo->packed_node_support, pOptionInfo->private_response,
-            pOptionInfo->disable_gzip_output, pOptionInfo->first_byte_flush);
-  }
-
-  return result;
+  return 0;
 }
 
 void
diff --git a/plugins/esi/fetcher/HttpDataFetcherImpl.cc 
b/plugins/esi/fetcher/HttpDataFetcherImpl.cc
index 5e8a545..70e4334 100644
--- a/plugins/esi/fetcher/HttpDataFetcherImpl.cc
+++ b/plugins/esi/fetcher/HttpDataFetcherImpl.cc
@@ -47,10 +47,29 @@ HttpDataFetcherImpl::_release(RequestData &req_data)
 }
 
 HttpDataFetcherImpl::HttpDataFetcherImpl(TSCont contp, sockaddr const 
*client_addr, const char *debug_tag)
-  : _contp(contp), _n_pending_requests(0), 
_curr_event_id_base(FETCH_EVENT_ID_BASE), _headers_str(""), 
_client_addr(client_addr)
+  : _contp(contp), _n_pending_requests(0), 
_curr_event_id_base(FETCH_EVENT_ID_BASE), _headers_str("")
 {
   _http_parser = TSHttpParserCreate();
   snprintf(_debug_tag, sizeof(_debug_tag), "%s", debug_tag);
+  // default client address to use for fetch url
+  struct sockaddr_in sin;
+  memset(&sin, 0, sizeof(sin));
+  sin.sin_family      = AF_INET;
+  sin.sin_addr.s_addr = inet_addr("127.0.0.1");
+
+  if (client_addr) {
+    if (client_addr->sa_family == AF_INET) {
+      memcpy(&_client_addr, client_addr, sizeof(sockaddr_in));
+    } else if (client_addr->sa_family == AF_INET6) {
+      memcpy(&_client_addr, client_addr, sizeof(sockaddr_in6));
+    } else {
+      memcpy(&_client_addr, &sin, sizeof(sin));
+      TSError("[HttpDataFetcherImpl] Unknown address family %d", 
client_addr->sa_family);
+    }
+  } else {
+    memcpy(&_client_addr, &sin, sizeof(sin));
+    TSError("[HttpDataFetcherImpl] Failed to get client host info");
+  }
 }
 
 HttpDataFetcherImpl::~HttpDataFetcherImpl()
@@ -95,7 +114,7 @@ HttpDataFetcherImpl::addFetchRequest(const string &url, 
FetchedDataProcessor *ca
   event_ids.timeout_event_id = _curr_event_id_base + 2;
   _curr_event_id_base += 3;
 
-  TSFetchUrl(http_req, length, _client_addr, _contp, AFTER_BODY, event_ids);
+  TSFetchUrl(http_req, length, reinterpret_cast<sockaddr *>(&_client_addr), 
_contp, AFTER_BODY, event_ids);
   if (http_req != buff) {
     free(http_req);
   }
diff --git a/plugins/esi/fetcher/HttpDataFetcherImpl.h 
b/plugins/esi/fetcher/HttpDataFetcherImpl.h
index 1702813..9784b65 100644
--- a/plugins/esi/fetcher/HttpDataFetcherImpl.h
+++ b/plugins/esi/fetcher/HttpDataFetcherImpl.h
@@ -147,7 +147,7 @@ private:
 
   inline void _release(RequestData &req_data);
 
-  sockaddr const *_client_addr;
+  struct sockaddr_storage _client_addr;
 };
 
 inline void
diff --git a/plugins/esi/lib/EsiProcessor.cc b/plugins/esi/lib/EsiProcessor.cc
index 379252b..c8120bb 100644
--- a/plugins/esi/lib/EsiProcessor.cc
+++ b/plugins/esi/lib/EsiProcessor.cc
@@ -23,12 +23,10 @@
 
 #include "EsiProcessor.h"
 #include "Stats.h"
-#include "FailureInfo.h"
 #include <cctype>
 
 using std::string;
 using namespace EsiLib;
-extern pthread_key_t threadKey;
 // this needs to be a fixed address as only the address is used for comparison
 const char *EsiProcessor::INCLUDE_DATA_ID_ATTR = reinterpret_cast<const char 
*>(0xbeadface);
 
@@ -282,7 +280,6 @@ EsiProcessor::process(const char *&data, int &data_len)
   }
   DocNodeList::iterator node_iter, iter;
   bool attempt_succeeded;
-  std::vector<std::string> attemptUrls;
   TryBlockList::iterator try_iter = _try_blocks.begin();
   for (int i = 0; i < _n_try_blocks_processed; ++i, ++try_iter) {
     ;
@@ -294,7 +291,6 @@ EsiProcessor::process(const char *&data, int &data_len)
       if ((node_iter->type == DocNode::TYPE_INCLUDE) || (node_iter->type == 
DocNode::TYPE_SPECIAL_INCLUDE)) {
         const Attribute &url = (*node_iter).attr_list.front();
         string raw_url(url.value, url.value_len);
-        attemptUrls.push_back(_expression.expand(raw_url));
         if (!_getIncludeData(*node_iter)) {
           attempt_succeeded = false;
           _errorLog("[%s] attempt section errored; due to url [%s]", 
__FUNCTION__, raw_url.c_str());
@@ -303,44 +299,6 @@ EsiProcessor::process(const char *&data, int &data_len)
       }
     }
 
-    /* FAILURE CACHE */
-    FailureData *data = static_cast<FailureData 
*>(pthread_getspecific(threadKey));
-    _debugLog("plugin_esi_failureInfo", "[%s]Fetched data related to thread 
specific %p", __FUNCTION__, data);
-
-    for (iter = try_iter->attempt_nodes.begin(); iter != 
try_iter->attempt_nodes.end(); ++iter) {
-      if ((iter->type == DocNode::TYPE_INCLUDE) || iter->type == 
DocNode::TYPE_SPECIAL_INCLUDE) {
-        if (!attempt_succeeded && iter == node_iter) {
-          continue;
-        }
-        const Attribute &url = (*iter).attr_list.front();
-        string raw_url(url.value, url.value_len);
-        attemptUrls.push_back(_expression.expand(raw_url));
-      }
-    }
-
-    if (attemptUrls.size() > 0 && data) {
-      FailureData::iterator it = data->find(attemptUrls[0]);
-      FailureInfo *info;
-
-      if (it == data->end()) {
-        _debugLog("plugin_esi_failureInfo", "[%s]Inserting object for the 
attempt URLS", __FUNCTION__);
-        info = new FailureInfo(FAILURE_INFO_TAG, _debugLog, _errorLog);
-        for (int i = 0; i < static_cast<int>(attemptUrls.size()); i++) {
-          _debugLog("plugin_esi_failureInfo", "[%s] Urls [%.*s]", 
__FUNCTION__, attemptUrls[i].size(), attemptUrls[i].data());
-          (*data)[attemptUrls[i]] = info;
-        }
-
-        info->registerSuccFail(attempt_succeeded);
-
-      } else {
-        info = it->second;
-        // Should be registered only if attemp was made
-        // and it failed
-        if (_reqAdded) {
-          info->registerSuccFail(attempt_succeeded);
-        }
-      }
-    }
     if (attempt_succeeded) {
       _debugLog(_debug_tag, "[%s] attempt section succeeded; using attempt 
section", __FUNCTION__);
       _node_list.splice(try_iter->pos, try_iter->attempt_nodes);
@@ -399,7 +357,6 @@ EsiProcessor::flush(string &data, int &overall_len)
   bool attempt_succeeded;
   bool attempt_pending;
   bool node_pending;
-  std::vector<std::string> attemptUrls;
   _output_data.clear();
   TryBlockList::iterator try_iter = _try_blocks.begin();
   for (int i = 0; i < _n_try_blocks_processed; ++i, ++try_iter) {
@@ -425,7 +382,6 @@ EsiProcessor::flush(string &data, int &overall_len)
       if ((node_iter->type == DocNode::TYPE_INCLUDE) || (node_iter->type == 
DocNode::TYPE_SPECIAL_INCLUDE)) {
         const Attribute &url = (*node_iter).attr_list.front();
         string raw_url(url.value, url.value_len);
-        attemptUrls.push_back(_expression.expand(raw_url));
         if (_getIncludeStatus(*node_iter) != STATUS_DATA_AVAILABLE) {
           attempt_succeeded = false;
           _errorLog("[%s] attempt section errored; due to url [%s]", 
__FUNCTION__, raw_url.c_str());
@@ -434,44 +390,6 @@ EsiProcessor::flush(string &data, int &overall_len)
       }
     }
 
-    /* FAILURE CACHE */
-    FailureData *fdata = static_cast<FailureData 
*>(pthread_getspecific(threadKey));
-    _debugLog("plugin_esi_failureInfo", "[%s]Fetched data related to thread 
specific %p", __FUNCTION__, fdata);
-
-    for (iter = try_iter->attempt_nodes.begin(); iter != 
try_iter->attempt_nodes.end(); ++iter) {
-      if ((iter->type == DocNode::TYPE_INCLUDE) || iter->type == 
DocNode::TYPE_SPECIAL_INCLUDE) {
-        if (!attempt_succeeded && iter == node_iter) {
-          continue;
-        }
-        const Attribute &url = (*iter).attr_list.front();
-        string raw_url(url.value, url.value_len);
-        attemptUrls.push_back(_expression.expand(raw_url));
-      }
-    }
-
-    if (attemptUrls.size() > 0 && fdata) {
-      FailureData::iterator it = fdata->find(attemptUrls[0]);
-      FailureInfo *info;
-
-      if (it == fdata->end()) {
-        _debugLog("plugin_esi_failureInfo", "[%s]Inserting object for the 
attempt URLS", __FUNCTION__);
-        info = new FailureInfo(FAILURE_INFO_TAG, _debugLog, _errorLog);
-        for (int i = 0; i < static_cast<int>(attemptUrls.size()); i++) {
-          _debugLog("plugin_esi_failureInfo", "[%s] Urls [%.*s]", 
__FUNCTION__, attemptUrls[i].size(), attemptUrls[i].data());
-          (*fdata)[attemptUrls[i]] = info;
-        }
-
-        info->registerSuccFail(attempt_succeeded);
-
-      } else {
-        info = it->second;
-        // Should be registered only if attemp was made
-        // and it failed
-        if (_reqAdded) {
-          info->registerSuccFail(attempt_succeeded);
-        }
-      }
-    }
     if (attempt_succeeded) {
       _debugLog(_debug_tag, "[%s] attempt section succeeded; using attempt 
section", __FUNCTION__);
       _n_prescanned_nodes = _n_prescanned_nodes + 
try_iter->attempt_nodes.size();
@@ -764,43 +682,12 @@ EsiProcessor::_preprocess(DocNodeList &node_list, int 
&n_prescanned_nodes)
         continue;
       }
 
-      bool fetch = true;
-      FailureData *threadData;
-      /* FAILURE CACHE */
-      if ((threadData = static_cast<FailureData 
*>(pthread_getspecific(threadKey))) == nullptr) {
-        threadData = new FailureData();
-        if (pthread_setspecific(threadKey, threadData)) {
-          _errorLog("[%s] Unable to set the key", __FUNCTION__);
-          abort();
-        }
-        _debugLog("plugin_esi_failureInfo", "[%s] Data is set for this thread 
[threadData]%p [threadID]%u [%.*s]", __FUNCTION__,
-                  threadData, pthread_self(), expanded_url.size(), 
expanded_url.data());
-      } else {
-        _debugLog("plugin_esi_failureInfo", "[%s] URL request [%.*s] %u", 
__FUNCTION__, expanded_url.size(), expanded_url.data(),
-                  pthread_self());
-
-        FailureData::iterator it = threadData->find(expanded_url);
-        FailureInfo *info;
-
-        if (it != threadData->end()) {
-          info  = it->second;
-          fetch = _reqAdded = info->isAttemptReq();
-          _debugLog(_debug_tag, "[%s] Fetch result is %d", __FUNCTION__, 
fetch);
-        }
-      }
-
-      if (fetch) {
-        if (!_fetcher.addFetchRequest(expanded_url)) {
-          _errorLog("[%s] Couldn't add fetch request for URL [%.*s]", 
__FUNCTION__, raw_url.size(), raw_url.data());
-          Stats::increment(Stats::N_INCLUDE_ERRS);
-          continue;
-        }
-        _include_urls.insert(StringHash::value_type(raw_url, expanded_url));
-      } else {
-        _debugLog("plugin_esi_failureInfo", "[%s] Not adding fetch request for 
[%.*s]", __FUNCTION__, expanded_url.size(),
-                  expanded_url.data());
+      if (!_fetcher.addFetchRequest(expanded_url)) {
+        _errorLog("[%s] Couldn't add fetch request for URL [%.*s]", 
__FUNCTION__, raw_url.size(), raw_url.data());
+        Stats::increment(Stats::N_INCLUDE_ERRS);
         continue;
       }
+      _include_urls.insert(StringHash::value_type(raw_url, expanded_url));
       break;
     }
     case DocNode::TYPE_SPECIAL_INCLUDE: {
diff --git a/plugins/esi/lib/EsiProcessor.h b/plugins/esi/lib/EsiProcessor.h
index 897d265..d264a05 100644
--- a/plugins/esi/lib/EsiProcessor.h
+++ b/plugins/esi/lib/EsiProcessor.h
@@ -25,7 +25,6 @@
 
 #include <string>
 #include <map>
-#include <pthread.h>
 #include "lib/ComponentBase.h"
 #include "lib/StringHash.h"
 #include "lib/DocNode.h"
@@ -36,7 +35,6 @@
 #include "SpecialIncludeHandler.h"
 #include "HandlerManager.h"
 
-extern pthread_key_t key;
 class EsiProcessor : private EsiLib::ComponentBase
 {
 public:
diff --git a/plugins/esi/lib/FailureInfo.cc b/plugins/esi/lib/FailureInfo.cc
deleted file mode 100644
index 6249637..0000000
--- a/plugins/esi/lib/FailureInfo.cc
+++ /dev/null
@@ -1,105 +0,0 @@
-/** @file
-
-  A brief file description
-
-  @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.
- */
-
-#include "FailureInfo.h"
-#include <cstdlib>
-
-static int LOWER_CUT_OFF  = 300;
-static int HIGHER_CUT_OFF = 1000;
-
-void
-FailureInfo::registerSuccFail(bool isSuccess)
-{
-  struct timeval currTime, result;
-  gettimeofday(&currTime, nullptr);
-  timersub(&currTime, &_start, &result);
-
-  if ((result.tv_sec * 1000000 + result.tv_usec) > (WINDOW_SIZE * 1000)) {
-    ++_windowMarker;
-    _windowMarker %= _totalSlots;
-
-    if (_windowMarker == _totalSlots - 1) {
-      ++_windowsPassed;
-      double avg = 0;
-      for (size_t i = 0; i < _totalSlots; i++) {
-        if (_statistics[i].first > 0) {
-          avg += _statistics[i].first / (_statistics[i].first + 
_statistics[i].second);
-        }
-      }
-      _avgOverWindow += avg / _windowsPassed;
-      _debugLog(_debug_tag, "[%s] current average over window is %lf", 
__FUNCTION__, _avgOverWindow);
-    }
-
-    gettimeofday(&_start, nullptr);
-  }
-
-  if (isSuccess) {
-    _statistics[_windowMarker].second++;
-  }
-
-  else {
-    _statistics[_windowMarker].first++;
-  }
-}
-
-bool
-FailureInfo::isAttemptReq()
-{
-  double avg = 0;
-  for (size_t i = 0; i < _totalSlots; i++) {
-    if (_statistics[i].first > 0) {
-      avg += _statistics[i].first / (_statistics[i].first + 
_statistics[i].second);
-    }
-  }
-
-  if (avg) {
-    // Average it out for time being
-    avg = avg / _totalSlots;
-    double prob;
-
-    if (avg * 1000 < LOWER_CUT_OFF) {
-      prob = avg;
-
-    } else {
-      double mapFactor =
-        (((avg * 1000 - LOWER_CUT_OFF) * (avg * 1000 - LOWER_CUT_OFF)) / 
(HIGHER_CUT_OFF - LOWER_CUT_OFF)) + LOWER_CUT_OFF;
-      prob = mapFactor / 1000;
-    }
-
-    if (static_cast<int>(prob)) {
-      prob = _avgOverWindow;
-    }
-
-    _debugLog(_debug_tag, "[%s] Calculated probability is %lf", __FUNCTION__, 
prob);
-    // coverity[dont_call]
-    int decision = rand() % 100;
-
-    if (decision < prob * 100) {
-      _debugLog(_debug_tag, "[%s] fetch request will not be added for an 
attempt request", __FUNCTION__);
-      return (_requestMade = false);
-    }
-  }
-
-  _debugLog(_debug_tag, "[%s] fetch request will be added for an attempt 
request", __FUNCTION__);
-  return true;
-}
diff --git a/plugins/esi/lib/FailureInfo.h b/plugins/esi/lib/FailureInfo.h
deleted file mode 100644
index ffb4a9e..0000000
--- a/plugins/esi/lib/FailureInfo.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/** @file
-
-  A brief file description
-
-  @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 <ctime>
-#include <vector>
-#include <map>
-#include <sys/time.h>
-
-#if defined(solaris) && !defined(timersub)
-#define timersub(a, b, result)                       \
-  do {                                               \
-    (result)->tv_sec  = (a)->tv_sec - (b)->tv_sec;   \
-    (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
-    if ((result)->tv_usec < 0) {                     \
-      --(result)->tv_sec;                            \
-      (result)->tv_usec += 1000000;                  \
-    }                                                \
-  } while (0)
-#endif
-
-#include <string>
-#include <pthread.h>
-
-#include "ComponentBase.h"
-
-using namespace std;
-
-typedef std::vector<std::pair<double, double>> FailureToSuccess;
-typedef std::map<std::string, class FailureInfo *> FailureData;
-
-static const int WINDOW_SIZE    = 200;
-static const int TOTAL_DURATION = 2000;
-
-class FailureInfo : private EsiLib::ComponentBase
-{
-public:
-  FailureInfo(const char *debug_tag, ComponentBase::Debug debug_func, 
ComponentBase::Error error_func)
-    : ComponentBase(debug_tag, debug_func, error_func), _windowsPassed(0), 
_avgOverWindow(0), _requestMade(true)
-  {
-    _totalSlots   = TOTAL_DURATION / WINDOW_SIZE;
-    _windowMarker = 0;
-    for (size_t i = 0; i < _totalSlots; i++) {
-      _statistics.push_back(make_pair(0, 0));
-    }
-    _debugLog(_debug_tag, "FailureInfo Ctor:inserting URL object into the 
statistics map [FailureInfo object]%p", this);
-  };
-
-  ~FailureInfo() override {}
-  /* Fills the statistics vector depending
-   * upon the position of the window marker
-   */
-  void registerSuccFail(bool isSuccess);
-
-  /*
-   * Decides if an attempt shud be made
-   * for the attempt tag or except tag
-   * depending upon the statistics
-   */
-  bool isAttemptReq();
-
-private:
-  /*
-   * Keeps track of failures of attempt
-   * vs success
-   */
-  FailureToSuccess _statistics;
-
-  /* Slot on which to register success/failures
-   * Changes as soon as time has passed windowSize
-   */
-  size_t _windowMarker;
-
-  /* Number of slots to be filled over time */
-  size_t _totalSlots;
-
-  /* Start time for the window slots */
-  struct timeval _start;
-
-  /* Keep track of the number of windows filled prev*/
-  size_t _windowsPassed;
-
-  /* Used as a deciding factor between attempt/except
-   * in case prob is complete truth
-   */
-  double _avgOverWindow;
-
-public:
-  /*Was a request made*/
-  bool _requestMade;
-};
diff --git a/plugins/esi/test/docnode_test.cc b/plugins/esi/test/docnode_test.cc
index e0af7b6..1e1dc29 100644
--- a/plugins/esi/test/docnode_test.cc
+++ b/plugins/esi/test/docnode_test.cc
@@ -148,12 +148,9 @@ checkNodeList2(const DocNodeList &node_list)
   check_node_attr(list_iter3->attr_list.front(), "src", "bar3");
 }
 
-pthread_key_t threadKey;
-
 int
 main()
 {
-  pthread_key_create(&threadKey, nullptr);
   Utils::init(&Debug, &Error);
 
   {
diff --git a/plugins/esi/test/gzip_test.cc b/plugins/esi/test/gzip_test.cc
index a8b9def..2d8ea6e 100644
--- a/plugins/esi/test/gzip_test.cc
+++ b/plugins/esi/test/gzip_test.cc
@@ -36,12 +36,9 @@ using std::endl;
 using std::string;
 using namespace EsiLib;
 
-pthread_key_t threadKey;
-
 int
 main()
 {
-  pthread_key_create(&threadKey, nullptr);
   Utils::init(&Debug, &Error);
 
   {
diff --git a/plugins/esi/test/parser_test.cc b/plugins/esi/test/parser_test.cc
index 1bd5f7b..c200eeb 100644
--- a/plugins/esi/test/parser_test.cc
+++ b/plugins/esi/test/parser_test.cc
@@ -46,12 +46,9 @@ check_node_attr(const Attribute &attr, const char *name, 
const char *value)
   assert(strncmp(attr.value, value, value_len) == 0);
 }
 
-pthread_key_t threadKey;
-
 int
 main()
 {
-  pthread_key_create(&threadKey, nullptr);
   Utils::init(&Debug, &Error);
 
   {
diff --git a/plugins/esi/test/processor_test.cc 
b/plugins/esi/test/processor_test.cc
index 850ce5b..9ed9a1c 100644
--- a/plugins/esi/test/processor_test.cc
+++ b/plugins/esi/test/processor_test.cc
@@ -37,8 +37,6 @@ using std::endl;
 using std::string;
 using namespace EsiLib;
 
-pthread_key_t threadKey;
-
 static const int FETCHER_STATIC_DATA_SIZE = 30;
 
 int
@@ -48,7 +46,6 @@ main()
   Variables esi_vars("vars", &Debug, &Error, whitelistCookies);
   HandlerManager handler_mgr("handler_mgr", &Debug, &Error);
 
-  pthread_key_create(&threadKey, nullptr);
   Utils::init(&Debug, &Error);
 
   {
diff --git a/plugins/esi/test/utils_test.cc b/plugins/esi/test/utils_test.cc
index 481bfbc..0e63a35 100644
--- a/plugins/esi/test/utils_test.cc
+++ b/plugins/esi/test/utils_test.cc
@@ -48,12 +48,9 @@ checkAttributes(const char *check_id, const AttributeList 
&attr_list, const char
   assert(iter == attr_list.end());
 }
 
-pthread_key_t threadKey;
-
 int
 main()
 {
-  pthread_key_create(&threadKey, nullptr);
   Utils::init(&Debug, &Error);
 
   AttributeList attr_list;
diff --git a/plugins/esi/test/vars_test.cc b/plugins/esi/test/vars_test.cc
index 0bd11b7..1eacd2b 100644
--- a/plugins/esi/test/vars_test.cc
+++ b/plugins/esi/test/vars_test.cc
@@ -37,8 +37,6 @@ using std::endl;
 using std::string;
 using namespace EsiLib;
 
-pthread_key_t threadKey;
-
 void
 addToHeaderList(const char *strings[], HttpHeaderList &headers)
 {
@@ -70,7 +68,6 @@ fakeDebug(const char *tag, const char *fmt, ...)
 int
 main()
 {
-  pthread_key_create(&threadKey, nullptr);
   Utils::init(&Debug, &Error);
 
   {

Reply via email to