You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by yu...@apache.org on 2013/10/01 06:59:47 UTC

[1/2] git commit: TS-2259: Introduce failover hosts for logging system

Updated Branches:
  refs/heads/master 134b8a6f9 -> 4591314f6


TS-2259: Introduce failover hosts for logging system

This patch introduce failover hosts for collation host by using '|' delimiter
to extend <CollationHosts> tags in logs_xml.config.

Let me give an example:
<CollationHosts = "host1:5000|host2:5000|host3:6000, 209.131.52.129:6000"/>

In the example above, host2/host3 are failover hosts for host1. When host1
disconnected, log entries will be sent to host2, and then if host2 failed again,
log entries will be sent to host3 until host1 or host2 comes back.

Signed-off-by: Yunkai Zhang <qi...@taobao.com>


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/54883f2f
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/54883f2f
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/54883f2f

Branch: refs/heads/master
Commit: 54883f2ff62a5b09d238b54ffb4279ea9f45e796
Parents: 134b8a6
Author: Yunkai Zhang <qi...@taobao.com>
Authored: Mon Sep 30 11:46:38 2013 +0800
Committer: Yunkai Zhang <qi...@taobao.com>
Committed: Tue Oct 1 12:52:17 2013 +0800

----------------------------------------------------------------------
 proxy/config/logs_xml.config.default |  8 ++++++++
 proxy/logging/LogBufferSink.h        |  4 +++-
 proxy/logging/LogConfig.cc           | 23 +++++++++++++++++------
 proxy/logging/LogFile.cc             | 10 ++++++----
 proxy/logging/LogFile.h              |  2 +-
 proxy/logging/LogHost.cc             | 31 ++++++++++++++++++++++---------
 proxy/logging/LogHost.h              |  5 +++--
 7 files changed, 60 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/54883f2f/proxy/config/logs_xml.config.default
----------------------------------------------------------------------
diff --git a/proxy/config/logs_xml.config.default b/proxy/config/logs_xml.config.default
index 62f614f..7633808 100644
--- a/proxy/config/logs_xml.config.default
+++ b/proxy/config/logs_xml.config.default
@@ -186,6 +186,14 @@ Example2: do not log requests for domain unwanted.com
       either a name or an ip. For example:
       <CollationHosts = "host1.company.com:5000, 209.131.52.129:6000"/>
 
+      Also, we can introduce failover hosts for each collation host by
+      using '|' delimiter, For example:
+      <CollationHosts = "host1:5000|host2:5000|host3:6000, 209.131.52.129:6000"/>
+
+      In the example above, host2/host3 are failover hosts for host1. When host1
+      disconnected, log entries will be sent to host2, and then if host2 failed
+      again, log entries will be sent to host3 until host1 or host2 comes back.
+
   <Header = "header"/>
       This tag specifies a string to be written at the beginning of
       the log file, just before the first record.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/54883f2f/proxy/logging/LogBufferSink.h
----------------------------------------------------------------------
diff --git a/proxy/logging/LogBufferSink.h b/proxy/logging/LogBufferSink.h
index b7d4ca6..53789df 100644
--- a/proxy/logging/LogBufferSink.h
+++ b/proxy/logging/LogBufferSink.h
@@ -42,7 +42,9 @@ public:
   // Of course, this function may not free memory directly, it
   // can delegate another function to do it.
   //
