Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(704)

Unified Diff: logdog/common/archive/index.go

Issue 2435883002: LogDog: Fix archival Get/Tail implementations. (Closed)
Patch Set: LogDog: Fix archival Get/Tail implementations. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: logdog/common/archive/index.go
diff --git a/logdog/common/archive/index.go b/logdog/common/archive/index.go
index 3e9ad22891cf3946d2e82d65642db77024fc5df4..f4ca32c112f4a8dde6149b0dd7d922b26f0313c0 100644
--- a/logdog/common/archive/index.go
+++ b/logdog/common/archive/index.go
@@ -20,6 +20,8 @@ type indexBuilder struct {
lastStreamIndex uint64
lastBytes uint64
+ latestBufferedEntry *logpb.LogIndex_Entry
+
sizeFunc func(proto.Message) int
}
@@ -34,25 +36,29 @@ func (i *indexBuilder) addLogEntry(le *logpb.LogEntry, offset int64) {
i.index.LastStreamIndex = le.StreamIndex
i.index.LogEntryCount++
+ entry := logpb.LogIndex_Entry{
+ Sequence: le.Sequence,
+ PrefixIndex: le.PrefixIndex,
+ StreamIndex: le.StreamIndex,
+ Offset: uint64(offset),
+ TimeOffset: le.TimeOffset,
+ }
+
// Do we index this LogEntry?
if len(i.index.Entries) > 0 {
if !((i.StreamIndexRange > 0 && (le.StreamIndex-i.lastStreamIndex) >= uint64(i.StreamIndexRange)) ||
(i.PrefixIndexRange > 0 && (le.PrefixIndex-i.lastPrefixIndex) >= uint64(i.PrefixIndexRange)) ||
(i.ByteRange > 0 && i.lastBytes >= uint64(i.ByteRange))) {
- // Not going to index this entry.
+ // Not going to index this entry. Buffer it as a terminator.
+ i.latestBufferedEntry = &entry
return
}
i.lastBytes = 0
}
- i.index.Entries = append(i.index.Entries, &logpb.LogIndex_Entry{
- Sequence: le.Sequence,
- PrefixIndex: le.PrefixIndex,
- StreamIndex: le.StreamIndex,
- Offset: uint64(offset),
- TimeOffset: le.TimeOffset,
- })
+ i.index.Entries = append(i.index.Entries, &entry)
+ i.latestBufferedEntry = nil
// Update our counters.
i.lastStreamIndex = le.StreamIndex
@@ -60,6 +66,11 @@ func (i *indexBuilder) addLogEntry(le *logpb.LogEntry, offset int64) {
}
func (i *indexBuilder) emit(w io.Writer) error {
+ // Always include the last stream entry in the index.
+ if i.latestBufferedEntry != nil {
+ i.index.Entries = append(i.index.Entries, i.latestBufferedEntry)
+ }
+
d, err := proto.Marshal(&i.index)
if err != nil {
return err

Powered by Google App Engine
This is Rietveld 408576698