From e7887a3293bc2e3dbde9ab4f92b15d4039ecd6ee Mon Sep 17 00:00:00 2001 From: John Spray Date: Thu, 1 Nov 2018 19:45:34 -0400 Subject: [PATCH] mon: fix 'log last' missing out latest event The loop was iterating up to but not including the rbegin() entry. Also remove a spurious derr << "bar" Fixes: http://tracker.ceph.com/issues/36679 Signed-off-by: John Spray --- src/mon/LogMonitor.cc | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index 85a982ba50ea..2ccef7d76f5f 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -446,6 +446,7 @@ bool LogMonitor::preprocess_command(MonOpRequestRef op) return entry.prio >= level; }; + // Decrement operation that sets to container end when hitting rbegin ostringstream ss; if (channel == "*") { list full_tail; @@ -460,7 +461,21 @@ bool LogMonitor::preprocess_command(MonOpRequestRef op) if (rp == full_tail.rend()) { --rp; } - for (; rp != full_tail.rbegin(); --rp) { + + // Decrement a reverse iterator such that going past rbegin() + // sets it to rend(). This is for writing a for() loop that + // goes up to (and including) rbegin() + auto dec = [&rp, &full_tail] () { + if (rp == full_tail.rbegin()) { + rp = full_tail.rend(); + } else { + --rp; + } + }; + + // Move forward to the end of the container (decrement the reverse + // iterator). + for (; rp != full_tail.rend(); dec()) { if (!match(*rp)) { continue; } @@ -471,7 +486,6 @@ bool LogMonitor::preprocess_command(MonOpRequestRef op) } } } else { - derr << "bar" << dendl; auto p = summary.tail_by_channel.find(channel); if (p != summary.tail_by_channel.end()) { auto rp = p->second.rbegin(); @@ -483,7 +497,21 @@ bool LogMonitor::preprocess_command(MonOpRequestRef op) if (rp == p->second.rend()) { --rp; } - for (; rp != p->second.rbegin(); --rp) { + + // Decrement a reverse iterator such that going past rbegin() + // sets it to rend(). This is for writing a for() loop that + // goes up to (and including) rbegin() + auto dec = [&rp, &p] () { + if (rp == p->second.rbegin()) { + rp = p->second.rend(); + } else { + --rp; + } + }; + + // Move forward to the end of the container (decrement the reverse + // iterator). + for (; rp != p->second.rend(); dec()) { if (!match(rp->second)) { continue; } -- 2.47.3