Files
seaweedfs/weed/worker/tasks/iceberg
Chris LuandClaude Opus 5.5 51d2b2b712 mq: read a table-backed topic's history from its Iceberg table (#13260)
* mq: read a topic table's data files back as log entries

A view of a topic's table holds the current snapshot's offset map and, per
_partition, its data files with the _offset and _ts_ns bounds from the
manifests. A partition's rows are read by offset or by time, skipping files
and then row groups whose bounds miss the read, and come back as the log
entries they were copied from: key, timestamp, offset, and the message as
_value or as the record re-encoded from its columns. Views are cached per
topic, rechecked every few seconds, rebuilt only when the metadata location
moves, reuse already-parsed manifests, and are evicted past a bound on the
data files they hold. A table that is gone or replaced by another UUID reads
as empty; one with delete files is refused.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: read a table-backed partition below its table's high-water mark from the table

The merged reader takes the partition's table, looked up on every read so a
table attached later is seen. An offset read below the mark reads the table
up to the mark and continues into the log files and compacted parquet from
the mark; a time read takes the table's rows after the time and then the
files' entries at or above the mark. Log files left below the mark by a
crash between the writer's commit and its delete are never read. The broker
hands its partitions' disk reads to the table through the topic's cached
view; a topic without a table, or whose topic.conf is gone, reads its files
as before.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq broker: start a table-backed partition's offsets at its table

A partition whose log files below the table's high-water mark were deleted
would reload with a high-water mark and log start taken from the files that
are left. Loading it now continues its offsets no lower than the table's
mark and starts its log at the table's lowest offset, or, when the table
holds nothing of it, at the first file offset at or above the mark. A
retired range of a repartitioned topic is read and bounded the same way,
and a retention purge raises the log start likewise, so purging hot log
files never makes the table's offsets out of range.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* query: keep a flushed data source's finished flag atomic

The streaming goroutine sets finished while the merge loop reads it through
HasMore, which the race detector reports on any scan that reads flushed
data.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* query: scan a table-backed topic's history from its table

The hybrid scanner hands each partition's merged read the topic's table,
so a scan reads the table's data files below the partition's high-water
mark, pruned by _partition, _offset and _ts_ns, and log files from the mark
on, skipping any a crash left below it. Aggregations no longer answer such
a topic from parquet statistics and log counts, which hold none of its
table's rows; they scan instead.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: read a schematized row's raw _value back as its message

A schematized topic's table can keep a message that is not a record, a
tombstone or an undecodable value, as raw bytes in an optional _value with
the record columns null. Such a row now reads back as those bytes; a row
whose _value is null reads back as its record, and a schemaless topic's row
as its _value as before.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: delete log files a topic table already holds

A log file or compacted parquet whose every offset is below a partition's
table high-water mark is never read again, so it can go. The mark used is
that of the newest snapshot at least a minute old: a reader's view of the
table is at most a few seconds old, so it already reads those offsets from
the table and never from a file being deleted. Files without an offset
range and the file holding the partition's highest offset are always kept.
DeleteCoveredLogFiles is for the topic's writer after its commit; a leader
also deletes them under its fence on load and on each retention pass,
covering a writer that crashed between its commit and its delete.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* query: report a topic table's rows as parquet_archive

A table-backed topic's scan labelled every row live_log, its table's
included. The flushed data source now records the high-water mark of the
table its merged read was handed and reports the rows below it, which come
only from the table's parquet data files, as parquet_archive.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* worker: delete the log files a topic table holds after each run

Every mq_topic_table run now ends by deleting, in each partition, the log
files wholly below the offsets of the newest snapshot at least
LogDeleteGrace old, never the leader's newest file. A commit is never old
enough on the run that makes it, so each run deletes what earlier ones
copied; the partition's leader deletes the same files when no run follows.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: keep a time read's position when nothing on disk follows it

A time read that found nothing after its position returned a position at
time zero: the parquet reader reports the newest time it delivered, which
is none. A loop over an empty memory buffer then read the whole partition
from the start, came back to the same empty read, and started over, so a
query asking a broker for its unflushed messages streamed the partition
forever. The merged and the table-tiered readers now keep the position
when they deliver nothing past it.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: publish a topic table view under the lock eviction reads it with

