trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z..@apache.org
Subject svn commit: r1166608 - in /trafficserver/traffic/trunk: ./ proxy/ proxy/logging/
Date Thu, 08 Sep 2011 10:26:01 GMT
Author: zym
Date: Thu Sep  8 10:26:00 2011
New Revision: 1166608

URL: http://svn.apache.org/viewvc?rev=1166608&view=rev
Log:
TS-168 revert iObject related changes in logging

we have remove the iObject/iObjectActivator/iLogBufferData and revert
the locking change too. the logging is now much clean, and it is a
good start for other changes.

things beyond revert include:
1, make LogObject compare really works, do not need to close and then
reopen the connections(when do remote logging), the files(when do local
file logging).
2, rework the size based rolling with a simple way.

Modified:
    trafficserver/traffic/trunk/CHANGES
    trafficserver/traffic/trunk/proxy/UglyLogStubs.cc
    trafficserver/traffic/trunk/proxy/logcat.cc
    trafficserver/traffic/trunk/proxy/logging/Log.cc
    trafficserver/traffic/trunk/proxy/logging/Log.h
    trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc
    trafficserver/traffic/trunk/proxy/logging/LogBuffer.h
    trafficserver/traffic/trunk/proxy/logging/LogBufferSink.h
    trafficserver/traffic/trunk/proxy/logging/LogCollationClientSM.cc
    trafficserver/traffic/trunk/proxy/logging/LogCollationHostSM.cc
    trafficserver/traffic/trunk/proxy/logging/LogConfig.cc
    trafficserver/traffic/trunk/proxy/logging/LogConfigCollation.cc
    trafficserver/traffic/trunk/proxy/logging/LogField.cc
    trafficserver/traffic/trunk/proxy/logging/LogField.h
    trafficserver/traffic/trunk/proxy/logging/LogFile.cc
    trafficserver/traffic/trunk/proxy/logging/LogFile.h
    trafficserver/traffic/trunk/proxy/logging/LogFilter.cc
    trafficserver/traffic/trunk/proxy/logging/LogHost.cc
    trafficserver/traffic/trunk/proxy/logging/LogHost.h
    trafficserver/traffic/trunk/proxy/logging/LogObject.cc
    trafficserver/traffic/trunk/proxy/logging/LogObject.h
    trafficserver/traffic/trunk/proxy/logging/Makefile.am

Modified: trafficserver/traffic/trunk/CHANGES
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/CHANGES?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/CHANGES (original)
+++ trafficserver/traffic/trunk/CHANGES Thu Sep  8 10:26:00 2011
@@ -1,5 +1,8 @@
 s                                                         -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 3.1.1
+  *) [TS-168] revert iObject and other changes, make collation client work
+   in the clean way.
+
   *) [TS-941] invalid cast of off_t math to int. Author: B Wyatt.
 
   *) [TS-940] Add new configuration option, and solaris support, to set

Modified: trafficserver/traffic/trunk/proxy/UglyLogStubs.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/UglyLogStubs.cc?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/UglyLogStubs.cc (original)
+++ trafficserver/traffic/trunk/proxy/UglyLogStubs.cc Thu Sep  8 10:26:00 2011
@@ -101,38 +101,57 @@ this_machine()
   return NULL;
 }
 
+#include "LogCollationAccept.h"
+LogCollationAccept::LogCollationAccept(int port)
+  : Continuation(new_ProxyMutex()),
+    m_port(port),
+    m_pending_event(NULL)
+{
+}
+LogCollationAccept::~LogCollationAccept()
+{
+}
 
-#include "LogConfig.h"
-void
-LogConfig::setup_collation(LogConfig * prev_config)
+//
+//int
+//LogHost::write(LogBuffer * lb)
+//{
+//  NOWARN_UNUSED(lb);
+//  ink_release_assert(false);
+//  return 0;
+//}
+
+#include "LogCollationClientSM.h"
+LogCollationClientSM::LogCollationClientSM(LogHost * log_host):
+  Continuation(new_ProxyMutex()),
+  m_host_vc(NULL),
+  m_host_vio(NULL),
+  m_auth_buffer(NULL),
+  m_auth_reader(NULL),
+  m_send_buffer(NULL),
+  m_send_reader(NULL),
+  m_pending_action(NULL),
+  m_pending_event(NULL),
+  m_abort_vio(NULL),
+  m_abort_buffer(NULL),
+  m_buffer_send_list(NULL), m_buffer_in_iocore(NULL), m_flow(LOG_COLL_FLOW_ALLOW), m_log_host(log_host), m_id(0)
 {
-  NOWARN_UNUSED(prev_config);
-  ink_release_assert(false);
+  Debug("log-coll", "[%d]client::constructor", m_id);
 }
 
-void
-LogConfig::create_pre_defined_objects_with_filter(const PreDefinedFormatInfoList & pre_def_info_list, size_t num_filters,
-                                                  LogFilter ** filter, const char *filt_name, bool force_extension)
-{
-  NOWARN_UNUSED(pre_def_info_list);
-  NOWARN_UNUSED(num_filters);
-  NOWARN_UNUSED(filter);
-  NOWARN_UNUSED(filt_name);
-  NOWARN_UNUSED(force_extension);
-  ink_release_assert(false);
+LogCollationClientSM::~LogCollationClientSM()
+{
 }
 
 int
-LogHost::write(LogBuffer * lb, size_t * to_disk, size_t * to_net, size_t * to_pipe)
+LogCollationClientSM::send(LogBuffer * log_buffer)
 {
-  NOWARN_UNUSED(lb);
-  NOWARN_UNUSED(to_disk);
-  NOWARN_UNUSED(to_net);
-  NOWARN_UNUSED(to_pipe);
+  NOWARN_UNUSED(log_buffer);
   ink_release_assert(false);
   return 0;
 }
 
+
 // TODO: The following was necessary only for Solaris, should examine more.
 NetVCOptions const Connection::DEFAULT_OPTIONS;
 NetProcessor::AcceptOptions const NetProcessor::DEFAULT_ACCEPT_OPTIONS;
@@ -175,9 +194,3 @@ CacheVC::handleWrite(int event, Event *e
   return 0;
   ink_release_assert(false);
 }
-
-// LogHost destructor will need this, for solaris
-#include "LogCollationClientSM.h"
-LogCollationClientSM::~LogCollationClientSM()
-{
-}

Modified: trafficserver/traffic/trunk/proxy/logcat.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logcat.cc?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logcat.cc (original)
+++ trafficserver/traffic/trunk/proxy/logcat.cc Thu Sep  8 10:26:00 2011
@@ -29,6 +29,7 @@
 
 #define PROGRAM_NAME        "traffic_logcat"
 #define MAX_LOGBUFFER_SIZE  65536
+#undef IOCORE_LOG_COLLATION
 
 #include <poll.h>
 

Modified: trafficserver/traffic/trunk/proxy/logging/Log.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/Log.cc?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/Log.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/Log.cc Thu Sep  8 10:26:00 2011
@@ -171,6 +171,31 @@ Log::add_to_inactive(LogObject * object)
   -------------------------------------------------------------------------*/
 
 /*-------------------------------------------------------------------------
+  PeriodicWakeup
+
+  This continuation is invoked each second to wake-up the flush thread,
+  just in case it's sleeping on the job.
+  -------------------------------------------------------------------------*/
+
+struct PeriodicWakeup;
+typedef int (PeriodicWakeup::*PeriodicWakeupHandler)(int, void *);
+struct PeriodicWakeup : Continuation {
+
+    int wakeup (int event, Event *e)
+    {
+        NOWARN_UNUSED (event); NOWARN_UNUSED (e);
+        ink_cond_signal (&Log::flush_cond);
+        return EVENT_CONT;
+    }
+
+    PeriodicWakeup () : Continuation (new_ProxyMutex())
+    {
+        SET_HANDLER ((PeriodicWakeupHandler)&PeriodicWakeup::wakeup);
+    }
+};
+
+
+/*-------------------------------------------------------------------------
   Log::periodic_tasks
 
   This function contains all of the tasks that need to be done each
@@ -249,12 +274,12 @@ Log::periodic_tasks(long time_now)
       Log::config->roll_log_files_now = FALSE;
     } else {
       if (error_log) {
-        num_rolled += error_log->roll_files_if_needed(time_now);
+        num_rolled += error_log->roll_files(time_now);
       }
       if (global_scrap_object) {
-        num_rolled += global_scrap_object->roll_files_if_needed(time_now);
+        num_rolled += global_scrap_object->roll_files(time_now);
       }
-      num_rolled += Log::config->log_object_manager.roll_files_if_needed(time_now);
+      num_rolled += Log::config->log_object_manager.roll_files(time_now);
     }
 
   }
@@ -848,34 +873,27 @@ Log::handle_logging_mode_change(const ch
 void
 Log::init(int flags)
 {
-  iObject::Init();
-  iLogBufferBuffer::Init();
-
   maxInactiveObjects = LOG_OBJECT_ARRAY_DELTA;
   numInactiveObjects = 0;
-  inactive_objects = new LogObject *[maxInactiveObjects];
+  inactive_objects = new LogObject*[maxInactiveObjects];
 
   collation_accept_file_descriptor = NO_FD;
 
-  // initialize logging fields
-  //
-  init_fields();
-
   // store the configuration flags
   //
   config_flags = flags;
 
   // create the configuration object
   //
-  config = NEW(new LogConfig);
-  ink_assert(config != NULL);
+  config = NEW (new LogConfig);
+  ink_assert (config != NULL);
 
-  // set the logging_mode and initialize
+  // set the logging_mode and read config variables if needed
   //
   if (config_flags & LOGCAT) {
     logging_mode = LOG_NOTHING;
-  } else {
-
+  }
+  else {
     log_rsb = RecAllocateRawStatBlock((int) log_stat_count);
     LogConfig::register_stat_callbacks();
 
@@ -884,53 +902,66 @@ Log::init(int flags)
 
     if (config_flags & STANDALONE_COLLATOR) {
       logging_mode = LOG_TRANSACTIONS_ONLY;
-      config->collation_mode = LogConfig::COLLATION_HOST;
-    } else {
+    }
+    else {
       int val = (int) LOG_ConfigReadInteger("proxy.config.log.logging_enabled");
-      if (val<LOG_NOTHING || val> FULL_LOGGING) {
+      if (val < LOG_NOTHING || val > FULL_LOGGING) {
         logging_mode = FULL_LOGGING;
-        Warning("proxy.config.log.logging_enabled has an invalid " "value, setting it to %d", logging_mode);
-      } else {
+        Warning("proxy.config.log.logging_enabled has an invalid "
+          "value, setting it to %d", logging_mode);
+      }
+      else {
         logging_mode = (LoggingMode) val;
       }
     }
+  }
 
-    config->init();
-    _init();
+  // if remote management is enabled, do all necessary initialization to
+  // be able to handle a logging mode change
+  //
+  if (!(config_flags & NO_REMOTE_MANAGEMENT)) {
 
-    // Clear any stat values that need to be reset on startup
+    LOG_RegisterConfigUpdateFunc("proxy.config.log.logging_enabled",
+        &Log::handle_logging_mode_change, NULL);
+
+    LOG_RegisterLocalUpdateFunc("proxy.local.log.collation_mode",
+        &Log::handle_logging_mode_change, NULL);
+
+    // we must create the flush thread since it takes care of the
+    // periodic events (should this behavior be reversed ?)
     //
-    LOG_CLEAR_DYN_STAT(log_stat_log_files_open_stat);
-    LOG_CLEAR_DYN_STAT(log_stat_log_files_space_used_stat);
-/*
-        The following variables are not cleared at startup, although
-	we probably should because otherwise their meaning is not very
-	clear. When did we start counting? Does it make sense to have
-	these values since the Traffic Server was setup on the
-	machine?
-
-	LOG_CLEAR_DYN_STAT(log_stat_bytes_written_to_disk_stat);
-	LOG_CLEAR_DYN_STAT(log_stat_bytes_sent_to_network_stat);
-	LOG_CLEAR_DYN_STAT(log_stat_bytes_received_from_network_stat);
-	LOG_CLEAR_DYN_STAT(log_stat_event_log_access_stat);
-	LOG_CLEAR_DYN_STAT(log_stat_event_log_access_skip_stat);
-	LOG_CLEAR_DYN_STAT(log_stat_event_log_access_fail_stat);
-	LOG_CLEAR_DYN_STAT(log_stat_event_log_error_stat);
-*/
-    // if remote management is enabled, do all necessary initialization to
-    // be able to handle a logging mode change
+    create_threads();
+
+#ifndef INK_SINGLE_THREADED
+    eventProcessor.schedule_every(NEW (new PeriodicWakeup()), HRTIME_SECOND,
+        ET_CALL);
+#endif
+    init_status |= PERIODIC_WAKEUP_SCHEDULED;
+
+    // Clear any stat values that need to be reset on startup
     //
-    if (!(config_flags & NO_REMOTE_MANAGEMENT)) {
+    LOG_CLEAR_DYN_STAT( log_stat_log_files_open_stat);
+  }
 
-      LOG_RegisterConfigUpdateFunc("proxy.config.log.logging_enabled", &Log::handle_logging_mode_change, NULL);
-      LOG_RegisterLocalUpdateFunc("proxy.local.log.collation_mode", &Log::handle_logging_mode_change, NULL);
+  if (config_flags & LOGCAT) {
+    init_fields();
+  }
+  else {
+    Debug("log-config", "Log::init(): logging_mode = %d "
+        "init status = %d", logging_mode, init_status);
+    init_when_enabled();
+    if (config_flags & STANDALONE_COLLATOR) {
+      config->collation_mode = LogConfig::COLLATION_HOST;
     }
+    config->init();
   }
 }
 
 void
