prathik-onehouse commented on issue #20603: URL: https://github.com/apache/hudi/issues/20603#issuecomment-6995573969
Hi Siva, following up here on the threshold, as you suggested in #20604. ### Where things stand #20604 now fixes the two defer.init bugs the tightened tests caught on master (partitioned RLI file groups created during the deferral, and a rolled back first commit ending the deferral). With that in, the threshold can build on a deferral that holds. ### What the threshold needs Until the index is built, every commit has to decide whether the latest base files hold at least N records. The open question is how to get that count cheaply. ### Baseline: footer count List the latest base files and read each footer's row count. It is exact, but it costs a listing plus one footer read per base file on every commit until the build, which grows with the table while the deferral lasts. ### What I tried that did not hold up - **Base file bytes / average record size.** `AverageRecordSizeEstimator` only uses commits that wrote more than `hoodie.record.size.estimation.threshold` × `hoodie.parquet.small.file.limit` (100MB by default), checked per commit. A table built from smaller commits falls back to 1024 bytes per record, so a narrow-record table would stay deferred indefinitely, and the estimate itself skips the count that would correct it. - **`numInserts - numDeletes` over the timeline.** `delete_partition` writes no stats, clustering reports rewritten rows as inserts, and archival drops the early commits. - **`numWrites` summed over the timeline.** On COW, `numWrites` is the whole rewritten file, so summing double counts. - **A running counter in table state.** Cheapest to read, but it adds per-commit state that every engine has to maintain, to optimise a phase that ends once the index is built. ### Proposal: file system view for liveness, `numWrites` for counts - The file system view gives the latest base file of each file group, so replaced, clustered and dropped files are already excluded. - Each live base file's row count is the `numWrites` of the write stat that produced it. On the Spark and Java paths that holds for every base file writer: create, the default `FileGroupReaderBasedMergeHandle` (including compaction), row-writer bulk insert and clustering, and binary-copy clustering. - A footer is read only for base files whose commit has been archived, since their write stats are gone. - On MOR only base files count, matching how the issue defines the threshold, so log files are not read. - Flink merges the stats of a file group written more than once in an instant by summing `numWrites`, which can overcount. Flink rejects defer.init today, so I'd keep the threshold Spark and Java only at first, or count footers on Flink. Per commit this reads one commit metadata file per active commit that produced a live base file, plus a footer for each live base file whose commit has been archived. ### Prototype results I compared the two counts in a test-only prototype (Spark, table version 10). **Correctness.** After each of these steps the write-stat count equals the footer count, on COW and MOR, and on COW both equal the table's row count: bulk_insert with and without the row writer, insert into small files, upsert, delete, inline compaction, inline clustering, insert_overwrite, delete_partition, and further inserts after archival (where the archived-commit fallback kicks in). No live base file lacked a write stat. Binary-copy clustering and Flink were not covered. **Cost.** 2,400 base files written by 12 bulk-insert commits, local file system, listing excluded since it is the same for both: | | Footer count | Write-stat count | |---|---|---| | Default archival (12 active commits) | 2,400 footer reads, 2.76 s | 12 commit metadata reads, 11 ms | | Aggressive archival (5 active, 7 archived) | 2,400 footer reads, 2.80 s | 5 commit metadata reads + 1,400 footer reads, 1.63 s | Timings are local, so the read counts are the comparison to go by. On object storage each footer is a remote request. The cost now grows with commits rather than files, except for live files whose commit has been archived, which fall back to footers. That is never worse than the footer count, but a streaming table that stays under the threshold past archival (about 30 commits by default) pays footer reads for most of its older files. For those files, the column stats partition's value count for the record key column (always indexed) could stand in for the footer when column stats are enabled. I have not tried this yet. ### The rest of the design - **Build trigger:** the build runs at the start of the first commit whose count reaches the threshold, through the same path defer.init uses today. - **HFile base files:** reject the threshold at config validation, as you suggested. - **Streaming:** with a threshold the build can land on any later commit. The #20604 tests rerun with a threshold set, plus a streaming case aimed at that commit, cover whether its records reach the index. - **Out of scope here:** p90 sizing for new partitions and the fallback following `hoodie.record.index.update.partition.path` stay as their own changes. ### Questions 1. Does the file system view plus `numWrites` approach look acceptable to you, given these numbers? 2. For files from archived commits: accept footer reads, use column stats value counts when available, or treat a table with archived commits as past the threshold? 3. Is keeping the threshold Spark and Java only at first fine, given the Flink stat merging? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