A loaded view was stored under its entry's loading lock while eviction,
run by another topic's load, read every entry's view under the cache's
lock, so two topics refreshing at once raced. A view is now stored holding
both locks: a load reads it under the first, eviction under the second.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: keep no topic table view larger than the whole view cache

Eviction never dropped the view just loaded, so one topic whose table had
more data files than the cache's bound stayed cached past it, and evicted
every other topic's view on the way. Such a view is now answered and not
kept; the others stay.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: look up a topic table's mark again where a read leaves the table

A read kept the table mark it started with. One slow over the table's
rows could outlast the grace: the writer commits past that mark, the logs
below the new mark are deleted, and the read then lists the logs from its
old mark and passes over the deleted offsets without a word. The read now
asks for the table again each time it leaves it and reads on in the table
up to the mark it finds, until the mark stops moving; a time read takes
the rows between the marks by offset. A gap where the logs begin is
checked against the table once more, and read from the table if it took
it meanwhile.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: read a topic table's timestamps back without going through nanoseconds

A timestamp or time column was turned into micros by way of nanoseconds,
which overflow for dates before 1678 or after 2261, so a year 1 or year
9999 value came back as another date. Each unit now converts to micros
directly. The table fixture wrote every topic's rows whole into _value
once every table had that column, so the record columns these reads take
went untested; it now writes a schematized topic's rows as columns.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* iceberg: order a compaction bin by the first sort field that varies in it

A topic table sorts by _partition, then _offset, and is partitioned by
_partition, so every file of a bin holds one _partition. Ordering the bin
by it kept the files in manifest order, and a merged file's offsets came
out of order for the topic table reader, which delivers a data file's rows
as offsets in order.

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

* mq broker: list a retired range from its table's lowest offset

A topic lookup lists each retired range with the bounds of its own files,
so once the table held a range's history and its log files went, the range
was listed from its newest file on, while its reader serves the table's
offsets below it.

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

* iceberg: never merge compaction inputs across a file left out of the merge

A file already at the target size takes no part in compaction, yet small
files on both sides of it in sort order went into one bin, so the merged
file's bounds spanned it. For a topic table that is a data file whose
_offset range overlaps another's, which a reader finishing one file before
the next cannot read in order. An ordered bin is now cut wherever a file
left out of the merge falls between two of its files, so every merged file
covers a range no file outside its run lies in.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: merge a topic table's overlapping data files by offset when reading

A partition's data files were read one after another by their lowest
offset, which only reads in offset order while no two ranges overlap. A
rewrite by another engine can leave a file spanning another one, and then
a read from inside the overlap delivered the spanning file's later rows
first, and a read that stopped early left the rows in between behind.
Files whose offset ranges overlap are now read together, their rows merged
by offset and an offset held twice delivered once.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: open a topic table's data files only as a read reaches them

A merged read opened every file of an overlapping group before it
delivered a row, and a file the manifest records no offset bounds for
overlaps every other one, so a short fetch held a reader for each file of
the partition's history. The files of a read now wait in a heap keyed by
the lowest offset each can hold, and a file is opened only once nothing
before that offset is left to deliver; a file without bounds is opened
where the read starts, and its row groups' statistics skip what they rule
out.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq broker: retire no log file a topic's table does not hold yet

Retention deleted a table-backed topic's log files by age alone, so with
the table writer behind it deleted messages the table did not hold, and
they were gone from both. On such a topic a file now expires only once
all it holds is below the table's mark of a grace-old snapshot, the same
files the leader deletes as covered; what the table holds ages out with
table retention.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq broker: bound a table-backed range's bounds by its caller's deadline

The table lookup that widens a partition's bounds ran under a background
context, so a retention pass or a retired-range lookup with a deadline
waited on a stalled table catalog for as long as it stalled. It now runs
under the caller's context.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: check a topic table's mark again when a time read reaches its files