-Log::_init()
+Log::init_when_enabled()
 {
+  init_fields();
+
   if (!(init_status & FULLY_INITIALIZED)) {
 
     if (!(config_flags & STANDALONE_COLLATOR)) {
@@ -1120,29 +1151,24 @@ Log::va_error(char *format, va_list ap)
 void *
 Log::flush_thread_main(void *args)
 {
+  NOWARN_UNUSED (args);
   time_t now, last_time = 0;
-  size_t total_bytes, bytes_to_disk, bytes_to_net, bytes_to_pipe;
+  size_t buffers_flushed;
 
   Debug("log-flush", "Log flush thread is alive ...");
 
   while (true) {
-    ink_timestruc timeout_time;
+    buffers_flushed = 0;
 
-    bytes_to_disk = (bytes_to_net = (bytes_to_pipe = 0));
-    total_bytes = config->log_object_manager.flush_buffers(&bytes_to_disk, &bytes_to_net, &bytes_to_pipe);
+    buffers_flushed = config->log_object_manager.flush_buffers();
 
     if (error_log)
-      total_bytes += error_log->flush_buffers(&bytes_to_disk, &bytes_to_net, &bytes_to_pipe);
+      buffers_flushed += error_log->flush_buffers();
 
-    config->increment_space_used(bytes_to_disk);
+    // config->increment_space_used(bytes_to_disk);
+    // TODO: the bytes_to_disk should be set to Log
 
-    // Update statistics
-    //
-    LOG_SUM_GLOBAL_DYN_STAT(log_stat_bytes_written_to_disk_stat, bytes_to_disk);
-    LOG_SUM_GLOBAL_DYN_STAT(log_stat_bytes_sent_to_network_stat, bytes_to_net);
-
-    Debug("log-flush", "%d bytes flushed this round [ %d to disk, %d to net, %d to pipe]",
-          total_bytes, bytes_to_disk, bytes_to_net, bytes_to_pipe);
+    Debug("log-flush","%d buffers flushed this round", buffers_flushed);
 
     // Time to work on periodic events??
     //
@@ -1158,22 +1184,10 @@ Log::flush_thread_main(void *args)
     // check the queue and find there is nothing to do, then wait
     // again.
     //
-    //ink_cond_wait (&flush_cond, &flush_mutex);
-
-    // vl: we should use ink_cond_timedwait in order to be sure that this thread is alive at least once per second
-    // to execute periodic_tasks()
-    memset(&timeout_time, 0, sizeof(timeout_time));
-    ink_mutex_acquire(&flush_mutex);
-    while (flush_counter < FLUSH_THREAD_MIN_FLUSH_COUNTER && now <= last_time) {
-      timeout_time.tv_sec = (now = time(NULL)) + FLUSH_THREAD_SLEEP_TIMEOUT;
-      if (ink_cond_timedwait(&flush_cond, &flush_mutex, &timeout_time) == ETIMEDOUT)
-        break;
-    }
-    flush_counter = 0;
-    ink_mutex_release(&flush_mutex);
+    ink_cond_wait (&flush_cond, &flush_mutex);
   }
   /* NOTREACHED */
-  return args;
+  return NULL;
 }
 
 /*-------------------------------------------------------------------------

Modified: trafficserver/traffic/trunk/proxy/logging/Log.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/Log.h?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/Log.h (original)
+++ trafficserver/traffic/trunk/proxy/logging/Log.h Thu Sep  8 10:26:00 2011
@@ -339,7 +339,8 @@ public:
   {
     FIELDS_INITIALIZED = 1,
     THREADS_CREATED = 2,
-    FULLY_INITIALIZED = 4
+    PERIODIC_WAKEUP_SCHEDULED = 4,
+    FULLY_INITIALIZED = 8
   };
 
   enum ConfigFlags
@@ -416,7 +417,7 @@ private:
 
   static void periodic_tasks(long time_now);
   static void create_threads();
-  static void _init();
+  static void init_when_enabled();
 
   static int init_status;
   static int config_flags;

Modified: trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc Thu Sep  8 10:26:00 2011
@@ -69,132 +69,6 @@ FieldListCacheElement fieldlist_cache[FI
 int fieldlist_cache_entries = 0;
 vint32 LogBuffer::M_ID = 0;
 
-//iObjectActivator  iObjectActivatorInstance;     /* just to do ::Init() before main() */
-
-iObject *iObject::free_heap = 0;       /* list of free blocks */
-ink_mutex iObject::iObjectMutex;        /* mutex for access iObject class global variables */
-
-iLogBufferBuffer *iLogBufferBuffer::free_heap = 0;      /* list of free blocks */
-ink_mutex iLogBufferBuffer::iLogBufferBufferMutex;      /* mutex for access iLogBufferBuffer class global variables */
-
-
-/* --------------------- iStaticBuf_LogBuffer::Init ------------------------ */
-void
-iLogBufferBuffer::Init(void)
-{
-  ink_mutex_init(&iLogBufferBufferMutex, "iLogBufferBufferMutex");
-}
-
-/* ------------------ iLogBufferBuffer::New_iLogBufferBuffer --------------- */
-iLogBufferBuffer *
-iLogBufferBuffer::New_iLogBufferBuffer(size_t _buf_size)
-{
-  iLogBufferBuffer **objj, **objj_best = 0;
-  iLogBufferBuffer *ob = 0, *ob_best = 0;
-
-  if (_buf_size > 0) {
-    ink_mutex_acquire(&iLogBufferBufferMutex);
-    for (objj = &free_heap; (ob = *objj) != 0; objj = &(ob->next)) {
-      if (ob->real_buf_size == _buf_size) {
-        *objj = ob->next;
-        break;
-      } else if (ob->real_buf_size > _buf_size) {
-        if (!ob_best || ob_best->real_buf_size > ob->real_buf_size) {
-          ob_best = ob;
-          objj_best = objj;
-        }
-      }
-    }
-    if (!ob && ob_best && objj_best) {
-      *objj_best = (ob = ob_best)->next;
-    }
-    ink_mutex_release(&iLogBufferBufferMutex);
-
-    if (!ob) {
-      ob = new iLogBufferBuffer();
-      if (ob) {
-        ob->buf = (char *)ats_malloc(_buf_size);
-        ob->real_buf_size = _buf_size;
-      }
-    }
-
-    if (likely(ob)) {           /* we need to touch it in order to be sure that this
-                                   page in the physical memory, plus, we zero it! */
-      memset(ob->buf, 0, ob->real_buf_size);
-      ob->size = _buf_size;
-    }
-  }
-  return ob;
-}
-
-/* ----------------- iLogBufferBuffer::Delete_iLogBufferBuffer ------------- */
-iLogBufferBuffer *
-iLogBufferBuffer::Delete_iLogBufferBuffer(iLogBufferBuffer * _b)
-{
-  if (likely(_b)) {
-    ink_mutex_acquire(&iLogBufferBufferMutex);
-    _b->next = free_heap;
-    free_heap = _b;
-    ink_mutex_release(&iLogBufferBufferMutex);
-  }
-  return (iLogBufferBuffer *) 0;
-}
-
-/* --------------------------- iObject::Init ------------------------------- */
-void
-iObject::Init(void)
-{
-  ink_mutex_init(&iObjectMutex, "iObjectMutex");
-}
-
-/* ---------------------------- iObject::new ------------------------------- */
-void *
-iObject::operator new(size_t _size)
-{
-  iObject **objj, **objj_best = NULL;
-  iObject *ob = NULL, *ob_best = NULL;
-  size_t real_size = _size;
-
-  ink_mutex_acquire(&iObjectMutex);
-  for (objj = &free_heap; (ob = *objj) != NULL; objj = &(ob->next_object)) {
-    if (ob->class_size == _size) {
-      *objj = ob->next_object;
-      break;
-    } else if (ob->class_size > _size) {
-      if (!ob_best || ob_best->class_size > ob->class_size) {
-        ob_best = ob;
-        objj_best = objj;
-      }
-    }
-  }
-  if (!ob && ob_best && objj_best) {
-    *objj_best = (ob = ob_best)->next_object;
-    real_size = ob->class_size;
-  }
-  ink_mutex_release(&iObjectMutex);
-
-  if (!ob)
-    ob = (iObject *)ats_malloc(_size);
-
-  if (likely(ob)) {
-    memset(ob, 0, _size);
-    ob->class_size = real_size;
-  }
-  return (void *) ob;
-}
-
-/* --------------------------- iObject::delete ----------------------------- */
-void
-iObject::operator delete(void *p)
-{
-  iObject *ob = (iObject *) p;
-
-  ink_mutex_acquire(&iObjectMutex);
-  ob->next_object = free_heap;
-  free_heap = ob;
-  ink_mutex_release(&iObjectMutex);
-}
-
 /*-------------------------------------------------------------------------
   The following LogBufferHeader routines are used to grab strings out from
   the data section using the offsets held in the buffer header.
@@ -261,25 +135,19 @@ LogBufferHeader::log_filename()
   -------------------------------------------------------------------------*/
 
 LogBuffer::LogBuffer(LogObject * owner, size_t size, size_t buf_align, size_t write_align):
-  sign(CLASS_SIGN_LOGBUFFER),
   next_flush(NULL),
   next_list(NULL),
-  m_new_buffer(NULL),
   m_size(size),
   m_buf_align(buf_align),
   m_write_align(write_align), m_max_entries(Log::config->max_entries_per_buffer), m_owner(owner)
 {
   size_t hdr_size;
 
-//    Debug("log-logbuffer","LogBuffer::LogBuffer(owner,size=%ld, buf_align=%ld,write_align=%ld)",
-//          size,buf_align,write_align);
-
-  // create the buffer: size + LB_DEFAULT_ALIGN(512)
-  m_bb = iLogBufferBuffer::New_iLogBufferBuffer(size + buf_align);
-  ink_assert(m_bb != NULL);
-
-  m_unaligned_buffer = m_bb->buf;
-  m_buffer = (char *) align_pointer_forward(m_unaligned_buffer, buf_align);
+  // create the buffer
+  //
+  m_unaligned_buffer = NEW (new char [size + buf_align]);
+  m_buffer = (char *)align_pointer_forward(m_unaligned_buffer,
+                                           buf_align);
 
   // add the header
   hdr_size = _add_buffer_header();
@@ -293,15 +161,13 @@ LogBuffer::LogBuffer(LogObject * owner, 
 
   m_expiration_time = LogUtils::timestamp() + Log::config->max_secs_per_buffer;
 
-//    Debug("log-logbuffer","[%p] Created buffer %u for %s at address %p, size %d",
-//        this_ethread(), m_id, m_owner->get_base_filename(), m_buffer, (int)size);
+  Debug("log-logbuffer","[%p] Created buffer %u for %s at address %p, size %d",
+        this_ethread(), m_id, m_owner->get_base_filename(), m_buffer, (int)size);
 }
 
 LogBuffer::LogBuffer(LogObject * owner, LogBufferHeader * header):
-  sign(CLASS_SIGN_LOGBUFFER),
   next_flush(NULL),
   next_list(NULL),
-  m_bb(NULL),
   m_unaligned_buffer(NULL),
   m_buffer((char *) header),
   m_size(0),
@@ -313,34 +179,26 @@ LogBuffer::LogBuffer(LogObject * owner, 
   // no checkout writes or checkin writes are allowed. This is enforced
   // by the asserts in checkout_write and checkin_write
 
-//    Debug("log-logbuffer","LogBuffer::LogBuffer(owner,header)");
-
-  m_new_buffer = (char *) header;       /* must be deleted inside destructor */
-
   // update the buffer id (m_id gets the old value)
   //
   m_id = (uint32_t) ink_atomic_increment((pvint32) & M_ID, 1);
 
-//    Debug("log-logbuffer","[%p] Created buffer %u for %s at address %p",
-//        this_ethread(), m_id, m_owner->get_base_filename(), m_buffer);
+  Debug("log-logbuffer","[%p] Created buffer %u for %s at address %p",
+        this_ethread(), m_id, m_owner->get_base_filename(), m_buffer);
 }
 
 LogBuffer::~LogBuffer()
 {
-  ink_assert(sign == CLASS_SIGN_LOGBUFFER);     /* vl: FIXME remove it later */
-  if (sign == CLASS_SIGN_LOGBUFFER) {
-    sign = 0;
-    m_unaligned_buffer = (m_buffer = 0);
-    m_size = 0;
-    if (m_new_buffer) {
-      delete m_new_buffer;
-      m_new_buffer = 0;
-    }
-    m_bb = iLogBufferBuffer::Delete_iLogBufferBuffer(m_bb);
-//      Debug("log-logbuffer", "[%p] Deleted buffer %u", this_ethread(), m_id);
+  if (m_unaligned_buffer) {
+    delete [] m_unaligned_buffer;
+  } else {
+    delete [] m_buffer;
   }
-//    else
-//      Debug("log-logbuffer", "Incorrect signature 0x%08lX inside LogBuffer::~LogBuffer()", sign);
+
+  Debug("log-logbuffer", "[%p] Deleted buffer %u at address %p",
+        this_ethread(), m_id, m_unaligned_buffer?m_unaligned_buffer:m_buffer);
+  m_buffer = 0;
+  m_unaligned_buffer = 0;
 }
 
 /*-------------------------------------------------------------------------
@@ -355,10 +213,7 @@ LogBuffer::LB_ResultCode LogBuffer::chec
   // LogBuffer::LogBuffer(LogObject *owner, LogBufferHeader *header)
   // was used to construct the object
   //
-  //ink_debug_assert(m_unaligned_buffer);
-
-  ink_assert(sign == CLASS_SIGN_LOGBUFFER);
-  ink_assert(m_unaligned_buffer != NULL);
+  ink_debug_assert(m_unaligned_buffer);
 
   LB_ResultCode
     ret_val = LB_BUSY;
@@ -472,9 +327,7 @@ LogBuffer::LB_ResultCode LogBuffer::chec
   // LogBuffer::LogBuffer(LogObject *owner, LogBufferHeader *header)
   // was used to construct the object
   //
-  //ink_debug_assert(m_unaligned_buffer);
-  ink_assert(sign == CLASS_SIGN_LOGBUFFER);
-  ink_assert(m_unaligned_buffer != NULL);
+  ink_debug_assert(m_unaligned_buffer);
 
   LB_ResultCode ret_val = LB_OK;
   LB_State old_s, new_s;
@@ -517,7 +370,6 @@ LogBuffer::_add_buffer_header()
 {
   size_t header_len;
 
-  ink_assert(sign == CLASS_SIGN_LOGBUFFER);
   //
   // initialize the header
   //
@@ -588,7 +440,6 @@ LogBuffer::update_header_data()
   // only update the header if the LogBuffer did not receive its data
   // upon construction (i.e., if m_unaligned_buffer was allocated)
   //
-  ink_assert(sign == CLASS_SIGN_LOGBUFFER);
 
   if (m_unaligned_buffer) {
     m_header->entry_count = m_state.s.num_entries;
@@ -1048,7 +899,6 @@ LogBuffer::convert_to_host_order(LogBuff
 LogBufferList::LogBufferList()
 {
   m_size = 0;
-  m_list_last_ptr = (m_list = 0);
   ink_mutex_init(&m_mutex, "LogBufferList");
 }
 
@@ -1058,18 +908,12 @@ LogBufferList::LogBufferList()
 
 LogBufferList::~LogBufferList()
 {
-  LogBuffer *lb, *_list;
+  LogBuffer *lb;
   ink_mutex_acquire(&m_mutex);
-  _list = m_list;
-  m_list_last_ptr = (m_list = 0);
   m_size = 0;
-  ink_mutex_release(&m_mutex);
-
-  while ((lb = _list) != NULL) {
-    _list = lb->next_list;
-    delete lb;
+  while ((lb = get()) != NULL) {
+      delete lb;
   }
-  ink_mutex_acquire(&m_mutex);
   ink_mutex_release(&m_mutex);
   ink_mutex_destroy(&m_mutex);
 }
@@ -1082,13 +926,10 @@ void
 LogBufferList::add(LogBuffer * lb)
 {
   ink_assert(lb != NULL);
-  lb->next_list = 0;
+
   ink_mutex_acquire(&m_mutex);
-  if (m_list && m_list_last_ptr) {
-    m_list_last_ptr->next_list = lb;
-  } else
-    m_list = lb;
-  m_list_last_ptr = lb;
+  m_buffer_list.enqueue (lb);
+  ink_assert(m_size >= 0);
   m_size++;
   ink_mutex_release(&m_mutex);
 }
@@ -1103,13 +944,14 @@ LogBufferList::get()
   LogBuffer *lb;
 
   ink_mutex_acquire(&m_mutex);
-
-  if ((lb = m_list) != 0) {
-    if ((m_list = lb->next_list) == 0)
-      m_list_last_ptr = 0;
+  lb =  m_buffer_list.dequeue ();
+  if (lb != NULL) {
     m_size--;
+    ink_assert(m_size >= 0);
+//      hrtime_t t = gethrtime();
+//      printf("%lld removed buffer %p from queue %p, size = %d\n", t, lb,
+//           this, m_size);
   }
-  ink_assert(m_size >= 0);
   ink_mutex_release(&m_mutex);
   return lb;
 }

Modified: trafficserver/traffic/trunk/proxy/logging/LogBuffer.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogBuffer.h?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogBuffer.h (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogBuffer.h Thu Sep  8 10:26:00 2011
@@ -129,99 +129,12 @@ union LB_State
   } s;
 };
 
-
-/* ---------------------------------- iObject ------------------------------ */
-class iObjectActivator;
-class iObject
-{
-private:
-  static iObject *free_heap;    /* list of free blocks */
-  static ink_mutex iObjectMutex;        /* mutex for access to iObject class global variables */
-
-  size_t class_size;            /* real class size */
-  iObject *next_object;
-
-
-protected:
-  iObject(const iObject &);   /* declared; not implemented - block copying and assignment */
-  iObject & operator=(const iObject &);       /* ditto */
-
-public:
-  static void Init(void);
-  void *operator  new(size_t size);
-  void operator  delete(void *p);
-
- iObject()
- {                             /* nop */
- }
-
- virtual ~iObject()
- {                             /* nop */
- }
-
- friend class iObjectActivator;
-};
-
-/* ------------------------------ iLogBufferBuffer ------------------------- */
-class iLogBufferBuffer
-{
-private:
-  static iLogBufferBuffer *free_heap;   /* list of free blocks */
-  static ink_mutex iLogBufferBufferMutex;       /* mutex for access iLogBufferBuffer class global variables */
-
-  iLogBufferBuffer *next;
-  size_t real_buf_size;
-
-
-  iLogBufferBuffer()
-  {
-    next = 0;
-    buf = 0;
-    real_buf_size = (size = 0);
-  }
-
-  ~iLogBufferBuffer()
-  {
-    ats_free(buf);
-    real_buf_size = (size = 0);
-  }
-
-protected:
-  iLogBufferBuffer(const iLogBufferBuffer &);   /* declared; not implemented - block copying and assignment */
-  iLogBufferBuffer & operator=(const iLogBufferBuffer &);       /* ditto */
-
-public:
-  char *buf;
-  size_t size;
-
-  static void Init(void);
-  static iLogBufferBuffer *New_iLogBufferBuffer(size_t _buf_size);
-  static iLogBufferBuffer *Delete_iLogBufferBuffer(iLogBufferBuffer * _b);
-
-  friend class iObjectActivator;
-};
-
-/* ---------------------------- iObjectActivator --------------------------- */
-class iObjectActivator
-{
-public:
-  iObjectActivator()
-  {
-    iObject::Init();
-    iLogBufferBuffer::Init();
-  }
-
-  ~iObjectActivator()
-  {                             /* nop */
-  }
-};
-
 /*-------------------------------------------------------------------------
   LogBuffer
   -------------------------------------------------------------------------*/
 #define CLASS_SIGN_LOGBUFFER 0xFACE5370 /* LogBuffer class signature */
 
-class LogBuffer:public iObject
+class LogBuffer
 {
 public:
   unsigned long sign;           /* class signature (must be CLASS_SIGN_LOGBUFFER) */
@@ -282,7 +195,7 @@ public:
     return m_owner;
   };
 
-  Link<LogBuffer> link;
+  LINK(LogBuffer, link);;
 
   // static variables
   static vint32 M_ID;
@@ -301,8 +214,6 @@ public:
   static void convert_to_host_order(LogBufferHeader * header);
 
 private:
-  iLogBufferBuffer * m_bb;      // real buffer
-  char *m_new_buffer;           // new buffer (must be free)
   char *m_unaligned_buffer;     // the unaligned buffer
   char *m_buffer;               // the buffer
   size_t m_size;                // the buffer size
@@ -342,14 +253,13 @@ class LogFile;
 class LogBufferList
 {
 private:
-  LogBuffer * m_list;
-  LogBuffer *m_list_last_ptr;
+  Queue<LogBuffer> m_buffer_list;
   ink_mutex m_mutex;
   int m_size;
 
 public:
-    LogBufferList();
-   ~LogBufferList();
+  LogBufferList();
+  ~LogBufferList();
 
   void add(LogBuffer * lb);
   LogBuffer *get(void);

Modified: trafficserver/traffic/trunk/proxy/logging/LogBufferSink.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogBufferSink.h?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogBufferSink.h (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogBufferSink.h Thu Sep  8 10:26:00 2011
@@ -35,7 +35,7 @@ the network
 class LogBufferSink
 {
 public:
-  virtual int write(LogBuffer * buffer, size_t * to_disk, size_t * to_net, size_t * to_pipe) = 0;
+  virtual int write(LogBuffer * buffer) = 0;
     virtual ~ LogBufferSink()
   {
   };

Modified: trafficserver/traffic/trunk/proxy/logging/LogCollationClientSM.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogCollationClientSM.cc?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogCollationClientSM.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogCollationClientSM.cc Thu Sep  8 10:26:00 2011
@@ -693,9 +693,9 @@ LogCollationClientSM::client_send(int ev
 #endif // defined(LOG_BUFFER_TRACKING)
 
     // done with the buffer, delete it
+    Debug("log-coll", "[%d]client::client_send - m_buffer_in_iocore[%p] to delete_list", m_id, m_buffer_in_iocore);
     delete m_buffer_in_iocore;
     m_buffer_in_iocore = NULL;
-    Debug("log-coll", "[%d]client::client_send - m_buffer_in_iocore to delete_list", m_id);
 
     // switch back to client_send
     return client_send(LOG_COLL_EVENT_SWITCH, NULL);

Modified: trafficserver/traffic/trunk/proxy/logging/LogCollationHostSM.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogCollationHostSM.cc?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogCollationHostSM.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogCollationHostSM.cc Thu Sep  8 10:26:00 2011
@@ -325,10 +325,7 @@ LogCollationHostSM::host_recv(int event,
         //
         log_buffer = NEW(new LogBuffer(log_object, log_buffer_header));
         log_object->add_to_flush_queue(log_buffer);
-        ink_mutex_acquire(&Log::flush_mutex);
-        Log::flush_counter++;
         ink_cond_signal(&Log::flush_cond);
-        ink_mutex_release(&Log::flush_mutex);
       }
 
 #if defined(LOG_BUFFER_TRACKING)

Modified: trafficserver/traffic/trunk/proxy/logging/LogConfig.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogConfig.cc?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogConfig.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogConfig.cc Thu Sep  8 10:26:00 2011
@@ -656,6 +656,77 @@ LogConfig::~LogConfig()
   ats_free(m_dir_entry);
 }
 
+
+/*-------------------------------------------------------------------------
+  LogConfig::setup_collation
+  -------------------------------------------------------------------------*/
+
+void
+LogConfig::setup_collation(LogConfig * prev_config)
+{
+  // Set-up the collation status, but only if collation is enabled and
+  // there are valid entries for the collation host and port.
+  //
+  if (collation_mode<NO_COLLATION || collation_mode>= N_COLLATION_MODES) {
+    Note("Invalid value %d for proxy.local.log.collation_mode"
+         " configuration variable (valid range is from %d to %d)\n"
+         "Log collation disabled", collation_mode, NO_COLLATION, N_COLLATION_MODES - 1);
+  } else if (collation_mode == NO_COLLATION) {
+    // if the previous configuration had a collation accept, delete it
+    //
+    if (prev_config && prev_config->m_log_collation_accept) {
+      delete prev_config->m_log_collation_accept;
+      prev_config->m_log_collation_accept = NULL;
+    }
+  } else {
+    if (!collation_port) {
+      Note("Cannot activate log collation, %d is and invalid " "collation port", collation_port);
+    } else if (collation_mode > COLLATION_HOST && strcmp(collation_host, "none") == 0) {
+      Note("Cannot activate log collation, \"%s\" is and invalid " "collation host", collation_host);
+    } else {
+      if (collation_mode == COLLATION_HOST) {
+#if defined(IOCORE_LOG_COLLATION)
+
+        ink_debug_assert(m_log_collation_accept == 0);
+
+        if (prev_config && prev_config->m_log_collation_accept) {
+          if (prev_config->collation_port == collation_port) {
+            m_log_collation_accept = prev_config->m_log_collation_accept;
+          } else {
+            delete prev_config->m_log_collation_accept;
+          }
+        }
+
+        if (!m_log_collation_accept) {
+          Log::collation_port = collation_port;
+          m_log_collation_accept = NEW(new LogCollationAccept(collation_port));
+        }
+#else
+        // since we are the collation host, we need to signal the
+        // collate_cond variable so that our collation thread wakes up.
+        //
+        ink_cond_signal(&Log::collate_cond);
+#endif
+        Debug("log", "I am a collation host listening on port %d.", collation_port);
+      } else {
+        Debug("log", "I am a collation client (%d)."
+              " My collation host is %s:%d", collation_mode, collation_host, collation_port);
+      }
+
+#ifdef IOCORE_LOG_COLLATION
+      Debug("log", "using iocore log collation");
+#else
+      Debug("log", "using socket log collation");
+#endif
+      if (collation_host_tagged) {
+        LogFormat::turn_tagging_on();
+      } else {
+        LogFormat::turn_tagging_off();
+      }
+    }
+  }
+}
+
 /*-------------------------------------------------------------------------
   LogConfig::init
   -------------------------------------------------------------------------*/
@@ -891,6 +962,56 @@ LogConfig::add_filters_to_search_log_obj
 #define MAXHOSTNAMELEN 256
 #endif
 
+void
+LogConfig::create_pre_defined_objects_with_filter(const PreDefinedFormatInfoList & pre_def_info_list, size_t num_filters,
+                                                  LogFilter ** filter, const char *filt_name, bool force_extension)
+{
+  PreDefinedFormatInfo *pdi;
+
+  for (pdi = pre_def_info_list.head; pdi != NULL; pdi = (pdi->link).next) {
+    char *obj_fname;
+    char obj_filt_fname[PATH_MAX];
+    if (filt_name) {
+      ink_string_concatenate_strings_n(obj_filt_fname, PATH_MAX, pdi->filename, "-", filt_name, NULL);
+      obj_fname = obj_filt_fname;
+    } else {
+      obj_fname = pdi->filename;
+    }
+
+    if (force_extension) {
+      ink_string_append(obj_filt_fname,
+                        (char *) (pdi->is_ascii ?
+                                  ASCII_LOG_OBJECT_FILENAME_EXTENSION :
+                                  BINARY_LOG_OBJECT_FILENAME_EXTENSION), PATH_MAX);
+    }
+    // create object with filters
+    //
+    LogObject *obj;
+    obj = NEW(new LogObject(pdi->format, logfile_dir, obj_fname,
+                            pdi->is_ascii ? ASCII_LOG : BINARY_LOG,
+                            pdi->header, rolling_enabled, rolling_interval_sec, rolling_offset_hr, rolling_size_mb));
+
+    if (collation_mode == SEND_STD_FMTS || collation_mode == SEND_STD_AND_NON_XML_CUSTOM_FMTS) {
+
+      LogHost *loghost = NEW(new LogHost(obj->get_full_filename(),
+                                         obj->get_signature()));
+      ink_assert(loghost != NULL);
+
+      loghost->set_name_port(collation_host, collation_port);
+      obj->add_loghost(loghost, false);
+    }
+
+    for (size_t i = 0; i < num_filters; ++i) {
+      obj->add_filter(filter[i]);
+    }
+
+    // give object to object manager
+    //
+    log_object_manager.manage_object(obj);
+  }
+}
+
+
 //-----------------------------------------------------------------------------
 // split_by_protocol
 //

Modified: trafficserver/traffic/trunk/proxy/logging/LogField.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogField.cc?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogField.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogField.cc Thu Sep  8 10:26:00 2011
@@ -314,6 +314,21 @@ LogField::display(FILE *fd)
 }
 
 /*-------------------------------------------------------------------------
+  LogField::operator==
+
+  This operator does only care of the name and m_symbol, may need
+  do check on others layter.
+  -------------------------------------------------------------------------*/
+bool
+LogField::operator==(LogField & rhs) {
+  if (strcmp(name(), rhs.name()) || strcmp(symbol(), rhs.symbol())) {
+    return false;
+  } else {
+    return true;
+  }
+}
+
+/*-------------------------------------------------------------------------
   -------------------------------------------------------------------------*/
 void
 LogField::set_aggregate_op(LogField::Aggregate agg_op)

Modified: trafficserver/traffic/trunk/proxy/logging/LogField.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogField.h?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogField.h (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogField.h Thu Sep  8 10:26:00 2011
@@ -100,6 +100,7 @@ public:
   unsigned marshal_agg(char *buf);
   unsigned unmarshal(char **buf, char *dest, int len);
   void display(FILE * fd = stdout);
+  bool operator==(LogField & rhs);
 
   char *name()
   {

Modified: trafficserver/traffic/trunk/proxy/logging/LogFile.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogFile.cc?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogFile.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogFile.cc Thu Sep  8 10:26:00 2011
@@ -96,17 +96,6 @@ LogFile::LogFile(const char *name, const
     m_max_line_size(max_line_size),
     m_overspill_report_count(overspill_report_count)
 {
-  init();
-  m_ascii_buffer_size = (ascii_buffer_size < max_line_size ? max_line_size : ascii_buffer_size);
-  m_ascii_buffer = NEW(new char[m_ascii_buffer_size]);
-  m_overspill_buffer = NEW(new char[m_max_line_size]);
-
-  Debug("log-file", "exiting LogFile constructor, m_name=%s, this=%p", m_name, this);
-}
-
-void
-LogFile::init()
-{
   delete m_meta_info;
   m_meta_info = NULL;
   m_overspill_bytes = 0;
@@ -117,12 +106,44 @@ LogFile::init()
   m_end_time = 0L;
   m_bytes_written = 0;
   m_size_bytes = 0;
-  m_has_size_limit = false;
-  m_size_limit_bytes = 0;
-  m_filesystem_checks_done = false;
+  m_ascii_buffer_size = (ascii_buffer_size < max_line_size ? max_line_size : ascii_buffer_size);
+  m_ascii_buffer = NEW(new char[m_ascii_buffer_size]);
+  m_overspill_buffer = NEW(new char[m_max_line_size]);
+
+  Debug("log-file", "exiting LogFile constructor, m_name=%s, this=%p", m_name, this);
 }
 
 /*-------------------------------------------------------------------------
+  LogFile::LogFile
+
+  This (copy) contructor builds a LogFile object from another LogFile object.
+  -------------------------------------------------------------------------*/
+
+LogFile::LogFile (const LogFile& copy)
+  : m_file_format (copy.m_file_format),
+    m_name  (ats_strdup (copy.m_name)),
+    m_header  (ats_strdup (copy.m_header)),
+    m_signature (copy.m_signature),
+    m_meta_info (NULL),
+    m_ascii_buffer_size (copy.m_ascii_buffer_size),
+    m_max_line_size (copy.m_max_line_size),
+    m_overspill_bytes (0),
+    m_overspill_written (0),
+    m_attempts_to_write_overspill (0),
+    m_overspill_report_count (copy.m_overspill_report_count),
+    m_fd (-1),
+    m_start_time (0L),
+    m_end_time (0L),
+    m_bytes_written (0)
+{
+    ink_debug_assert(m_ascii_buffer_size >= m_max_line_size);
+    m_ascii_buffer = NEW (new char[m_ascii_buffer_size]);
+    m_overspill_buffer = NEW (new char[m_max_line_size]);
+
+    Debug("log-file", "exiting LogFile copy constructor, m_name=%s, this=%p",
+          m_name, this);
+}
+/*-------------------------------------------------------------------------
   LogFile::~LogFile
   -------------------------------------------------------------------------*/
 
@@ -297,7 +318,6 @@ LogFile::close_file()
     // are running) and these won't be visible in Traffic Manager
     LOG_SUM_GLOBAL_DYN_STAT(log_stat_log_files_open_stat, -1);
   }
-  m_filesystem_checks_done = false;
 }
 
 /*-------------------------------------------------------------------------
@@ -456,6 +476,7 @@ LogFile::roll(long interval_start, long 
   // reset m_start_time
   //
   m_start_time = 0;
+  m_bytes_written = 0;
 
   Status("The logfile %s was rolled to %s.", m_name, roll_name);
 
@@ -468,16 +489,16 @@ LogFile::roll(long interval_start, long 
   Write the given LogBuffer data onto this file
   -------------------------------------------------------------------------*/
 int
-LogFile::write(LogBuffer * lb, size_t * to_disk, size_t * to_net, size_t * to_pipe)
+LogFile::write(LogBuffer * lb)
 {
-  NOWARN_UNUSED(to_net);
   if (lb == NULL) {
     Note("Cannot write LogBuffer to LogFile %s; LogBuffer is NULL", m_name);
     return -1;
   }
   LogBufferHeader *buffer_header = lb->header();
   if (buffer_header == NULL) {
-    Note("Cannot write LogBuffer to LogFile %s; LogBufferHeader is NULL", m_name);
+    Note("Cannot write LogBuffer to LogFile %s; LogBufferHeader is NULL",
+        m_name);
     return -1;
   }
   if (buffer_header->entry_count == 0) {
@@ -485,13 +506,7 @@ LogFile::write(LogBuffer * lb, size_t * 
     Note("LogBuffer with 0 entries for LogFile %s, nothing to write", m_name);
     return 0;
   }
-  // check if size limit has been exceeded and roll file if that is the case
 
-  if (size_limit_exceeded()) {
-    Warning("File %s will be rolled because its size is close to "
-            "or exceeds the operating system filesize limit", get_name());
-    roll(0, LogUtils::timestamp());
-  }
   // make sure we're open & ready to write
 
   check_fd();
@@ -509,30 +524,19 @@ LogFile::write(LogBuffer * lb, size_t * 
     // don't change between buffers), it's not worth trying to separate
     // out the buffer-dependent data from the buffer-independent data.
     //
-    if (!Log::config->logging_space_exhausted) {
-      bytes = writeln((char *) buffer_header, buffer_header->byte_count, m_fd, m_name);
-      if (bytes > 0 && to_disk) {
-        *to_disk += bytes;
-      }
-    }
-  } else if (m_file_format == ASCII_LOG) {
-    bytes = write_ascii_logbuffer3(buffer_header);
-    if (bytes > 0 && to_disk) {
-      *to_disk += bytes;
-    }
-#if defined(LOG_BUFFER_TRACKING)
-    Debug("log-buftrak", "[%d]LogFile::write - ascii write complete", buffer_header->id);
-#endif // defined(LOG_BUFFER_TRACKING)
-  } else if (m_file_format == ASCII_PIPE) {
+    bytes = buffer_header->byte_count;
+    writeln((char*) buffer_header, bytes, m_fd, m_name);
+  }
+  else if (m_file_format == ASCII_LOG || m_file_format == ASCII_PIPE) {
     bytes = write_ascii_logbuffer3(buffer_header);
-    if (bytes > 0 && to_pipe) {
-      *to_pipe += bytes;
-    }
 #if defined(LOG_BUFFER_TRACKING)
-    Debug("log-buftrak", "[%d]LogFile::write - ascii pipe write complete", buffer_header->id);
+    Debug("log-buftrak", "[%d]LogFile::write - ascii write complete",
+        buffer_header->id);
 #endif // defined(LOG_BUFFER_TRACKING)
-  } else {
-    Error("Cannot write LogBuffer to LogFile %s; invalid file format: %d", m_name, m_file_format);
+  }
+  else {
+    Note("Cannot write LogBuffer to LogFile %s; invalid file format: %d",
+        m_name, m_file_format);
     return -1;
   }
 
@@ -545,14 +549,7 @@ LogFile::write(LogBuffer * lb, size_t * 
   if (!m_start_time)
     m_start_time = buffer_header->low_timestamp;
   m_end_time = buffer_header->high_timestamp;
-
-  // update bytes written and file size (if not a pipe)
-  //
   m_bytes_written += bytes;
-  if (m_file_format != ASCII_PIPE) {
-    m_size_bytes += bytes;
-  }
-
   return bytes;
 }
 
@@ -830,36 +827,6 @@ LogFile::display(FILE * fd)
   fprintf(fd, "Logfile: %s, %s\n", get_name(), (is_open())? "file is open" : "file is not open");
 }
 
-int
-LogFile::do_filesystem_checks()
-{
-  int ret_val = 0;
-
-  int e = LogUtils::file_is_writeable(m_name, &m_size_bytes,
-                                      &m_has_size_limit,
-                                      &m_size_limit_bytes);
-
-  if (e == 1) {
-    Error("Log file %s is not a regular file or pipe", m_name);
-    ret_val = -1;
-  } else if (e == -1) {
-    Error("Filesystem checks for log file %s failed: %s", m_name, strerror(errno));
-    ret_val = -1;
-  } else if (m_has_size_limit) {
-    uint64_t safe_threshold =
-      (m_file_format == ASCII_PIPE ? 0 : Log::config->log_buffer_size * FILESIZE_SAFE_THRESHOLD_FACTOR);
-    if (safe_threshold > m_size_limit_bytes) {
-      Error("Filesize limit is too low for log file %s", m_name);
-      ret_val = -1;
-    } else {
-      m_size_limit_bytes = m_size_limit_bytes - safe_threshold;
-    }
-  }
-
-  m_filesystem_checks_done = true;
-  return ret_val;
-}
-
 /***************************************************************************
  LogFileList IS NOT USED
 ****************************************************************************/

Modified: trafficserver/traffic/trunk/proxy/logging/LogFile.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogFile.h?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogFile.h (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogFile.h Thu Sep  8 10:26:00 2011
@@ -124,8 +124,6 @@ public:
 
 class LogFile:public LogBufferSink
 {
-private:
-  LogFile(const LogFile &);
 public:
   LogFile(const char *name, const char *header, LogFileFormat format, uint64_t signature,
 #ifndef TS_MICRO
@@ -134,7 +132,7 @@ public:
           size_t ascii_buffer_size = 1024, size_t max_line_size = 1024,
 #endif
           size_t overspill_report_count = 1000);
-
+  LogFile(const LogFile &);
   ~LogFile();
 
   enum
@@ -147,7 +145,7 @@ public:
     LOG_FILE_FILESYSTEM_CHECKS_FAILED
   };
 
-  int write(LogBuffer * lb, size_t * to_disk = 0, size_t * to_net = 0, size_t * to_pipe = 0);
+  int write(LogBuffer * lb);
   int roll(long interval_start, long interval_end);
 
   char *get_name() const { return m_name; }
@@ -168,19 +166,10 @@ public:
   void display(FILE * fd = stdout);
   int open_file();
 
-  bool size_limit_exceeded() {
-    if (!m_filesystem_checks_done) {
-      do_filesystem_checks();
-    }
-    return (m_has_size_limit ? (uint64_t) m_size_bytes > m_size_limit_bytes : false);
-  }
-
-  int do_filesystem_checks();
-
-  off_t get_size_bytes() const { return m_size_bytes; };
+  off_t get_size_bytes() const { return m_file_format != ASCII_PIPE? m_bytes_written : 0; };
+  int do_filesystem_checks() { return 0; }; // TODO: this need to be tidy up when to redo the file checking
 
 private:
-  void init();
   bool is_open()
   {
     return (m_fd >= 0);
@@ -218,9 +207,6 @@ private:
   long m_end_time;
   uint64_t m_bytes_written;
   off_t m_size_bytes;           // current size of file in bytes
-  bool m_has_size_limit;        // true if file has a size limit
-  uint64_t m_size_limit_bytes;    // maximum file size in bytes
-  bool m_filesystem_checks_done;        // file system checks have been done
 
 public:
   Link<LogFile> link;

Modified: trafficserver/traffic/trunk/proxy/logging/LogFilter.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogFilter.cc?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogFilter.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogFilter.cc Thu Sep  8 10:26:00 2011
@@ -166,10 +166,13 @@ bool
 LogFilterString::operator==(LogFilterString & rhs)
 {
   if (m_type == rhs.m_type &&
-      m_field == rhs.m_field &&
-      m_action == rhs.m_action && m_operator == rhs.m_operator && m_num_values == rhs.m_num_values) {
+      *m_field == *rhs.m_field &&
+      m_action == rhs.m_action &&
+      m_operator == rhs.m_operator &&
+      m_num_values == rhs.m_num_values) {
     for (size_t i = 0; i < m_num_values; i++) {
-      if (m_length[i] != rhs.m_length[i] || strncmp(m_value[i], rhs.m_value[i], m_length[i])) {
+      if (m_length[i] != rhs.m_length[i] ||
+          strncmp(m_value[i], rhs.m_value[i], m_length[i])) {
         return false;
       }
     }
@@ -420,8 +423,10 @@ LogFilterInt::~LogFilterInt()
 bool LogFilterInt::operator==(LogFilterInt & rhs)
 {
   if (m_type == rhs.m_type &&
-      m_field == rhs.m_field &&
-      m_action == rhs.m_action && m_operator == rhs.m_operator && m_num_values == rhs.m_num_values) {
+      * m_field == * rhs.m_field &&
+      m_action == rhs.m_action &&
+      m_operator == rhs.m_operator &&
+      m_num_values == rhs.m_num_values) {
     for (size_t i = 0; i < m_num_values; i++) {
       if (m_value[i] != rhs.m_value[i]) {
         return false;
@@ -517,14 +522,18 @@ filters_are_equal(LogFilter * filt1, Log
 {
   bool ret = false;
 
+  // TODO: we should check name here
   if (filt1->type() == filt2->type()) {
     if (filt1->type() == LogFilter::INT_FILTER) {
+      Debug("log-filter-compare", "int compare");
       ret = (*((LogFilterInt *) filt1) == *((LogFilterInt *) filt2));
     } else if (filt1->type() == LogFilter::STRING_FILTER) {
       ret = (*((LogFilterString *) filt1) == *((LogFilterString *) filt2));
     } else {
       ink_debug_assert(!"invalid filter type");
     }
+  } else {
+    Debug("log-filter-compare", "type diff");
   }
   return ret;
 }
@@ -560,7 +569,6 @@ bool LogFilterList::operator==(LogFilter
       f = first();
     LogFilter *
       rhsf = rhs.first();
-
     while (true) {
       if (!(f || rhsf)) {
         return true;

Modified: trafficserver/traffic/trunk/proxy/logging/LogHost.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogHost.cc?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogHost.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogHost.cc Thu Sep  8 10:26:00 2011
@@ -251,22 +251,110 @@ LogHost::create_orphan_LogFile_object()
   ats_free(name_buf);
 }
 
+int
+LogHost::write (LogBuffer *lb)
+{
+  if (lb == NULL) {
+    Note("Cannot write LogBuffer to LogHost %s; LogBuffer is NULL", name());
+    return -1;
+  }
+  LogBufferHeader *buffer_header = lb->header();
+  if (buffer_header == NULL) {
+    Note("Cannot write LogBuffer to LogHost %s; LogBufferHeader is NULL",
+        name());
+    return -1;
+  }
+  if (buffer_header->entry_count == 0) {
+    // no bytes to write
+    return 0;
+  }
+
+#if !defined(IOCORE_LOG_COLLATION)
+
+  // make sure we're connected & authenticated
+
+  if (!connected(NOPING)) {
+    if (!connect ()) {
+      Note("Cannot write LogBuffer to LogHost %s; not connected",
+          name());
+      return orphan_write (lb);
+    }
+  }
+
+  // try sending the logbuffer
+
+  int bytes_to_send, bytes_sent;
+  bytes_to_send = buffer_header->byte_count;
+  lb->convert_to_network_order ();
+  bytes_sent = m_sock->write (m_sock_fd, buffer_header, bytes_to_send);
+  if (bytes_to_send != bytes_sent) {
+    Note("Bad write to LogHost %s; bad send count %d/%d",
+        name(), bytes_sent, bytes_to_send);
+    disconnect();
+    lb->convert_to_host_order ();
+    return orphan_write (lb);
+  }
+
+  Debug("log-host","%d bytes sent to LogHost %s:%u", bytes_sent,
+      name(), port());
+  SUM_DYN_STAT (log_stat_bytes_sent_to_network_stat, bytes_sent);
+  return bytes_sent;
+
+#else // !defined(IOCORE_LOG_COLLATION)
+  // make a copy of our log_buffer
+  int buffer_header_size = buffer_header->byte_count;
+  LogBufferHeader *buffer_header_copy =
+      (LogBufferHeader*) NEW(new char[buffer_header_size]);
+  ink_assert(buffer_header_copy != NULL);
+
+  memcpy(buffer_header_copy, buffer_header, buffer_header_size);
+  LogBuffer *lb_copy = NEW(new LogBuffer(lb->get_owner(),
+          buffer_header_copy));
+  ink_assert(lb_copy != NULL);
+
+  // create a new collation client if necessary
+  if (m_log_collation_client_sm == NULL) {
+    m_log_collation_client_sm = NEW(new LogCollationClientSM(this));
+    ink_assert(m_log_collation_client_sm != NULL);
+  }
+
+  // send log_buffer; orphan if necessary
+  int bytes_sent = m_log_collation_client_sm->send(lb_copy);
+  if (bytes_sent <= 0) {
+#ifndef TS_MICRO
+    orphan_write_and_delete(lb_copy);
+#if defined(LOG_BUFFER_TRACKING)
+    Debug("log-buftrak", "[%d]LogHost::write - orphan write complete",
+        lb_copy->header()->id);
+#endif // defined(LOG_BUFFER_TRACKING)
+#else
+    Note("Starting dropping log buffer due to overloading");
+    delete lb_copy;
+    lb_copy = 0;
+#endif // TS_MICRO
+  }
+
+  return bytes_sent;
+
+#endif // !defined(IOCORE_LOG_COLLATION)
+}
+
 #ifndef TS_MICRO
 int
-LogHost::orphan_write(LogBuffer * lb, size_t * to_file)
+LogHost::orphan_write(LogBuffer * lb)
 {
   if (!Log::config->logging_space_exhausted) {
     Debug("log-host", "Sending LogBuffer to orphan file %s", m_orphan_file->get_name());
-    return m_orphan_file->write(lb, to_file);
+    return m_orphan_file->write(lb);
   } else {
     return 0;                   // nothing written
   }
 }
 
 int
-LogHost::orphan_write_and_delete(LogBuffer * lb, size_t * to_disk)
+LogHost::orphan_write_and_delete(LogBuffer * lb)
 {
-  int bytes = orphan_write(lb, to_disk);
+  int bytes = orphan_write(lb);
   // done with the buffer, delete it
   delete lb;
   lb = 0;
@@ -369,11 +457,11 @@ LogHostList::clear()
 }
 
 int
-LogHostList::write(LogBuffer * lb, size_t * to_disk, size_t * to_net, size_t * to_pipe)
+LogHostList::write(LogBuffer * lb)
 {
   int total_bytes = 0;
   for (LogHost * host = first(); host; host = next(host)) {
-    int bytes = host->write(lb, to_disk, to_net, to_pipe);
+    int bytes = host->write(lb);
     if (bytes > 0)
       total_bytes += bytes;
   }

Modified: trafficserver/traffic/trunk/proxy/logging/LogHost.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogHost.h?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogHost.h (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogHost.h Thu Sep  8 10:26:00 2011
@@ -52,7 +52,7 @@ public:
   bool connected(bool ping);
   bool connect();
   void disconnect();
-  int write(LogBuffer * lb, size_t * to_disk, size_t * to_net, size_t * to_pipe);
+  int write(LogBuffer * lb);
 
   char *name() const { return (char *) ((m_name) ? m_name : "UNKNOWN"); }
   unsigned port() const { return m_port; }
@@ -68,8 +68,8 @@ public:
 private:
   void clear();
   bool authenticated();
-  int orphan_write(LogBuffer * lb, size_t * to_disk = 0);
-  int orphan_write_and_delete(LogBuffer * lb, size_t * to_disk = 0);
+  int orphan_write(LogBuffer * lb);
+  int orphan_write_and_delete(LogBuffer * lb);
   void create_orphan_LogFile_object();
 
 private:
@@ -108,7 +108,7 @@ public:
   void add(LogHost * host, bool copy = true);
   unsigned count();
   void clear();
-  int write(LogBuffer * lb, size_t * to_disk = 0, size_t * to_net = 0, size_t * to_pipe = 0);
+  int write(LogBuffer * lb);
 
   LogHost *first() { return m_host_list.head; }
   LogHost *next(LogHost * here) { return (here->link).next; }

Modified: trafficserver/traffic/trunk/proxy/logging/LogObject.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogObject.cc?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogObject.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogObject.cc Thu Sep  8 10:26:00 2011
@@ -46,129 +46,152 @@ LogBufferManager::~LogBufferManager()
     delete _delay_delete_array[i];
     _delay_delete_array[i] = 0;
   }
-  ink_mutex_acquire(&_flush_array_mutex);
-  ink_mutex_release(&_flush_array_mutex);
-  ink_mutex_destroy(&_flush_array_mutex);
 }
 
 
 size_t
-LogBufferManager::flush_buffers(LogBufferSink * sink, size_t * to_disk, size_t * to_net, size_t * to_pipe)
+LogBufferManager::flush_buffers(LogBufferSink *sink)
 {
-  LogBuffer *flush_buffer, *wlist;
-  size_t total_bytes_flushed = 0;
+  while (!ink_atomic_cas(&_flush_array_lock, 0, 1));
 
-  if ((wlist = get_flush_queue()) != 0) {
-    int delcnt = 0;
+  int ofa = _open_flush_array;
+  int nfb = _num_flush_buffers[ofa];
+  if (nfb) {
+    _open_flush_array = !_open_flush_array;        // switch to other array
+    _num_flush_buffers[_open_flush_array] = 0;     // clear count
+  }
+
+  _flush_array_lock = 0;
 
-    while ((flush_buffer = wlist) != 0) {
-      wlist = flush_buffer->next_flush;
+  if (nfb) {
+    int i;
+    int btd = nfb > DELAY_DELETE_SIZE ? nfb - DELAY_DELETE_SIZE : 0;
+
+    for (i=0 ;i < nfb; ++i) {
+      LogBuffer *flush_buffer = _flush_array[ofa][i];
       flush_buffer->update_header_data();
-      int bytes_flushed = sink->write(flush_buffer, to_disk, to_net, to_pipe);
-      if (bytes_flushed > 0)
-        total_bytes_flushed += bytes_flushed;
-      delete _delay_delete_array[_head];
-      _delay_delete_array[_head++] = flush_buffer;
-      _head = _head % DELAY_DELETE_SIZE;
-      delcnt++;
-    }
-    Debug("log-logbuffer", "flushed %d buffers: %lu bytes", delcnt, (unsigned long) total_bytes_flushed);
+
+      sink->write(flush_buffer);
+
+      if (i < btd) {
+        delete flush_buffer;
+      } else {
+        delete _delay_delete_array[_head];
+        _delay_delete_array[_head] = flush_buffer;
+        ++_head;
+        _head = _head % DELAY_DELETE_SIZE;
+       }
+     }
+
+    Debug("log-logbuffer", "flushed %d buffers from array %d",
+          nfb, ofa);
   }
-  return total_bytes_flushed;
-}
 
+  return nfb;
+}
 
 /*-------------------------------------------------------------------------
   LogObject
   -------------------------------------------------------------------------*/
-LogObject::LogObject(LogFormat * format, const char *log_dir,
-                     const char *basename, LogFileFormat file_format,
-                     const char *header, int rolling_enabled,
-                     int rolling_interval_sec, int rolling_offset_hr, int rolling_size_mb)
-  : m_alt_filename(NULL),
-    m_flags(0),
-    m_signature(0),
-    m_ref_count(0),
-    m_log_buffer(NULL)
-{
-  init(format, log_dir, basename, file_format, header, rolling_enabled, rolling_interval_sec,
-       rolling_offset_hr, rolling_size_mb);
-}
 
+LogObject::LogObject(LogFormat *format, const char *log_dir,
+                      const char *basename, LogFileFormat file_format,
+                      const char *header, int rolling_enabled,
+                      int rolling_interval_sec, int rolling_offset_hr, int rolling_size_mb):
+      m_alt_filename (NULL),
+      m_flags (0),
+      m_signature (0),
+      m_rolling_interval_sec (rolling_interval_sec),
+      m_rolling_offset_hr (rolling_offset_hr),
+      m_rolling_size_mb (rolling_size_mb),
+      m_ref_count (0),
+      m_log_buffer (NULL)
+{
+    ink_debug_assert (format != NULL);
+    m_format = new LogFormat(*format);
+
+    if (file_format == BINARY_LOG) {
+        m_flags |= BINARY;
+    } else if (file_format == ASCII_PIPE) {
+#ifdef ASCII_PIPE_FORMAT_SUPPORTED
+        m_flags |= WRITES_TO_PIPE;
+#else
+        // ASCII_PIPE not supported, reset to ASCII_LOG
+        Warning("ASCII_PIPE Mode not supported, resetting Mode to ASCII_LOG "
+                "for LogObject %s", basename);
+        file_format = ASCII_LOG;
+#endif
+    }
 
-LogObject::LogObject(LogFormat format, const char *log_dir,
-                     const char *basename, LogFileFormat file_format,
-                     const char *header, int rolling_enabled,
-                     int rolling_interval_sec, int rolling_offset_hr, int rolling_size_mb)
-  : m_alt_filename(NULL),
-    m_flags(0),
-    m_signature(0),
-    m_ref_count(0),
-    m_log_buffer(NULL)
-{
-  init(&format, log_dir, basename, file_format, header, rolling_enabled, rolling_interval_sec,
-       rolling_offset_hr, rolling_size_mb);
-}
+    generate_filenames(log_dir, basename, file_format);
 
+    // compute_signature is a static function
+    m_signature = compute_signature(m_format, m_basename, m_flags);
 
-void
-LogObject::init(LogFormat * format, const char *log_dir,
-                     const char *basename, LogFileFormat file_format,
-                     const char *header, int rolling_enabled,
-                     int rolling_interval_sec, int rolling_offset_hr, int rolling_size_mb)
-{
-  LogBuffer *tmp_lb_array[(DELAY_DELETE_SIZE + (DELAY_DELETE_SIZE / 4))];
-  int i;
+#ifndef TS_MICRO
+    // by default, create a LogFile for this object, if a loghost is
+    // later specified, then we will delete the LogFile object
+    //
+    m_logFile = NEW(new LogFile (m_filename, header, file_format,
+                                 m_signature,
+                                 Log::config->ascii_buffer_size,
+                                 Log::config->max_line_size,
+                                 Log::config->overspill_report_count));
+#endif // TS_MICRO
 
-  ink_debug_assert(format != NULL);
-  m_format = new LogFormat(*format);
+    m_log_buffer = NEW (new LogBuffer (this, Log::config->log_buffer_size));
+    ink_debug_assert (m_log_buffer != NULL);
 
-  if (file_format == BINARY_LOG) {
-    m_flags |= BINARY;
-  } else if (file_format == ASCII_PIPE) {
-#ifdef ASCII_PIPE_FORMAT_SUPPORTED
-    m_flags |= WRITES_TO_PIPE;
-#else
-    // ASCII_PIPE not supported, reset to ASCII_LOG
-    Warning("ASCII_PIPE Mode not supported, resetting Mode to ASCII_LOG " "for LogObject %s", basename);
-    file_format = ASCII_LOG;
-#endif
-  }
+    _setup_rolling(rolling_enabled, rolling_interval_sec, rolling_offset_hr, rolling_size_mb);
 
-  generate_filenames(log_dir, basename, file_format);
+    Debug("log-config", "exiting LogObject constructor, filename=%s this=%p",
+          m_filename, this);
+}
 
-  // compute_signature is a static function
-  m_signature = compute_signature(m_format, m_basename, m_flags);
+LogObject::LogObject(LogObject& rhs)
+  : m_basename(ats_strdup(rhs.m_basename)),
+    m_filename(ats_strdup(rhs.m_filename)),
+    m_alt_filename(ats_strdup(rhs.m_alt_filename)),
+    m_flags(rhs.m_flags),
+    m_signature(rhs.m_signature),
+    m_rolling_interval_sec(rhs.m_rolling_interval_sec),
+    m_last_roll_time(rhs.m_last_roll_time),
+    m_ref_count(0),
+    m_log_buffer(NULL)
+{
+    m_format = new LogFormat(*(rhs.m_format));
 
 #ifndef TS_MICRO
-  // by default, create a LogFile for this object, if a loghost is
-  // later specified, then we will delete the LogFile object
-  //
-  m_logFile = NEW(new LogFile(m_filename, header, file_format,
-                              m_signature,
-                              Log::config->ascii_buffer_size,
-                              Log::config->max_line_size, Log::config->overspill_report_count));
-#endif // TS_MICRO
+    if (rhs.m_logFile) {
+        m_logFile = NEW (new LogFile(*(rhs.m_logFile)));
+    } else {
+#endif
+        m_logFile = NULL;
+#ifndef TS_MICRO
+    }
+#endif
 
-  m_log_buffer = NEW(new LogBuffer(this, Log::config->log_buffer_size));
-  ink_assert(m_log_buffer != NULL);
+    LogFilter *filter;
+    for (filter = rhs.m_filter_list.first(); filter;
+            filter = rhs.m_filter_list.next (filter)) {
+        add_filter (filter);
+    }
 
-  // preallocate LogBuffers in order to use cont memory
-  for (i = 0; i < (DELAY_DELETE_SIZE + (DELAY_DELETE_SIZE / 4)); i++) {
-    tmp_lb_array[i] = NEW(new LogBuffer(this, Log::config->log_buffer_size));
-    ink_assert(tmp_lb_array[i] != NULL);
-  }
-  for (i = 0; i < (DELAY_DELETE_SIZE + (DELAY_DELETE_SIZE / 4)); i++) {
-    delete tmp_lb_array[i];
-  }
+    LogHost *host;
+    for (host = rhs.m_host_list.first(); host;
+            host = rhs.m_host_list.next (host)) {
+        add_loghost (host);
+    }
 
-  _setup_rolling(rolling_enabled, rolling_interval_sec, rolling_offset_hr, rolling_size_mb);
-  m_last_roll_time = LogUtils::timestamp();
+    // copy gets a fresh log buffer
+    //
+    m_log_buffer = NEW (new LogBuffer (this, Log::config->log_buffer_size));
+    ink_debug_assert (m_log_buffer != NULL);
 
-  Debug("log-config", "exiting LogObject constructor, filename=%s this=%p", m_filename, this);
+    Debug("log-config", "exiting LogObject copy constructor, "
+          "filename=%s this=%p", m_filename, this);
 }
 
-
 LogObject::~LogObject()
 {
   Debug("log-config", "entering LogObject destructor, this=%p", this);
@@ -177,7 +200,7 @@ LogObject::~LogObject()
     Debug("log-config", "LogObject refcount = %d, waiting for zero", m_ref_count);
   }
 
-  flush_buffers(0, 0, 0);
+  flush_buffers();
 
   // here we need to free LogHost if it is remote logging.
   if (is_collation_client()) {
@@ -193,7 +216,6 @@ LogObject::~LogObject()
   delete m_log_buffer;
 }
 
-
 //-----------------------------------------------------------------------------
 //
 // This function generates an object filename according to the following rules:
@@ -210,9 +232,9 @@ void
 LogObject::generate_filenames(const char *log_dir, const char *basename, LogFileFormat file_format)
 {
   ink_debug_assert(log_dir && basename);
+
   int i = -1, len = 0;
   char c;
-
   while (c = basename[len], c != 0) {
     if (c == '.') {
       i = len;
@@ -225,7 +247,6 @@ LogObject::generate_filenames(const char
 
   const char *ext = 0;
   int ext_len = 0;
-
   if (i < 0) {                  // no extension, add one
     switch (file_format) {
     case ASCII_LOG:
@@ -266,6 +287,7 @@ LogObject::generate_filenames(const char
 }
 
 
+
 void
 LogObject::rename(char *new_name)
 {
@@ -422,28 +444,29 @@ LogObject::_checkout_write(size_t * writ
 
     case LogBuffer::LB_FULL_ACTIVE_WRITERS:
     case LogBuffer::LB_FULL_NO_WRITERS:
+      if (result_code == LogBuffer::LB_FULL_NO_WRITERS) {
+        // there are no writers, move the buffer to the flush list
+        //
+        Debug("log-logbuffer",
+              "adding buffer %d to flush list after checkout",
+              buffer->get_id());
+
+        m_buffer_manager.add_to_flush_queue(buffer);
+
+        ink_cond_signal (&Log::flush_cond);
+      }
 
       // no more room in current buffer, create a new one
       //
-      new_buffer = NEW(new LogBuffer(this, Log::config->log_buffer_size));
+      new_buffer =
+          NEW (new LogBuffer(this, Log::config->log_buffer_size));
 
       // swap the new buffer for the old one (only this thread
       // should be doing this, so there should be no problem)
       //
       INK_WRITE_MEMORY_BARRIER;
-      ink_atomic_swap_ptr((void *) &m_log_buffer, new_buffer);
-
-      if (result_code == LogBuffer::LB_FULL_NO_WRITERS) {
-        // there are no writers, move the buffer to the flush list
-        //
-        Debug("log-logbuffer", "adding buffer %d to flush list after checkout", buffer->get_id());
+      ink_atomic_swap_ptr((void *)&m_log_buffer, new_buffer);
 
-        m_buffer_manager.add_to_flush_queue(buffer);
-        ink_mutex_acquire(&Log::flush_mutex);
-        Log::flush_counter++;
-        ink_cond_signal(&Log::flush_cond);
-        ink_mutex_release(&Log::flush_mutex);
-      }
       // fallover to retry
 
     case LogBuffer::LB_RETRY:
@@ -588,10 +611,7 @@ LogObject::log(LogAccess * lad, char *te
     Debug("log-logbuffer", "adding buffer %d to flush list after checkin", buffer->get_id());
 
     m_buffer_manager.add_to_flush_queue(buffer);
-    ink_mutex_acquire(&Log::flush_mutex);
-    Log::flush_counter++;
-//      ink_cond_signal (&Log::flush_cond);
-    ink_mutex_release(&Log::flush_mutex);
+//    ink_cond_signal (&Log::flush_cond);
   }
 
   LOG_INCREMENT_DYN_STAT(log_stat_event_log_access_stat);
@@ -646,16 +666,18 @@ LogObject::_setup_rolling(int rolling_en
       }
 
       m_rolling_offset_hr = rolling_offset_hr;
+      m_rolling_size_mb = 0; // it is safe to set it as 0, if we set SIZE rolling,
+                             // it will be updated later
     }
 
     if (rolling_enabled == LogConfig::ROLL_ON_SIZE_ONLY ||
         rolling_enabled == LogConfig::ROLL_ON_TIME_OR_SIZE || rolling_enabled == LogConfig::ROLL_ON_TIME_AND_SIZE) {
-      if (rolling_size_mb <= 0) {
-        rolling_size_mb = 10;
-        Note("Rolling size invalid for %s, setting it to %d MB", m_filename, rolling_size_mb);
+      if (rolling_size_mb <= 10) {
+        m_rolling_size_mb = 10;
+        Note("Rolling size invalid(%d) for %s, setting it to 10 MB", rolling_size_mb, m_filename);
+      } else {
+        m_rolling_size_mb = rolling_size_mb;
       }
-
-      m_rolling_size_mb = rolling_size_mb;
     }
 
     m_rolling_enabled = rolling_enabled;
@@ -664,7 +686,7 @@ LogObject::_setup_rolling(int rolling_en
 
 
 int
-LogObject::roll_files_if_needed(long time_now)
+LogObject::roll_files(long time_now)
 {
   if (!m_rolling_enabled)
     return 0;
@@ -721,7 +743,7 @@ LogObject::roll_files_if_needed(long tim
       (roll_on_size && (m_rolling_enabled == LogConfig::ROLL_ON_SIZE_ONLY ||
                         m_rolling_enabled == LogConfig::ROLL_ON_TIME_OR_SIZE))
       || (roll_on_time && roll_on_size && m_rolling_enabled == LogConfig::ROLL_ON_TIME_AND_SIZE)) {
-    num_rolled = roll_files(time_now);
+    num_rolled = _roll_files(m_last_roll_time, time_now ? time_now : LogUtils::timestamp());
   }
 
   return num_rolled;
@@ -780,7 +802,7 @@ LogObject::do_filesystem_checks()
   -------------------------------------------------------------------------*/
 TextLogObject::TextLogObject(const char *name, const char *log_dir, bool timestamps, const char *header, int rolling_enabled,
                              int rolling_interval_sec, int rolling_offset_hr, int rolling_size_mb)
-  : LogObject(LogFormat(TEXT_LOG), log_dir, name, ASCII_LOG, header,
+  : LogObject(NEW(new LogFormat(TEXT_LOG)), log_dir, name, ASCII_LOG, header,
               rolling_enabled, rolling_interval_sec, rolling_offset_hr, rolling_size_mb), m_timestamps(timestamps)
 {
 }
@@ -1118,38 +1140,6 @@ LogObjectManager::_solve_internal_filena
 }
 
 
-int
-LogObjectManager::_roll_files(long time_now, bool roll_only_if_needed)
-{
-  int num_rolled = 0;
-  size_t i;
-
-  for (i = 0; i < _numObjects; i++) {
-    if (roll_only_if_needed) {
-      num_rolled += _objects[i]->roll_files_if_needed(time_now);
-    } else {
-      num_rolled += _objects[i]->roll_files(time_now);
-    }
-  }
-  // we don't care if we miss an object that may be added to the set of api
-  // objects just after we have read _numAPIobjects and found it to be zero;
-  // we will get a chance to roll this object next time
-  //
-  if (_numAPIobjects) {
-    ACQUIRE_API_MUTEX("A LogObjectManager::roll_files");
-    for (i = 0; i < _numAPIobjects; i++) {
-      if (roll_only_if_needed) {
-        num_rolled += _APIobjects[i]->roll_files_if_needed(time_now);
-      } else {
-        num_rolled += _APIobjects[i]->roll_files(time_now);
-      }
-    }
-    RELEASE_API_MUTEX("R LogObjectManager::roll_files");
-  }
-  return num_rolled;
-}
-
-
 LogObject *
 LogObjectManager::get_object_with_signature(uint64_t signature)
 {
@@ -1172,48 +1162,24 @@ LogObjectManager::check_buffer_expiratio
   for (i = 0; i < _numObjects; i++) {
     _objects[i]->check_buffer_expiration(time_now);
   }
-
-  // we don't care if we miss an object that may be added to the set of api
-  // objects just after we have read _numAPIobjects and found it to be zero;
-  // we will get a chance to check the buffer expiration next time
-  //
-  if (_numAPIobjects) {
-    ACQUIRE_API_MUTEX("A LogObjectManager::check_buffer_expiration");
-    for (i = 0; i < _numAPIobjects; i++) {
-      _APIobjects[i]->check_buffer_expiration(time_now);
-    }
-    RELEASE_API_MUTEX("R LogObjectManager::check_buffer_expiration");
+  for (i = 0; i < _numAPIobjects; i++) {
+    _APIobjects[i]->check_buffer_expiration(time_now);
   }
 }
 
-
-size_t
-LogObjectManager::flush_buffers(size_t * to_disk, size_t * to_net, size_t * to_pipe)
+size_t LogObjectManager::flush_buffers()
 {
   size_t i;
-  size_t bytes_flushed;
-  size_t total_bytes_flushed = 0;
+  size_t buffers_flushed = 0;
 
   for (i = 0; i < _numObjects; i++) {
-    LogObject *obj = _objects[i];
-
-    bytes_flushed = obj->flush_buffers(to_disk, to_net, to_pipe);
-    total_bytes_flushed += bytes_flushed;
+    buffers_flushed += _objects[i]->flush_buffers();
   }
 
-  // we don't care if we miss an object that may be added to the set of
-  // api objects just after we have read _numAPIobjects and found it to
-  // be zero; we will get a chance to flush the buffer next time
-  //
-  if (_numAPIobjects) {
-    ACQUIRE_API_MUTEX("A LogObjectManager::flush_buffers");
-    for (i = 0; i < _numAPIobjects; i++) {
-      bytes_flushed = _APIobjects[i]->flush_buffers(to_disk, to_net, to_pipe);
-      total_bytes_flushed += bytes_flushed;
-    }
-    RELEASE_API_MUTEX("R LogObjectManager::flush_buffers");
+  for (i = 0; i < _numAPIobjects; i++) {
+      buffers_flushed += _APIobjects[i]->flush_buffers();
   }
-  return total_bytes_flushed;
+  return buffers_flushed;
 }
 
 

Modified: trafficserver/traffic/trunk/proxy/logging/LogObject.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogObject.h?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogObject.h (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogObject.h Thu Sep  8 10:26:00 2011
@@ -69,46 +69,39 @@ Debug("log-api-mutex", _f)
 class LogBufferManager
 {
 private:
-  ink_mutex _flush_array_mutex; // synchronize access to flush_array
-  LogBuffer *_flush_list;
-  LogBuffer **_flush_list_last;
+  int _flush_array_lock;
+
+  LogBuffer *_flush_array[2][FLUSH_ARRAY_SIZE];
   LogBuffer *_delay_delete_array[DELAY_DELETE_SIZE];
-  int _head;                    // index of next buffer in deleted list
+
+  int _num_flush_buffers[2];          // number of buffers in queue
+  int _open_flush_array;              // index of queue accepting buffers
+  int _head;                          // index of next buffer to be deleted
 
 public:
  LogBufferManager()
-   : _flush_list(0), _head(0)
+   : _flush_array_lock(0), _open_flush_array(0), _head(0)
   {
-    _flush_list_last = &_flush_list;
-    for (int i = 0; i < DELAY_DELETE_SIZE; i++)
-      _delay_delete_array[i] = 0;
-    ink_mutex_init(&_flush_array_mutex, "_flush_array_mutex");
+    _num_flush_buffers[0] = 0;
+    _num_flush_buffers[1] = 0;
+    for (int i=0; i<DELAY_DELETE_SIZE; ++i) _delay_delete_array[i] = 0;
   }
 
   ~LogBufferManager();
 
   void add_to_flush_queue(LogBuffer * buffer)
   {
-    if (buffer && buffer->sign == CLASS_SIGN_LOGBUFFER) {
-      ink_mutex_acquire(&_flush_array_mutex);
-      (*_flush_list_last = buffer)->next_flush = 0;
-      _flush_list_last = &buffer->next_flush;
-      ink_mutex_release(&_flush_array_mutex);
-    }
-  }
+    while (!ink_atomic_cas(&_flush_array_lock, 0, 1));
 
-  LogBuffer *get_flush_queue(void)
-  {
-    LogBuffer *list;
-    ink_mutex_acquire(&_flush_array_mutex);
-    list = _flush_list;
-    _flush_list = 0;
-    _flush_list_last = &_flush_list;
-    ink_mutex_release(&_flush_array_mutex);
-    return list;
+    ink_release_assert(_num_flush_buffers[_open_flush_array] <
+                       FLUSH_ARRAY_SIZE);
+    int idx = _num_flush_buffers[_open_flush_array]++;
+    _flush_array[_open_flush_array][idx] = buffer;
+
+    _flush_array_lock = 0;
   }
 
-  size_t flush_buffers(LogBufferSink * sink, size_t * to_disk, size_t * to_net, size_t * to_pipe);
+  size_t flush_buffers(LogBufferSink *sink);
 };
 
 
@@ -128,18 +121,10 @@ public:
   // WRITES_TO_PIPE: object writes to a named pipe rather than to a file
 
   LogObject(LogFormat *format, const char *log_dir, const char *basename,
-            LogFileFormat file_format, const char *header,
-            int rolling_enabled, int rolling_interval_sec = 0, int rolling_offset_hr = 0, int rolling_size_mb = 0);
-  LogObject(LogFormat format, const char *log_dir, const char *basename,
-            LogFileFormat file_format, const char *header,
-            int rolling_enabled, int rolling_interval_sec = 0, int rolling_offset_hr = 0, int rolling_size_mb = 0);
-private:
-  void init(LogFormat * format, const char *log_dir, const char *basename,
-            LogFileFormat file_format, const char *header,
-            int rolling_enabled, int rolling_interval_sec = 0, int rolling_offset_hr = 0, int rolling_size_mb = 0);
+                 LogFileFormat file_format, const char *header,
+                 int rolling_enabled, int rolling_interval_sec = 0,
+                 int rolling_offset_hr = 0, int rolling_size_mb = 0);
   LogObject(LogObject &);
-
-public:
   virtual ~LogObject();
 
   void add_filter(LogFilter * filter, bool copy = true);
@@ -152,21 +137,24 @@ public:
   };
 
   int log(LogAccess * lad, char *text_entry = NULL);
-  int roll_files_if_needed(long time_now = 0);
 
-  int roll_files(long time_now = 0) {
-    return _roll_files(m_last_roll_time, time_now ? time_now : LogUtils::timestamp());
-  }
+  int roll_files(long time_now = 0);
 
   void add_to_flush_queue(LogBuffer * buffer)
   {
     m_buffer_manager.add_to_flush_queue(buffer);
   }
 
-  size_t flush_buffers(size_t * to_disk, size_t * to_net, size_t * to_pipe)
+  size_t flush_buffers()
   {
-    return (m_logFile) ? m_buffer_manager.flush_buffers(m_logFile, to_disk, to_net, to_pipe) :
-      m_buffer_manager.flush_buffers(&m_host_list, to_disk, to_net, to_pipe);
+    size_t nfb;
+
+    if (m_logFile) {
+      nfb = m_buffer_manager.flush_buffers(m_logFile);
+    } else {
+      nfb = m_buffer_manager.flush_buffers(&m_host_list);
+    }
+    return nfb;
   }
 
   void check_buffer_expiration(long time_now);
@@ -217,7 +205,7 @@ public:
     _setup_rolling(m_rolling_enabled, rolling_interval_sec, m_rolling_offset_hr, m_rolling_size_mb);
   }
 
-  void set_rolling_offset_hr(int rolling_offset_hr)
+ void set_rolling_offset_hr(int rolling_offset_hr)
   {
     _setup_rolling(m_rolling_enabled, m_rolling_interval_sec, rolling_offset_hr, m_rolling_size_mb);
   }
@@ -382,7 +370,7 @@ public:
 
 private:
 
-    LogObject ** _objects;      // array of objects managed
+  LogObject ** _objects;      // array of objects managed
   size_t _numObjects;           // the number of objects managed
   size_t _maxObjects;           // the maximum capacity of the array
   // of objects managed
@@ -453,19 +441,13 @@ public:
     return _numObjects;
   }
 
-  int roll_files(long time_now = 0) {
-    return _roll_files(time_now, false);
-  }
-
-  int roll_files_if_needed(long time_now = 0) {
-    return _roll_files(time_now, true);
-  }
+  int roll_files(long time_now);
 
   int log(LogAccess * lad);
   void display(FILE * str = stdout);
   void add_filter_to_all(LogFilter * filter);
   LogObject *find_by_format_name(const char *name);
-  size_t flush_buffers(size_t * to_disk, size_t * to_net = 0, size_t * to_pipe = 0);
+  size_t flush_buffers();
   void open_local_pipes();
   void transfer_objects(LogObjectManager & mgr);
 
@@ -476,6 +458,15 @@ public:
   size_t get_num_collation_clients();
 };
 
+inline int LogObjectManager::roll_files(long time_now)
+{
+    int num_rolled = 0;
+    for (size_t i=0; i < _numObjects; i++)
+    {
+        num_rolled += _objects[i]->roll_files(time_now);
+    }
+    return num_rolled;
+};
 
 inline int
 LogObjectManager::log(LogAccess * lad)

Modified: trafficserver/traffic/trunk/proxy/logging/Makefile.am
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/Makefile.am?rev=1166608&r1=1166607&r2=1166608&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/Makefile.am (original)
+++ trafficserver/traffic/trunk/proxy/logging/Makefile.am Thu Sep  8 10:26:00 2011
@@ -70,7 +70,6 @@ liblogging_a_SOURCES = \
   LogUtils.h
 
 liblogcollation_a_SOURCES = \
-  LogConfigCollation.cc \
   LogCollationAccept.cc \
   LogCollationAccept.h \
   LogCollationBase.h \



Mime
View raw message