Repository navigation
Description
Search before asking
- I searched in the issues and found nothing similar.
Fluss version
1.0.0 (latest release)
Please describe the bug 🐞
For a log table tiered to Iceberg, a Flink union read (scan.startup.mode = 'full') does not return a bucket's rows in write order. No rows are lost or duplicated, but the Iceberg data files of one bucket are read in an arbitrary order before the hand-off to the Fluss log. The same test against a Paimon lake returns rows in write order. Also seen on 0.9.0.
Found by @dgnester while we were testing union reads on Fluss 1.0.
Dustin and I then used AI tooling (Claude Code) to trace the cause through the Fluss and Iceberg source and to write the throwaway unit test below. We reviewed the findings ourselves.
Observed (log table, 3 buckets, bucket.key = k, every row written with one constant key so all rows land in bucket 0; writer and reader both at parallelism 1; 5 tiering rounds, one Iceberg commit each):
| Printed | seq range | Rows | Came from |
|---|---|---|---|
| 1st | 235–294 | 60 | Iceberg file from tiering round 5 (newest) |
| 2nd | 1–234 | 234 | Iceberg files from rounds 1–4 |
| 3rd | 295–442 | 148 | Fluss log split from offset 294, then live rows |
The enumerator planned 5 lake splits for bucket 0 (one per data file), and the print order matched the split order exactly. The reader had one source subtask and one split fetcher thread, so parallel reading is not the cause. The lake-to-log hand-off at offset 294 had no gap and no overlap.
Expected: within a bucket, rows come out in write (offset) order, as they do for Paimon and for the Fluss log itself. Order across buckets is not expected.
Impact: an event-time job sees newer data first, so the watermark jumps ahead and the older rows that follow arrive late and may be dropped.
Cause
Nothing on the Iceberg read path puts a bucket's files in order, and Iceberg's planFiles() does not return them in commit order.
IcebergSplitPlanner.plan()creates oneIcebergSplitperFileScanTask, in the ordertableScan.planFiles()returns them, and does not sort.LakeSplitGenerator.groupLakeSplits()groups splits by partition and bucket, keeping that order.toLakeSnapshotSplits()then flattens them, also without sorting.FlinkSourceEnumerator.getSplitOwner()sends every split of a bucket to the same subtask.FlinkSourceSplitReaderreads them first-in-first-out from anArrayDeque, finishing all lake splits before it reads the log. So the planner's order is exactly the order in which rows come out.
Iceberg (checked against 1.10.1 source) gives no order to rely on, with or without parallel planning:
ManifestGroupstores the snapshot's data manifests in aHashSet, andGenericManifestFile.hashCode()is the hash of the manifest path, which contains a random UUID. Even sequential planning walks manifests in an arbitrary order that is fixed for a given snapshot.- When there is more than one manifest,
DataTableScan.doPlanFiles()plans them on the worker pool.iceberg.scan.plan-in-worker-pooldefaults to true, and the results are merged through aParallelIterable, so the order also changes from run to run.
Paimon is not affected because Paimon itself sorts a bucket's files by minSequenceNumber (AppendOnlySplitGenerator.splitForBatch, Paimon 1.4.1).
Reproduced in a unit test
Using the existing IcebergSourceTestBase (local Hadoop catalog, Iceberg 1.10.1), the test made 5 commits of one file each into bucket 0, then ran IcebergSplitPlanner.plan() 50 times on the same snapshot. Orders are shown as each file's commit (1 = oldest):
| Planning mode | Distinct orders in 50 runs | Examples |
|---|---|---|
| Worker pool on (default) | 44 and 49 (two JVM runs) | 5,1,2,3,4 (the order seen in the cluster), 3,5,4,1,2, 2,4,3,1,5 |
Worker pool off (ICEBERG_SCAN_PLAN_IN_WORKER_POOL=false) |
1 | 3,5,2,1,4 every time |
So turning off parallel planning only makes the wrong order repeatable. Code has to put the files in order.
How to reproduce on a cluster
- Create a log table that tiers to Iceberg and keeps all rows in one bucket:
CREATE TABLE order_probe (
`k` STRING,
`seq` BIGINT,
`event_time` TIMESTAMP_LTZ(3)
) WITH (
'bucket.num' = '3',
'bucket.key' = 'k',
'table.datalake.enabled' = 'true',
'table.datalake.freshness' = '30s'
);- Write one row per second with a rising
seq(parallelism 1):
CREATE TEMPORARY TABLE probe_gen (`seq` BIGINT) WITH (
'connector' = 'datagen', 'rows-per-second' = '1',
'fields.seq.kind' = 'sequence', 'fields.seq.start' = '1', 'fields.seq.end' = '86400'
);
INSERT INTO order_probe SELECT 'probe-key', `seq`, CURRENT_TIMESTAMP FROM probe_gen;- Wait for at least 2 tiering commits (we waited for 5, about 6 minutes).
- Run a full union read (parallelism 1) and print it:
CREATE TEMPORARY TABLE order_probe_print (
`k` STRING, `seq` BIGINT, `event_time` TIMESTAMP_LTZ(3)
) WITH ('connector' = 'print');
INSERT INTO order_probe_print
SELECT * FROM order_probe /*+ OPTIONS('scan.startup.mode' = 'full') */;seq should rise by exactly 1 on every line. With 5 files there are 120 possible orders and only one is correct, so most runs show the bug.
Environment: Fluss 1.0.0 (3 tablet servers), Flink 1.20, Iceberg 1.10.1 with a REST catalog (Lakekeeper) on S3.
Solution
For log tables, sort each bucket's Iceberg splits into write order in IcebergSplitPlanner.plan(). Which key is correct depends on the table's schema:
| Table | Sort key | Why |
|---|---|---|
Clean schema (default for tables created on 1.0, FIP-27): no __offset column |
The data file's dataSequenceNumber(), using a stable sort |
Each tiering round is one Iceberg commit, so the sequence number follows tiering order. Fluss does not compact clean-schema tables. |
Legacy schema (created before 1.0): has __offset |
Lower bound of __offset per file, the same comparator IcebergRewriteDataFiles already uses when it packs files for compaction |
Fluss compaction commits RewriteFiles without calling dataSequenceNumber(...), so a compacted file, which holds the oldest rows, gets the newest sequence number. Sorting by sequence number would put it last. |
Details checked:
- Sequence numbers are present and distinct per commit. In the test above, the 5 files had data sequence numbers 1–5. Iceberg's default table format is v2.
- Ties are safe with a stable sort. When one commit holds several files for the same bucket (the tiering writer rolls at
write.target-file-size-bytes, 512 MB by default), they share a sequence number. In the test, one commit added three files for bucket 0. In all 100 plans, with the worker pool on and off, they came out in the order they were appended. A commit's new files are written to one manifest, and each manifest is read sequentially. - The legacy path needs column stats. The planner today requests column stats only for filter columns, so it must also call
includeColumnStatsfor__offsetto read its lower bound. If the bound is missing (for example, on very wide tables beyond Iceberg's default limit of 100 columns with inferred metrics), fall back to the sequence number.
Optional follow-up: have Fluss compaction call rewriteFiles.dataSequenceNumber(<sequence number of the snapshot it planned from>), as Spark's use-starting-sequence-number does. New compactions would then keep sequence order too. Tables that are already compacted still need the __offset key.
Tests to add: plan a bucket with several commits (and one commit with several files) and assert the splits come out in commit order. This fails today (see the table above). For legacy tables, also cover the case where the table has been compacted.
Out of scope: order across buckets; bucket-unaware tables, whose lake splits are spread across subtasks by split-id hash; and primary key tables, which we did not examine. fluss-lake-iceberg-1.12 shares IcebergSplitPlanner from fluss-lake-iceberg-common, so the fix covers it too, though we only checked Iceberg 1.10.1 internals.
Are you willing to submit a PR?
- I'm willing to submit a PR!
Activity
polyzos commentedon Nov 6, 2026
Thanks @jaimelopez89 and @dgnester for the detailed analysis.
Indeed, the Iceberg planner returns a bucket's files in no particular order, and Fluss passes that order straight to the reader. The Fluss log and the Paimon path both preserve write order within a bucket, so this should be fixed in Fluss.
Sorting each bucket's lake splits by data sequence number in the planner, and keeping that order when restoring from a checkpoint, is probably the way to go. Flink restores reader splits in arbitrary order, which affects Paimon as well once a bucket spans more than one split. Both changes are cheap, with no extra I/O and no format change.
There are some limitations to this fix, though. Compaction rewrites files without preserving row order inside them, so a fully ordered read is not possible for Iceberg tables that are compacted externally. The sort still bounds the disorder. In a typical setup, each compaction run rewrites only the small files written since the previous run, and its output gets a newer sequence number. Compacted data is therefore read run by run, oldest first, followed by the data written since the last compaction, which is read in order and continues into the log without a gap. Rows can only be out of order within the data rewritten by a single run, roughly one compaction interval, whereas today the disorder spans the bucket's whole history.
The event-time impact described in the issue is also broader than ordering within a bucket, and applies to both lake formats. A reader typically owns several buckets and partitions and reads them one after another. With an idle timeout set, the watermark can run ahead of the buckets not yet read. Order is also lost when a job is rescaled during the lake phase.
Possible follow-ups
For event-time workloads, one option is to make lake reads event-time aware. Each reader would order its lake splits by the minimum value of the watermark column, taken from file statistics, as Iceberg's own Flink source does. This would work across buckets and partitions and rely on data that survives compaction. It works best when compaction sorts by the event-time column (for example, Spark's
rewrite_data_fileswithstrategy => 'sort'), which also removes the remaining disorder within compacted data.For write order on Iceberg, Fluss-owned compaction could follow Paimon's approach. It would merge only files that are adjacent in sequence order, write their rows in that order, and keep the merged file's sequence number within the original range. Fluss auto-compaction is not production-ready yet, and we currently recommend external compaction. This is worth considering as part of the ongoing compaction work.
In the meantime, the docs should state that, for Iceberg, union read preserves per-bucket order for the lake part only on a best-effort basis, and describe the effect of compaction. Tables without a bucket key have no per-bucket order in the lake for either format.
A PR for the sort and the restore fix is welcome. Tests should cover several commits into one bucket, several buckets on one reader, and a restore while lake splits are still pending.
hutiefang76 commentedon Nov 6, 2026
Is anyone already implementing the sort or the pending-split restore part of this? The report says its authors intend to contribute, so I would like to coordinate ownership before starting.
If those parts are available, I'd be happy to take the fix on top of #5075: order Iceberg lake splits within each bucket, preserve the order of unread splits on checkpoint restore, and add regressions for multiple commits, multiple buckets on one reader, and restore with pending lake splits. I would keep the documented best-effort limit for externally compacted Iceberg data explicit. I haven't started a patch or run these regressions.
AI-generated scope and ownership question (Codex); no implementation or test result is claimed.
jaimelopez89 commentedon Nov 19, 2026
The fix is up in #5288. It sorts each bucket's lake splits by data sequence number in the Iceberg planner, and it puts lake snapshot splits back in planning order when the reader's splits are restored.
It also adds the docs note on best-effort order for compacted Iceberg data. The tests cover the three cases asked for: several commits into one bucket, several buckets on one reader, and a restore while lake splits are still pending.