A time read caught up with the table and then read the files above the
mark it last saw. A view that had moved on meanwhile, with the logs below
its new mark deleted before the files were listed, left the offsets
between the two marks to neither. The time read now asks for the table
again at the first file entry it would deliver, or after the files if they
held none, and on a moved mark reads the table up to it before reading the
files again.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: bound the topic table views kept, empty ones included, and keep those in use

Eviction only counted data files, so views of tables holding none, and
entries a failed first load left behind, were never dropped; and it could
drop an entry while a caller was loading it, so the next caller loaded the
same table again alongside. A failed first load now leaves no entry, at
most maxCachedTopics views are kept, and an entry a caller still holds is
never evicted. The eviction test now requires exactly the one eviction
that makes room.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: check a topic table afresh before deleting the logs below its mark

A leader's covered-log delete and log retention took the table's mark
from the cached view, up to a few seconds old, so a table rolled back to a
lower mark meanwhile had its logs above that mark deleted although it no
longer held them. Both now check the table before acting: the cache takes
a maximum age, a read passes ViewRefresh and a delete zero. A cached view
is also reused only for the same table state, since a commit that rewrote
the metadata in place keeps its location.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* iceberg: leave a sort field holding nulls to order a compaction bin

A sort field whose bounds are one value in every file was taken as
constant and the bin ordered by the next field, yet bounds leave nulls and
NaNs out, so a column holding them besides its one value is not constant.
A field is now skipped only when the files also record no null in it, and
no NaN for a floating point one.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* worker: delete a topic's covered logs only while it still names the table

A run's log cleanup used the table metadata the run started with, so after
the topic left the table, or the run lost its lock, it still deleted the
logs below that table's marks. The cleanup now checks, when it runs, that
it still holds the topic's lock and that topic.conf still names the table
with its recorded UUID, and reads the marks from the table as it is then.
It still runs after a run that failed otherwise.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq broker: check a topic table again before each covered log it deletes

The leader read the table's mark once, listed the files below it, then
deleted them one by one, so a rollback or a detach landing in between went
unseen and files the table no longer held were deleted. The delete now
holds the table writer's lock, so the topic cannot leave the table
meanwhile, and before each file reads topic.conf and the table afresh,
stopping at the first file not below the mark it finds.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: let a caller waiting on a topic table's load give up at its deadline

A caller wanting the view a stalled load of the same table was making
waited on a mutex, past its own deadline, for as long as the load stalled.
The entry is now held by a one-token channel a waiter selects on with its
context, so it returns at its deadline and lets go of the entry.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* query: give up a scan's table lookup when the query is cancelled

The table a scan reads below each partition's mark was looked up under a
background context, and the flushed data source waited on its channels
alone, so a cancelled query stayed blocked on a stalled table catalog. The
scan's context now reaches the topic.conf read and the table lookup, and
the data source returns once it is done.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq broker: take a topic table's lock only when a covered log is left to delete

The leader's covered-log pass took the table writer's lock for every
table-backed partition it leads once the table had a mark, every five
minutes, even with nothing to delete. While a copy run held the lock, each
such partition waited out the lock wait and logged a failure, holding up
the rest of the retention tick. List the covered files first and take the
lock only when there are some; the per-file checks under the lock stay.

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

* mq: drop a topic table view only with the last caller holding it

An oversized view was removed while other callers still held it, so the
next caller loaded it again alongside; an entry no load filled was removed
only by a failing load that was its sole holder, so one whose callers
failed or gave up in another order stayed; and eviction that found every
candidate held left the cache above its bounds with nothing to evict
again. Callers now let go through one release: the last one removes an
entry no load filled or one marked to drop, as an oversized view is, and
each release runs eviction again.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* worker: check a topic's table again before each covered log the cleanup deletes

The cleanup checked the lock, topic.conf and the table once, then deleted
every file below the marks it read, so a detach, a dropped or replaced
table, or a lapsed lease landing during the deletes went unseen. The
deletes now check all three again before each file, with the mark of the
table as it is then, and stop at the first file not below it.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* query: let a flushed data source's producer close its own channels