-  virtual void preproc_and_try_delete(LogBuffer * buffer) = 0;
+  // return 0 if success, -1 on error.
+  //
+  virtual int preproc_and_try_delete(LogBuffer * buffer) = 0;
   virtual ~ LogBufferSink()
   {
   };

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/54883f2f/proxy/logging/LogConfig.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/LogConfig.cc b/proxy/logging/LogConfig.cc
index d9810ce..40e0069 100644
--- a/proxy/logging/LogConfig.cc
+++ b/proxy/logging/LogConfig.cc
@@ -2308,13 +2308,24 @@ LogConfig::read_xml_log_config(int from_memory)
         char *host;
         SimpleTokenizer tok(collationHosts_str, ',');
         while (host = tok.getNext(), host != 0) {
-          LogHost *lh = NEW(new LogHost(obj->get_full_filename(), obj->get_signature()));
 
-          if (lh->set_name_or_ipstr(host)) {
-            Warning("Could not set \"%s\" as collation host", host);
-            delete lh;
-          } else {
-            obj->add_loghost(lh, false);
+          LogHost *prev = NULL;
+          char *failover_str;
+          SimpleTokenizer failover_tok(host, '|'); // split failover hosts
+
+          while (failover_str = failover_tok.getNext(), failover_str != 0) {
+            LogHost *lh = NEW(new LogHost(obj->get_full_filename(), obj->get_signature()));
+
+            if (lh->set_name_or_ipstr(failover_str)) {
+              Warning("Could not set \"%s\" as collation host", host);
+              delete lh;
+            } else if (!prev){
+              obj->add_loghost(lh, false);
+              prev = lh;
+            } else {
+              prev->failover_link.next = lh;
+              prev = lh;
+            }
           }
         }
       }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/54883f2f/proxy/logging/LogFile.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/LogFile.cc b/proxy/logging/LogFile.cc
index 71ac5f6..55fe900 100644
--- a/proxy/logging/LogFile.cc
+++ b/proxy/logging/LogFile.cc
@@ -470,14 +470,15 @@ LogFile::roll(long interval_start, long interval_end)
   preprocess the given buffer data before write to target file
   and try to delete it when its reference become zero.
   -------------------------------------------------------------------------*/
