osbase/logtree: add WithStartPosition option
To allow users to not always request all messages,
we introduce another option to the logtree.LogReader
which allows for starting at a specific global log id.
This, for example, makes implementing scrollback easier.
Change-Id: I1773288f670f476706d94baf3f052fe1e5da9eb0
Reviewed-on: https://review.monogon.dev/c/monogon/+/4452
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/osbase/logtree/journal_entry.go b/osbase/logtree/journal_entry.go
index c553ac8..d492d16 100644
--- a/osbase/logtree/journal_entry.go
+++ b/osbase/logtree/journal_entry.go
@@ -43,6 +43,10 @@
// length calculation for local linked lists as long as entries are only unlinked
// from the head or tail (which is the case in the current implementation).
seqLocal uint64
+
+ // seqGlobal is a counter within the global log structure that increases by
+ // one each time a new log entry is added.
+ seqGlobal uint64
}
// defaultDNQuota defines how many messages should be stored per DN.
@@ -53,9 +57,10 @@
// sequences, etc. These objects are visible to library consumers.
func (e *entry) external() *LogEntry {
return &LogEntry{
- DN: e.origin,
- Leveled: e.leveled,
- Raw: e.raw,
+ DN: e.origin,
+ Leveled: e.leveled,
+ Raw: e.raw,
+ Position: int(e.seqGlobal),
}
}
@@ -108,6 +113,8 @@
defer j.mu.Unlock()
e.journal = j
+ e.seqGlobal = j.seq
+ j.seq++
// Insert at head in global linked list, set pointers.
e.nextGlobal = nil