From: Xiubo Li Date: Wed, 30 Oct 2019 08:13:07 +0000 (+0530) Subject: log: just return if t is empty X-Git-Tag: v15.1.0~777^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=571671501bc1430bdb44f4485d4b53160b3a212a;p=ceph-ci.git log: just return if t is empty 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 --- diff --git a/src/log/Log.cc b/src/log/Log.cc index 9ecde2887ea..10cc60bda1a 100644 --- a/src/log/Log.cc +++ b/src/log/Log.cc @@ -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]; diff --git a/src/log/Log.h b/src/log/Log.h index a0b12e27432..9c7f53425b6 100644 --- a/src/log/Log.h +++ b/src/log/Log.h @@ -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);