Files
seaweedfs/weed/query/engine/system_columns_test.go
T
Chris LuandClaude Opus 5.5 3363f4a318 mq: disk and parquet reads stop when asked, resume inside earlier files, and order new stamps after stored ones (#13230)
* mq logstore: stop a disk read when the callback is done

GenLogOnDiskReadFunc ignored the isDone the per-entry callback returned, so it
kept fetching and delivering every later entry, chunk and file, and the merged
read then went on into the parquet files. The chunked offset read and the query
scanner's close path both return true and expect the read to stop. The reader
now stops at that entry, skips the remaining chunks and files, and returns done
with a position just past the entry: the next offset for an offset read, its
time for a timestamp read. The merged read returns there instead of reading
parquet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq logstore: stop a parquet read when the callback is done

The parquet reader also ignored the callback's isDone and delivered every
remaining row of every compacted file, and the merged read cleared any done it
reported. It now stops at that row and skips the remaining files, which it
lists before reading instead of reading inside the listing. Its done now means
only that the callback asked to stop, so the merged read passes it on; the
no-op readers and a file starting at or after stopTsNs no longer report done,
which the merged read used to clear anyway.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq logstore: read parquet files named before a timestamp resume

A parquet file is named after its first source log, and that log can start
seconds before rows the file holds, so listing parquet files from the resume
second skipped a file named earlier that still held later rows. The reader now
keeps the same sparse logFileIndex the log reader uses and lists from the last
mark before which every file ends before the resume time, deciding each file
by its ts_max.

Rows are not in time order once windows flushed across a reload are compacted
together, so stopping at the first row past stopTsNs dropped later rows still
inside it. Each row is now kept or skipped on its own, and the returned
position is the latest row delivered rather than the last row looked at.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* query: take MIN and MAX of _ts from the files' recorded time range

MIN and MAX of _ts without column statistics were computed from file names,
which are only the start second of a file's first source log: MIN rounded down
to that second and MAX was the start of the latest file rather than its last
row. Each file's stats already carry ts_min and ts_max as MinTimestampNs and
MaxTimestampNs, so those are used when set, and names only for files that
record no range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq broker: stamp a loaded partition's messages after the newest stored one

Within one LogBuffer timestamps only increase, but a new buffer starts LastTsNs
at 0, so a leader whose clock is behind the previous leader's stamped new
messages earlier than what was already stored, and a subscriber resuming by
timestamp from the last stored message dropped them. OffsetRange now also
records the newest ts_max of the partition's log and parquet files, and loading
a partition seeds LastTsNs with it, so the buffer bumps new messages past it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq logstore: read parquet rows at the stop time

The log reader treats stopTsNs as inclusive, delivering an entry at it and
reading a file whose first entry is at it, but the parquet reader stopped at a
row equal to it and skipped a file starting at it, so the same bounded read
returned that message from a log file and dropped it once compacted. Both
checks are now inclusive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq logstore: drop a debug print from the disk read

A disk read bounded by stopTsNs printed the stop time and the first entry past
it to stdout on every such read. It was a leftover debug line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq logstore: start an offset read of parquet files at the offset

An offset read of the parquet files delivered every row from the first one on,
and the stateless fetch fills a disk chunk with a callback that stops after a
chunk's worth of entries outside it. Now that the reader honors that stop, a
fetch at 1000 from a partition stored only in parquet stopped after rows 0-999
and returned nothing. An offset read now skips files whose recorded range ends
below the offset or that record none, reads the rest in offset order, and skips
rows below the offset before they reach the callback. It returns the offset
after the last row delivered, not a timestamp position.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq logstore: read parquet files first in a merged offset read

The merged read took the live log files first and, now that it honors the
callback's done, returned without reading parquet when the callback stopped.
The stateless fetch stops after a chunk's worth of entries outside the chunk it
fills, so with offsets 0-999 only in parquet and 1000-1999 in log files, a fetch
at 0 stopped on the log files' entries and never reached parquet.

Compaction turns the oldest windows into parquet, so an offset read now takes
the parquet files first and the log files after: the lower offsets arrive
first, and since each source skips what lies below its start, a bounded caller
only stops on entries past what it wants. Compaction leaves a parquet file's
source logs in place until retention removes them, so the log files are read
from the offset after the last one parquet delivered, and each offset is
delivered once. Timestamp reads keep their order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq logstore: serve merged offset reads from log files where they exist

A merged offset read took parquet first and the log files from the offset after
the last row parquet delivered. Compaction keeps a parquet file's source logs
until retention removes them and drops messages with no key or no data, so that
skipped those messages although their logs were still there, and delivered
compacted rows in place of the messages as written.

The log reader now lists its files before reading them, and an offset read
finds the lowest offset the listed log files record. Parquet serves only the
offsets from the requested one up to that, and the log files everything from
there, so each offset is read once and from a log file whenever one holds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq logstore: read schemaless parquet rows back as their published bytes

Compaction stores a schemaless message's bytes in the _value column, but the
parquet reader handed out the whole row marshaled as a RecordValue, with _key,
_ts_ns and _offset wrapped around it, so a consumer reading compacted offsets
got different bytes than it would from the log files, and the query engine
showed that wrapping as the value. A schemaless topic's rows now carry the
_value bytes as Data; schematized topics keep the marshaled row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq logstore: fail a read that needs parquet when its reader cannot be set up

A topic whose schema cannot be laid out as parquet left the parquet
reader nil, and a merged read that reached parquet called it and
panicked. Such a read now returns the setup error; skipping the parquet
rows silently would hide stored messages.

* mq logstore: a stopped log read returns the last delivered time

A later-named log file can hold earlier messages, so the latest time a
stopped read delivered can be past one it never reached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq logstore: compact a group's rows in offset order

Source logs list by name, which sorts out of offset order under clock
skew, so a compacted file could hold offsets 2,3,0,1. An offset read
delivers a file's rows as stored and then reports a next offset past
ones it never delivered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mq: floor a reload's stamps by the newest legacy log file name

Log files record ts_max only since this release, so after an upgrade a
reload saw no newest time and seeded the stamps at zero. A log file that
records no times is named by its first message, so its second still
bounds the newest stored time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 14:14:02 -08:00

33 lines
1.3 KiB
Go

package engine
import (
"testing"
"time"
"github.com/seaweedfs/seaweedfs/weed/mq/topic"
)
// A file's name is the start second of its first source log; MIN and MAX of _ts
// come from the timestamp range the file records, and from names only without one.
func TestSystemColumnTimestampRangePrefersFileStats(t *testing.T) {
base := time.Date(2026, 11, 30, 10, 0, 0, 0, time.UTC)
stats := map[string][]*ParquetFileStats{
"p0": {
{FileName: topic.LogFileName(base, 0) + ".parquet", MinTimestampNs: base.Add(500 * time.Millisecond).UnixNano(), MaxTimestampNs: base.Add(9 * time.Second).UnixNano()},
{FileName: topic.LogFileName(base.Add(5*time.Second), 4) + ".parquet"},
},
}
e := &SQLEngine{}
if got, want := e.getSystemColumnGlobalMin(SW_COLUMN_NAME_TIMESTAMP, stats), base.Add(500*time.Millisecond).UnixNano(); got != want {
t.Errorf("min %v, want %v", got, want)
}
if got, want := e.getSystemColumnGlobalMax(SW_COLUMN_NAME_TIMESTAMP, stats), base.Add(9*time.Second).UnixNano(); got != want {
t.Errorf("max %v, want %v", got, want)
}
stats["p0"] = stats["p0"][1:]
if got, want := e.getSystemColumnGlobalMax(SW_COLUMN_NAME_TIMESTAMP, stats), base.Add(5*time.Second).UnixNano(); got != want {
t.Errorf("max without stats %v, want the name's %v", got, want)
}
}