]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
log: just return if t is empty
authorXiubo Li <xiubli@redhat.com>
Wed, 30 Oct 2019 08:13:07 +0000 (13:43 +0530)
committerXiubo Li <xiubli@redhat.com>
Mon, 18 Nov 2019 00:34:00 +0000 (19:34 -0500)
When the t is empty, there is no need to do the followed t.clear
or the m_log_buf flush. Because the m_log_buf will be fed by _flush()
only when t is not empty and then immediately it will be flushed to
log files and emptied just before returned from _flush().

In other word, m_log_buf just a buffer for the log messages in _flush()
before flushing them to log files.

This will also remove the 'requeue' pararmeter since in all the cases
we should requeue the new entry.

Signed-off-by: Xiubo Li <xiubli@redhat.com>
src/log/Log.cc
src/log/Log.h

index 9ecde2887ea39cf50f2c401faaae7cc1591d0e63..10cc60bda1ac6e57dd6325808be37fc00a929691 100644 (file)
@@ -209,7 +209,7 @@ void Log::flush()
     m_queue_mutex_holder = 0;
   }
 
-  _flush(m_flush, true, false);
+  _flush(m_flush, false);
   m_flush_mutex_holder = 0;
 }
 
@@ -235,15 +235,16 @@ void Log::_flush_logbuf()
   }
 }
 
-void Log::_flush(EntryVector& t, bool requeue, bool crash)
+void Log::_flush(EntryVector& t, bool crash)
 {
   long len = 0;
+  if (t.empty()) {
+    assert(m_log_buf.empty());
+    return;
+  }
   if (crash) {
     len = t.size();
   }
-  if (!requeue && t.empty()) {
-    return;
-  }
   for (auto& e : t) {
     auto prio = e.m_prio;
     auto stamp = e.m_stamp;
@@ -302,9 +303,7 @@ void Log::_flush(EntryVector& t, bool requeue, bool crash)
       m_graylog->log_entry(e);
     }
 
-    if (requeue) {
-      m_recent.push_back(std::move(e));
-    }
+    m_recent.push_back(std::move(e));
   }
   t.clear();
 
@@ -345,7 +344,7 @@ void Log::dump_recent()
     m_queue_mutex_holder = 0;
   }
 
-  _flush(m_flush, true, false);
+  _flush(m_flush, false);
   _flush_logbuf();
 
   _log_message("--- begin dump of recent events ---", true);
@@ -353,7 +352,7 @@ void Log::dump_recent()
     EntryVector t;
     t.insert(t.end(), std::make_move_iterator(m_recent.begin()), std::make_move_iterator(m_recent.end()));
     m_recent.clear();
-    _flush(t, true, true);
+    _flush(t, true);
   }
 
   char buf[4096];
index a0b12e274323172cc4b7eeacb8ade39df05f4d0e..9c7f53425b650badbf63298da195a7f1d29536d2 100644 (file)
@@ -77,7 +77,7 @@ class Log : private Thread
 
   void _log_safe_write(std::string_view sv);
   void _flush_logbuf();
-  void _flush(EntryVector& q, bool requeue, bool crash);
+  void _flush(EntryVector& q, bool crash);
 
   void _log_message(const char *s, bool crash);