From: Kefu Chai Date: Mon, 6 Nov 2017 08:01:23 +0000 (+0800) Subject: mon/LogMonitor: "log last" should return up to n entries X-Git-Tag: v13.0.1~262^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F18759%2Fhead;p=ceph.git mon/LogMonitor: "log last" should return up to n entries limit the # of returned entries to "num", and backoff the start iterator by one if it reaches the rend(). Signed-off-by: Kefu Chai --- diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index 60f71e108bd2..9c9541933bca 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -429,23 +429,24 @@ bool LogMonitor::preprocess_command(MonOpRequestRef op) }; auto rp = summary.tail.rbegin(); - while (num > 0 && rp != summary.tail.rend()) { + for (; num > 0 && rp != summary.tail.rend(); ++rp) { if (match(*rp)) { num--; } - ++rp; + } + if (rp == summary.tail.rend()) { + --rp; } ostringstream ss; - auto p = summary.tail.begin(); - for ( ; p != summary.tail.end(); ++p) { - if (!match(*p)) { + for (; rp != summary.tail.rbegin(); --rp) { + if (!match(*rp)) { continue; } if (f) { - f->dump_object("entry", *p); + f->dump_object("entry", *rp); } else { - ss << *p << "\n"; + ss << *rp << "\n"; } } if (f) {