Skip to content

Commit

Permalink
mon/LogMonitor: "log last" should return up to n entries
Browse files Browse the repository at this point in the history
limit the # of returned entries to "num", and backoff the start iterator
by one if it reaches the rend().

Signed-off-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
tchaikov committed Nov 6, 2017
1 parent f265ed6 commit 356d35f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/mon/LogMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 356d35f

Please sign in to comment.