m/pkg/logtree: fix exact backlog fetch, head/tail confusion
This started off as 'hm, the backlog data returned seems wrong'. I
realized we had no test for that, so I added one. It was indeed broken.
This was because we had two simultaneous bugs: we confused head/tail
between docs and different parts of the code, and we forgot to do a
reverse operation when scanning/retrieving journal entries.
With those two fixed, we also implement backlog retrieval in a optimized
fashion, but not scanning/retrieving more entries that is necessary.
Finally, we drive-by fix a massacred ASCII graphic in a comment.
Change-Id: I2ec5dd9b5b58f66fbc015c142feb91bd92038e4f
Reviewed-on: https://review.monogon.dev/c/monogon/+/1430
Tested-by: Jenkins CI
Reviewed-by: Leopold Schabel <leo@monogon.tech>
diff --git a/metropolis/pkg/logtree/logtree_access.go b/metropolis/pkg/logtree/logtree_access.go
index 1babe1e..b601ea4 100644
--- a/metropolis/pkg/logtree/logtree_access.go
+++ b/metropolis/pkg/logtree/logtree_access.go
@@ -157,14 +157,10 @@
var entries []*entry
if backlog > 0 || backlog == BacklogAllAvailable {
- // TODO(q3k): pass over the backlog count to scanEntries/getEntries, instead of discarding them here.
if recursive {
- entries = l.journal.scanEntries(filters...)
+ entries = l.journal.scanEntries(backlog, filters...)
} else {
- entries = l.journal.getEntries(dn, filters...)
- }
- if backlog != BacklogAllAvailable && len(entries) > backlog {
- entries = entries[:backlog]
+ entries = l.journal.getEntries(backlog, dn, filters...)
}
}