-void
+int
 LogFile::preproc_and_try_delete(LogBuffer * lb)
 {
+  int ret = -1;
   LogBufferHeader *buffer_header;
 
   if (lb == NULL) {
     Note("Cannot write LogBuffer to LogFile %s; LogBuffer is NULL", m_name);
-    return;
+    return -1;
   }
 
   ink_atomic_increment(&lb->m_references, 1);
@@ -528,10 +529,11 @@ LogFile::preproc_and_try_delete(LogBuffer * lb)
     //
     // LogBuffer will be deleted in flush thread
     //
-    return;
+    return 0;
   }
   else if (m_file_format == ASCII_LOG || m_file_format == ASCII_PIPE) {
     write_ascii_logbuffer3(buffer_header);
+    ret = 0;
   }
   else {
     Note("Cannot write LogBuffer to LogFile %s; invalid file format: %d",
@@ -540,7 +542,7 @@ LogFile::preproc_and_try_delete(LogBuffer * lb)
 
 done:
   LogBuffer::destroy(lb);
-  return;
+  return ret;
 }
 
 /*-------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/54883f2f/proxy/logging/LogFile.h
----------------------------------------------------------------------
diff --git a/proxy/logging/LogFile.h b/proxy/logging/LogFile.h
index 3a3dc45..144a2b5 100644
--- a/proxy/logging/LogFile.h
+++ b/proxy/logging/LogFile.h
@@ -141,7 +141,7 @@ public:
     LOG_FILE_FILESYSTEM_CHECKS_FAILED
   };
 
-  void preproc_and_try_delete(LogBuffer * lb);
+  int preproc_and_try_delete(LogBuffer * lb);
 
   int roll(long interval_start, long interval_end);
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/54883f2f/proxy/logging/LogHost.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/LogHost.cc b/proxy/logging/LogHost.cc
index 84e08f4..05e9f28 100644
--- a/proxy/logging/LogHost.cc
+++ b/proxy/logging/LogHost.cc
@@ -263,14 +263,15 @@ LogHost::create_orphan_LogFile_object()
 // preprocess the given buffer data before sent to target host
 // and try to delete it when its reference become zero.
 //
-void
+int
 LogHost::preproc_and_try_delete (LogBuffer *lb)
 {
+  int ret = -1;
   int bytes;
 
   if (lb == NULL) {
     Note("Cannot write LogBuffer to LogHost %s; LogBuffer is NULL", name());
-    return;
+    return -1;
   }
   LogBufferHeader *buffer_header = lb->header();
   if (buffer_header == NULL) {
@@ -291,7 +292,7 @@ LogHost::preproc_and_try_delete (LogBuffer *lb)
     if (!connect ()) {
       Note("Cannot write LogBuffer to LogHost %s; not connected", name());
       orphan_write_and_try_delete(lb);
-      return;
+      return -1;
     }
   }
 
@@ -308,8 +309,9 @@ LogHost::preproc_and_try_delete (LogBuffer *lb)
     // TODO: We currently don't try to make the log buffers handle little vs big endian. TS-1156.
     // lb->convert_to_host_order ();
     orphan_write_and_try_delete(lb);
-    return;
+    return -1;
   }
+  ret = 0;
 
 #else // !defined(IOCORE_LOG_COLLATION)
   // create a new collation client if necessary
@@ -326,14 +328,15 @@ LogHost::preproc_and_try_delete (LogBuffer *lb)
     Debug("log-buftrak", "[%d]LogHost::preproc_and_try_delete - orphan write complete",
         lb->header()->id);
 #endif // defined(LOG_BUFFER_TRACKING)
+    return -1;
   }
 
-  return;
+  return 0;
 #endif // !defined(IOCORE_LOG_COLLATION)
 
 done:
   LogBuffer::destroy(lb);
-  return;
+  return ret;
 }
 
 //
@@ -355,7 +358,7 @@ LogHost::orphan_write_and_try_delete(LogBuffer * lb)
     Debug("log-host", "Sending LogBuffer to orphan file %s", m_orphan_file->get_name());
     m_orphan_file->preproc_and_try_delete(lb);
   } else {
-    Note("logging space exhausted, failed to write orphan file, drop(%" PRIu32 ") bytes",
+    Debug("log-host", "logging space exhausted, failed to write orphan file, drop(%" PRIu32 ") bytes",
          lb->header()->byte_count);
     LogBuffer::destroy(lb);
   }
@@ -454,9 +457,10 @@ LogHostList::clear()
   }
 }
 
-void
+int
 LogHostList::preproc_and_try_delete(LogBuffer * lb)
 {
+  int ret;
   unsigned nr_host, nr;
 
   ink_release_assert(lb->m_references == 0);
@@ -465,12 +469,21 @@ LogHostList::preproc_and_try_delete(LogBuffer * lb)
   ink_atomic_increment(&lb->m_references, nr_host);
 
   for (LogHost * host = first(); host && nr; host = next(host)) {
-    host->preproc_and_try_delete(lb);
+    LogHost *lh = host;
+
+    do {
+      ink_atomic_increment(&lb->m_references, 1);
+      ret = lh->preproc_and_try_delete(lb);
+    } while (ret < 0 && (lh = lh->failover_link.next));
+
+    LogBuffer::destroy(lb);
     nr--;
   }
 
   if (nr_host == 0)
     delete lb;
+
+  return 0;
 }
 
 void

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/54883f2f/proxy/logging/LogHost.h
----------------------------------------------------------------------
diff --git a/proxy/logging/LogHost.h b/proxy/logging/LogHost.h
index e8bec1e..55588d9 100644
--- a/proxy/logging/LogHost.h
+++ b/proxy/logging/LogHost.h
@@ -56,7 +56,7 @@ public:
   // preprocess the given buffer data before sent to target host
   // and try to delete it when its reference become zero.
   //
-  void preproc_and_try_delete(LogBuffer * lb);
+  int preproc_and_try_delete(LogBuffer * lb);
 
   char const* name() const { return m_name ? m_name : "UNKNOWN"; }
   IpAddr const& ip_addr() const { return m_ip; }
@@ -96,6 +96,7 @@ private:
 
 public:
   LINK(LogHost, link);
+  SLINK(LogHost, failover_link);
 
 private:
   // -- member functions not allowed --
@@ -115,7 +116,7 @@ public:
   void add(LogHost * host, bool copy = true);
   unsigned count();
   void clear();
-  void preproc_and_try_delete(LogBuffer * lb);
+  int preproc_and_try_delete(LogBuffer * lb);
 
   LogHost *first() { return m_host_list.head; }
   LogHost *next(LogHost * here) { return (here->link).next; }


[2/2] git commit: TS-2260: Avoid flooding log when log host is down

Posted by yu...@apache.org.
TS-2260: Avoid flooding log when log host is down

Signed-off-by: Yunkai Zhang <qi...@taobao.com>


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/4591314f
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/4591314f
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/4591314f

Branch: refs/heads/master
Commit: 4591314f6682b695c2b6996bf928c545d617e0c4
Parents: 54883f2
Author: Yunkai Zhang <qi...@taobao.com>
Authored: Mon Sep 30 23:33:52 2013 +0800
Committer: Yunkai Zhang <qi...@taobao.com>
Committed: Tue Oct 1 12:59:11 2013 +0800

----------------------------------------------------------------------
 proxy/logging/Log.cc                  | 2 +-
 proxy/logging/LogCollationClientSM.cc | 8 ++++++--
 proxy/logging/LogCollationClientSM.h  | 1 +
 3 files changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4591314f/proxy/logging/Log.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
index ea6493f..ce15131 100644
--- a/proxy/logging/Log.cc
+++ b/proxy/logging/Log.cc
@@ -1382,7 +1382,7 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */)
       //
       while (total_bytes - bytes_written) {
         if (Log::config->logging_space_exhausted) {
-          Warning("logging space exhausted, failed to write file:%s, have dropped (%d) bytes.",
+          Debug("log", "logging space exhausted, failed to write file:%s, have dropped (%d) bytes.",
                   logfile->m_name, (total_bytes - bytes_written));
 
           RecIncrRawStat(log_rsb, mutex->thread_holding,

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4591314f/proxy/logging/LogCollationClientSM.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/LogCollationClientSM.cc b/proxy/logging/LogCollationClientSM.cc
index e4d2a65..ef865e6 100644
--- a/proxy/logging/LogCollationClientSM.cc
+++ b/proxy/logging/LogCollationClientSM.cc
@@ -71,6 +71,7 @@ LogCollationClientSM::LogCollationClientSM(LogHost * log_host)
     m_pending_event(NULL),
     m_abort_vio(NULL),
     m_abort_buffer(NULL),
+    m_host_is_up(false),
     m_buffer_send_list(NULL),
     m_buffer_in_iocore(NULL),
     m_flow(LOG_COLL_FLOW_ALLOW),
@@ -262,6 +263,7 @@ LogCollationClientSM::client_auth(int event, VIO * /* vio ATS_UNUSED */)
     Debug("log-coll", "[%d]client::client_auth - WRITE_COMPLETE", m_id);
 
     Note("[log-coll] host up [%s:%u]", m_log_host->ip_addr().toString(ipb, sizeof(ipb)), m_log_host->port());
+    m_host_is_up = true;
 
     return client_send(LOG_COLL_EVENT_SWITCH, NULL);
 
@@ -403,13 +405,15 @@ LogCollationClientSM::client_fail(int event, void * /* data ATS_UNUSED */)
     Debug("log-coll", "[%d]client::client_fail - SWITCH", m_id);
     m_client_state = LOG_COLL_CLIENT_FAIL;
 
-    Note("[log-coll] host down [%s:%u]", m_log_host->ip_addr().toString(ipb, sizeof ipb), m_log_host->m_port);
-    {
+    // avoid flooding log when host is down
+    if (m_host_is_up) {
+      Note("[log-coll] host down [%s:%u]", m_log_host->ip_addr().toString(ipb, sizeof ipb), m_log_host->m_port);
       char msg_buf[128];
       snprintf(msg_buf, sizeof(msg_buf), "Collation host %s:%u down",
                m_log_host->ip_addr().toString(ipb, sizeof ipb), m_log_host->m_port
       );
       REC_SignalManager(400, msg_buf);
+      m_host_is_up = false;
     }
 
     // close our NetVConnection (do I need to delete this)

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4591314f/proxy/logging/LogCollationClientSM.h
----------------------------------------------------------------------
diff --git a/proxy/logging/LogCollationClientSM.h b/proxy/logging/LogCollationClientSM.h
index 594e61c..291fe02 100644
--- a/proxy/logging/LogCollationClientSM.h
+++ b/proxy/logging/LogCollationClientSM.h
@@ -104,6 +104,7 @@ private:
   // to detect server closes (there's got to be a better way to do this)
   VIO *m_abort_vio;
   MIOBuffer *m_abort_buffer;
+  bool m_host_is_up;
 
   // send stuff
   LogBufferList *m_buffer_send_list;