mq logstore: list from the start once a partition's names leave offset order

An offset read lists from the indexed file starting at or before its offset,
which is right only while names sort in offset order. Directories written
under clock skew before log file names were kept ordered hold files sorting
before files with lower offsets, and a read listing from a later mark passed
over them. The index now remembers the highest offset it has seen in name
order, and once a file starts below it the partition is unordered and every
offset read lists from the first file, as before the index existed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-12-01 00:53:59 -08:00
1 parent 6ec18be4d0
commit 74f43f7ad6
2 files changed
+17 -2

No files matched your search

+14 -2
View File
@@ -31,6 +31,10 @@ type logFileIndex struct {
marks []logFileMark
lastName string
unmarked int
// maxOffset is the highest offset recorded so far; a later name starting below it
// makes the partition unordered, as files written under clock skew can be
maxOffset int64
unordered bool
}
type logFileMark struct {
@@ -47,8 +51,12 @@ func (x *logFileIndex) add(entries []*filer_pb.Entry) {
if entry.Name <= x.lastName {
continue
}
minOffset, maxOffset, hasOffsets := logFileOffsets(entry)
if hasOffsets {
x.unordered = x.unordered || minOffset < x.maxOffset
x.maxOffset = max(x.maxOffset, maxOffset)
}
if len(x.marks) == 0 || x.unmarked >= logFileIndexStride-1 {
minOffset, _, hasOffsets := logFileOffsets(entry)
x.marks = append(x.marks, logFileMark{name: entry.Name, minOffset: minOffset, hasOffsets: hasOffsets})
x.unmarked = 0
} else {
@@ -69,10 +77,14 @@ func (x *logFileIndex) markBefore(name string) string {
}
// markAtOffset is the last marked file starting at or before offset, or "" for the start.
// Offsets grow with names, so no earlier file can hold offset, including one with no offset range.
// Where offsets grow with names, no earlier file can hold offset, including one with no
// offset range; an unordered partition is always read from the start.
func (x *logFileIndex) markAtOffset(offset int64) string {
x.Lock()
defer x.Unlock()
if x.unordered {
return ""
}
for i := len(x.marks) - 1; i >= 0; i-- {
if m := x.marks[i]; m.hasOffsets && m.minOffset <= offset {
return m.name
@@ -341,4 +341,7 @@ func TestReadFromDiskByOffsetFindsAFileSortingBeforeLowerOffsets(t *testing.T) {
if got := readOffsets(t, read, 0); !slices.Equal(slices.Sorted(slices.Values(got)), offsetsFrom(0, 2*files+2)) {
t.Errorf("read %d offsets from 0, want %d", len(got), 2*files+2)
}
if got := readOffsets(t, read, 2*files); !slices.Equal(got, offsetsFrom(2*files, 2*files+2)) {
t.Errorf("read %v from the skewed file once the reader had listed the partition", got)
}
}