[core] Speed up row-id manifest sorting - #9135
Conversation
0add9d0 to
ada84ad
Compare
7d6878a to
38af967
Compare
88f840c to
09c0472
Compare
09c0472 to
f384ec4
Compare
| @Override | ||
| public ByteBuffer encodedRecord() { | ||
| return current ? currentRows.encodedRecord() : null; | ||
| } |
There was a problem hiding this comment.
[P1] Do not copy encoded records across Avro writer schemas
rawBlockCopySupported() prevents whole-block copying when the input writer schema differs from the current manifest schema, but this path still returns the encoded bytes from the source record. writeSelected then passes those bytes to ManifestAvroWriter.writeEncoded, which appends them under the current schema header without transcoding or validation.
An upgraded data-evolution table can have legacy manifests that already contain _FIRST_ROW_ID (so run merge is enabled) but lack a later field such as _WRITE_COLS. Copying such records can produce a malformed manifest; a focused legacy-schema reproduction fails with EOFException when the output is read.
Please fall back to the existing external sorter whenever a source writer schema is not exactly compatible, or fully materialize and re-encode those records with the current schema. Please also add full/minor compaction coverage for a legacy RowID manifest containing fields 0..18 but not _WRITE_COLS. This blocks enabling the optimization in production by default.
What changed
paimon-format/.../avro/primitiveInternalRoworManifestEntryobjectsmanifest-sort.run-merge-optimize.enabledas a fallback switchWhy
Full row-id manifest compaction currently materializes every
ManifestEntry, feeds all entries through the external sorter, and encodes every surviving entry again. Large data-evolution tables therefore spend substantial CPU time, cumulative heap allocation, and temporary-disk I/O in this path even when their manifests already consist of a small number of sorted runs.The new manifest-only Avro path reads just the primitive fields needed for classification and ordering, interns partition data, and merges already-sorted runs directly. When an encoded record or compressed Avro block can be reused safely, it is copied without materializing a full entry or encoding it again. Minor compaction gathers DELETE identities during the same discovery scan, avoiding an extra pass over DELETE manifests. Fragmented input still falls back to the existing bounded external sorter.
Performance
Full compaction benchmark: snapshot 7537
The benchmark uses the production snapshot 7537 metadata fixture on Linux x86_64:
-XmxlimitTotal allocation during sortis cumulative allocation, calculated by summing JVM per-thread allocation deltas across the measured sort interval. It is GC-reclaimable allocation volume, not live heap or RSS.Peak RSSis the maximum resident set reported by/usr/bin/time -vfor the Maven/Surefire benchmark command.Spill values count compressed temporary files created by the sorter only; they exclude source-manifest reads and final output-manifest writes. External sort first wrote 1,080,034,577 bytes across 273 runs. Because this exceeded the 128-file-handle limit, two fan-in operations wrote another 506,977,657 and 1,007,390,265 bytes. The final run-merge path created no sorter spill files.
Production compaction snapshots: 8795–8826
The follow-up benchmark replays all 17 manifest-compaction snapshots in the production metadata window from snapshot 8795 through 8826 on Linux x86_64, without an
-Xmxlimit. Each snapshot contains about 26.6 million entries and 0.65–0.67 GiB of manifest data.Representative snapshots that previously received little or no benefit now avoid external sort:
For the 8795–8810 sequence, the final run completed all 11 snapshots in 48.7 s with a 0.98 GiB process peak RSS. In an isolated 8795 comparison, peak RSS decreased from 7.89 GiB for external sort to 0.96 GiB for run merge, an 8.2x reduction.
The bounded fallback remains active. Snapshot 8824 contains multiple fragmented manifests with 38,722 fragmented entries in one rewrite section, exceeding the 25,000-entry in-memory limit, so it intentionally uses external sort.
Result equivalence
Both snapshot 7537 paths produced exactly 26,095,685 output entries. Their logical encoded-record SHA-256 was identical:
afe6fcdaff7e8b2e7d047c199164c19457ced5b3cb2adaadd32c48cf11a1cdf5Validation
AvroFileFormatTestcases covering primitive projection, nullable/nested fields, reader reuse, and large Zstd blocksManifestFileMetaTestcases covering row-id order, secondary keys, exact DELETE identifiers, raw identity fields, many partitions, fragmented fallback, read amplification, block stats, configured partition fields, missing row-id stats, minor compaction, and single-pass minor DELETE discoveryByteArrayKeyTestcases plus 12 binary-manifest identifier/projection casesmvn -pl paimon-format,paimon-core -am -DskipTests compilewith checkstyle, Spotless, and enforcer enabled