From 9bc88511fb73d39790bf4e35229fb7b29924e586 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 1 Dec 2026 01:46:13 -0800 Subject: [PATCH] mq logstore: leave an older file unbounded when the next name was clamped A file without a recorded last message time was bounded by the end of the next file's start second, on the reasoning that it ended before the next began. When the next file is a slower leader's window clamped into that second, its name says nothing about when its messages, or the older file's, end; the older file was bounded too early, a later mark qualified, and a resume past it skipped its remaining messages. The next file now bounds it only when its name is not later than its first message; otherwise the older file stays unbounded, no mark after it qualifies, and a resume lists from before it. Co-Authored-By: Claude Opus 5.5 --- weed/mq/logstore/read_log_from_disk.go | 8 +++++--- weed/mq/logstore/read_log_from_disk_test.go | 13 ++++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/weed/mq/logstore/read_log_from_disk.go b/weed/mq/logstore/read_log_from_disk.go index 2166dfbb70..6d0f003cb5 100644 --- a/weed/mq/logstore/read_log_from_disk.go +++ b/weed/mq/logstore/read_log_from_disk.go @@ -65,11 +65,13 @@ func (x *logFileIndex) add(entries []*filer_pb.Entry) { x.maxOffset = max(x.maxOffset, maxOffset) } if x.open { - // a file without its last message time was named by its first, before any name was - // moved later, and ended before the next file began + // a file without its last message time was named by its first and ended before the + // next file began, which only a next name not moved later than its messages tells nameEndTsNs := int64(math.MaxInt64) if nameTime, err := topic.ParseLogFileTime(entry.Name); err == nil { - nameEndTsNs = nameTime.Add(time.Second).UnixNano() - 1 + if firstTsNs, ok := logFileTsNs(entry, mq.ExtendedAttrTimestampMin); !ok || firstTsNs >= nameTime.UnixNano() { + nameEndTsNs = nameTime.Add(time.Second).UnixNano() - 1 + } } x.lastTsNs, x.open = max(x.lastTsNs, nameEndTsNs), false } diff --git a/weed/mq/logstore/read_log_from_disk_test.go b/weed/mq/logstore/read_log_from_disk_test.go index b2aa7b1f87..27952bd93e 100644 --- a/weed/mq/logstore/read_log_from_disk_test.go +++ b/weed/mq/logstore/read_log_from_disk_test.go @@ -232,9 +232,12 @@ func TestReadFromDiskResumesPastManyLaterSortingFiles(t *testing.T) { for _, tc := range []struct { name string first time.Time + // the earlier file predates recorded message times + older bool }{ - {"names clamped to a slow leader's later second", second.Add(-time.Minute)}, - {"messages overlapping in one second", second.Add(100 * time.Millisecond)}, + {"names clamped to a slow leader's later second", second.Add(-time.Minute), false}, + {"messages overlapping in one second", second.Add(100 * time.Millisecond), false}, + {"names clamped after a file without its message times", second.Add(-time.Minute), true}, } { t.Run(tc.name, func(t *testing.T) { timeAttrs := func(minTs, maxTs time.Time) map[string][]byte { @@ -245,7 +248,11 @@ func TestReadFromDiskResumesPastManyLaterSortingFiles(t *testing.T) { } volume := serveChunks(t, map[string][]byte{"/3,01": logChunk(t, second.UnixNano(), second.Add(4*time.Second).UnixNano())}) a := volume.file(topic.LogFileName(second, 0), "3,01") - a.Extended = timeAttrs(second, second.Add(4*time.Second)) + if tc.older { + a.Name = second.Format(topic.TIME_FORMAT) + } else { + a.Extended = timeAttrs(second, second.Add(4*time.Second)) + } files := []*filer_pb.Entry{a} for i := range logFileIndexStride + 6 { ts := tc.first.Add(time.Duration(i) * time.Millisecond)