Next can return on the query's cancellation while the producer is still
sending, and the merge then closes the source, which closed the result
and error channels under that send. The producer now owns them: Close
only signals it to stop, every send also selects on that signal, and the
producer closes the result channel when it exits, after sending its one
error if it has one.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* query: fail a scan whose data source fails after its first row

The merge only logged an error from a source past its first row, the
query's cancellation included, and returned the rows read so far, so a
cancelled or timed-out COUNT or SUM answered with a wrong number. It now
closes its sources and returns the error, and the scan wraps it, so a
caller can tell the context's error from others.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq broker: check a topic table again before each group retention deletes

Retention read a table-backed partition's deletable mark once, chose its
expired groups, then deleted them with no further look, as the covered-log
delete did before it rechecked; a rollback in between left groups deleted
that the table no longer held. The live and retired purges and the
covered-log delete now share one guard: it holds the table writer's lock
and, before each group or file, reads topic.conf and the table afresh,
stopping at the first one not below the mark it finds.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq broker: bound a partition load's reads of what it already stores

Loading a partition reads its files' offset range and, for a table-backed
topic, the table's, while holding accessLock, under a background context,
so a stalled filer or table catalog held every other partition operation
for as long as it stalled. The reads now get the bound a load's fence
take has; past it the load fails, as it does when the stored offsets
cannot be read, and the caller retries. Falling back to the log files'
bounds would start the log above the table's offsets with no later
refresh to lower it, so consumers resetting to the earliest offset would
skip the table's history.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* query: count a flushed source's pending error as more to read

The merge asks HasMore before reading a source again, and HasMore looked
only at buffered rows and whether the producer finished, so a producer
that failed after its last row and finished before the merge asked had
its error never read, and the scan returned the rows so far as its
answer. An error waiting counts as more to read now, so Next returns it.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq broker: keep the table's files of a topic that left it before the delete

A topic that left its table between the listing of what the table held
and the guard the delete takes got no guard, which let every listed file
go, though readers take those offsets from the logs again. Files chosen
by the table's rules, the covered logs and the groups retention trimmed
to the table's mark, are now kept when no table remains; files of a topic
that had no table when the pass began still expire as before.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* query: order the pending-error merge test's row before its error

The test's producer could send its error before the first Next took the
row, and Next then picked either one, so on some runs the error came
through the first read and the test passed without exercising HasMore.
The producer now holds its error until the first Next has the row, and
the merge asks again only after the producer has finished, so the test
fails every time without the pending-error fix.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq: read a topic table's chunk-backed files under the caller's context

A manifest or manifest list stored in chunks was read through a stream
reader built without a context, and the stream reader looked up and
fetched each chunk under a background context even when built with one,
so a stalled volume server held a partition load past its bound while it
held accessLock. A chunk stream reader now looks up and fetches its chunks
under the context it was built with, and a table's chunk-backed files are
read with the caller's.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* mq broker: keep the expiredLogFiles doc comment on expiredLogFiles

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

* mq broker: let the table catalog read chunk-backed table metadata

The broker's table catalog reached its filers through a client with no
way to look up chunk locations, so a table whose catalog record holds
only the location of its metadata, as one whose metadata outgrew a
request does, failed to load once that file was stored in chunks: the
topic's history could not be read. The client now resolves chunks the
way the broker's own filer client does.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* iceberg: read chunk-backed table metadata under the caller's context

A catalog record holding only a metadata location had its chunk-backed
file read by StreamContent, whose lookups and fetches run under a
background context, so a stalled volume server held a table load past its
caller's deadline: a broker loading a table-backed partition under
accessLock past its bound. The read now streams under the read's own
context, which already bounds its other filer calls.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

* filer: give up a LookupFn volume lookup's retries at its caller's deadline

LookupFn retried a failed volume lookup through util.Retry, which sleeps
its backoff without looking at the caller's context, so a lookup failing
near a deadline outlived it by up to the whole backoff; a table load under
a broker's accessLock held it that long. The lookup now retries through
util.RetryWithBackoff with the same transient-error rule and about the
same total wait, which stops when the context is done.

Claude-Session: https://claude.ai/code/session_011Upvai5AjLiNE5B1HCAn34

---------

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