Repository navigation
[core][spark] Reduce Data Evolution metadata memory in scans and commits - #11156
JustinBinber wants to merge 8 commits into
Conversation
Add opt-in off, lightweight and streaming metadata modes for many-file Data Evolution operations. Reduce eager decoding and copies, plan complete RowID groups incrementally, replay file metadata and reconcile compact conflict summaries before one atomic Snapshot publication. Keep the feature disabled by default, preserve compatibility paths and document remaining memory and local-disk limits.
JingsongLi
left a comment
There was a problem hiding this comment.
The measured Data Evolution MERGE workload gives this change a concrete end-to-end use case. On the submitted head, 147 Core tests and 21 Spark 3.5.9 cases passed. Merging with the review base also exposed a content conflict in SnapshotReaderImpl. I ran additional real-table controls for the streaming option.
…19/master' into codex/spark-de-memory-review-fixes-20261119 # Conflicts: # paimon-core/src/main/java/org/apache/paimon/table/source/snapshot/SnapshotReaderImpl.java
JingsongLi
left a comment
There was a problem hiding this comment.
The original measured MERGE workload establishes end-to-end value. I integrated this head with current master 6beb23d690, which includes #11290. The clean integration fails test compilation at the outdated CommitScanner constructor. After a one-line adjustment to the local test fixture only, 388 Core and 37 focused Spark 3.5.9 cases passed, including the revised scan compatibility, bounded LIMIT controls, and full MERGE SQL. I did not rerun the original 524,288-file capacity comparison. The targeted checks below found three remaining behavior issues.
Purpose
Spark Data Evolution MERGE and read planning can exhaust Driver heap with many small column files. Metadata accumulates across scan planning, split serialization, task-result decoding and commit preparation; removing one eager collection alone can move the failure later in the same SQL.
Add an opt-in table mode,
data-evolution.metadata-memory-optimization.mode=off|lightweight|streaming(defaultoff). Lightweight reduces eager decoding, copies and overlapping object lifetimes. Streaming additionally sorts/replays metadata, incrementally plans complete RowID dependency groups, and uses compact summaries/external identity reconciliation in the actual commit path. Partial-write tasks produce messages on demand. One atomic Snapshot and existing compatibility contracts are preserved.data-evolution.metadata-memory-optimization.max-disk-sizelimits each metadata store; it is not a global process disk budget.Scope: the planning-to-commit chain required by the reproduced Data Evolution MERGE failure, plus the separately validated controlled wide-table read-planning case. This does not establish repair of the separate production three-million-file SELECT/LIMIT incident or constant memory. Task arrays, retained result bytes, largest messages/groups, RowID summaries and callback/deletion-vector/diagnostic fallback paths remain boundaries.
Review follow-up (current revision)
Integrated upstream
71082ea86aand addressed the four additional review findings one0be601617:Current-source local validation: 120 focused Core cases passed, plus the same inherited pinned-snapshot CommitScanner control passed with a temporary Windows-only local-filesystem fixture adapter. The original traceable-URI fixture is not Windows compatible; that adapter and its bytecode were removed and are not part of the PR. 18 Spark 3.5.9 cases passed through the normal 27-module Maven reactor (scan compatibility, repeated SELECT/LIMIT/partial columns, and full streaming MERGE SQL). Normal formatting/checkstyle/enforcer/licensing checks passed. The official vector SDK snapshot
0.7.0-20261120.003144-4was installed with its original POM and its complete downloaded JAR checked against the repository hash; local source classes were rebuilt, not substituted by a previous SDK.Automatic upstream CI passed for
b74ee68c5f: 19 checks succeeded and 1 skipped.CI follow-up: the preceding run exposed an unchanged upstream Spark 4.3 test-compilation defect (
VariantTestBasemissing), also reproduced on clean upstream71082ea86a. A separate build-only commit adds the same test-scope shared UT tests-jar dependency already used by Spark 4.2, with all transitive dependencies excluded. On JDK 17 / Scala 2.13 / Spark 4.3, normal Maven compiled the shared UT and Spark 4.3 test sources and passed normal formatting/checkstyle/enforcer checks. All 152 Variant cases passed in a bounded 1.5 GiB JVM using that exact reactor test classpath. The final PR head also passed a clean 28-module Maven package with-DskipTests, compiling all shared UT and Spark 4.3 tests; this is build validation and does not add executed test cases to the counts above. Broader local compatibility runs encountered existing Windows file-URI and missing-winutils failures, and one was stopped by the memory-reserve guard; those are not reported as passing full suites. No tests were removed or excluded. Production changes and their validation above remain unchanged frome0be601617.The large-capacity and full-SQL performance measurements below remain bound to their original measured revision; they were not rerun for this correctness follow-up.
Prior review follow-up (
c94e5051d0)The five new review findings are addressed on previous head
c94e5051d0. Upstream3a8e01f35d8fis merged and the SnapshotReaderImpl content conflict is resolved:scan.plan()and preserve complete provider groups for limits 1 and 3.Validation of that prior revision: JDK 8, 87 focused Core tests through the normal Maven reactor with fast-build disabled (zero failures/errors/skips), and 11 real Spark 3.5.9 ScalaTest read cases using the current normal-reactor Core build and the changed Spark source (zero failures/aborts). The Spark run uses actual repository test sources and the known SDK for remaining connector dependencies; it is not a full local Spark Maven reactor result. Scoped non-fast-build Spotless checks and
git diff --checkpass. RED evidence is retained for the reported failures. The exploratory DIFF control also fails with optimization off, revealing an independent DE planning/reader defect. Its correctness fix, including partial-column dependencies and deletion vectors, is tracked separately in #11285; it is not included in this PR or claimed repaired by this revision. The initial LIMIT fallback in62c90e2279was replaced after finding that small row limits do not bound an overlapping manifest group's metadata. Corrected-classpath RED is 28/32 on that revision, with four real failures; the streamed-prefix implementation passes 32/32 and the normal Core reactor passes 87/87. A prior exploratory fixture had a null bucket converter and a mixed runtime classpath; those failed attempts are retained separately. The full 32768-file capacity case was not rerun.Automatic upstream CI for prior revision c94e5051d0 completed successfully on
c94e5051d0: 18 checks succeeded and 1 was skipped. This acceptance belongs to prior revision c94e505; the earlier successful CI below belongs to the originally measured revision.Capacity and exact correctness
The following capacity and performance results were measured on candidate
3d64be92a161a12130ede4f2719fb4df4a1b8844against fixed clean baseb7cfb397de334d56b8c3eaeb60a2cfa9c9cab627, before the current review fixes and upstream merge. They remain results for that measured revision and have not been remeasured on the latest head. Latest-head correctness/build validation is reported separately above.With 524288 real two-row base files, Driver 1 GiB and two 512 MiB Executors, clean upstream fails with Driver heap OOM during scan planning and publishes no Snapshot. Same-input/same-resource streaming completes the full MERGE in 740.262 s and publishes only Snapshot 513. No speedup is calculated against the failure. A separate unmodified-upstream oracle (4 GiB Driver/two 1 GiB Executors, disclosed separately) passes five exact bidirectional checks: full rows, unchanged source, old key/RowID pairs, complete RowID domain and inserted RowID domain (1153433 result rows). Seed/source and earlier Snapshot bytes remain unchanged.
Successful-case performance
One 4-core/16-GiB Ubuntu host, Spark 3.5.9/Scala 2.12.18, JDK17 SQL processes; this is not a multiple-worker-node benchmark. At each scale all 16 measured MERGEs and five-check oracles pass. Four balanced Williams blocks, fixed inputs/SQL/heaps/split settings, fresh private copy and JVM per arm, no concurrent build/archive/analysis during timed blocks. Oracles use a separate 2-GiB Driver and are outside timing. Cache state is not identical/cold; balancing reduces but does not eliminate carryover. All samples are retained.
These four samples per mode do not establish p95, significance or general throughput gains. Streaming's first paired 32-file block is +11.42%; its small-case sampled Driver heap is higher. Larger successful-case gains coexist with increased local writes and commit work. The linked results include every sample, CPU/deserialization/GC, heap/RSS, commit duration, shuffle/Spark spill and common-live process I/O. Spark spill excludes connector-local sort/replay; process I/O is sampled and not exact SQL/connector-only I/O, and raw parent/child counters must not be summed. Exact isolated encoding/planning CPU is unavailable.
Separate controlled SELECT/LIMIT acceptance
Frozen wide input: 32768 real two-row base files, 259 business columns, one 128-column partial update, Snapshot 33 and 72089 result rows. The reader projects all business columns plus
_ROW_ID, and verifies actual values, NULLs, domains and counts. At the same 512-MiB Driver/two 512-MiB Executors, clean fixed-b7 fails both LIMIT 20 and full read with Driver Java heap OOM in Manifest decoding/decompression propagated through read planning. Streaming completes LIMIT 20 (9.573720134 s) and full read (82.889682472 s), without Snapshot/input changes. This is an independent controlled case, not a diagnosis of the production exit137 incident. Five exact bidirectional checks run separately with a 2-GiB Driver through each actual tested reader. The initial streaming controller stopped at an unstarted exact-oracle disk preflight; its successful reads were retained and an exact-only continuation completed. No measurement heap was raised and no query was retried.Successful-case timing gives ALL modes a 2-GiB Driver and two 512-MiB Executors. Exactly two reverse-order blocks (
U F S L/L S F U), fresh JVM/query, same frozen physical input and settings, serial execution without backup/cleanup/build/parsing during either whole block. Data inodes and warm OS caches are reused; order reversal does not equalize caches or fully balance carryover. All 16 queries pass the common consumer; independent exact checks are reused once per mode, outside timing. Two samples per mode/query support descriptive ranges only, not significance or p95. Timers include the common validation consumer.Streaming's LIMIT midpoint is +28.88% (about +2.17 s); full read is +2.75%. These negative timing costs are retained. Full-read sampled Driver heap midpoint is approximately 1093.73 MiB upstream / 539.50 MiB lightweight / 381.00 MiB streaming; sampled peaks can miss real peaks. Streaming common-live Driver writes increase by about 120 MiB in both query types. They include runtime/log work and are not exact connector-only bytes. All query event logs report zero Spark shuffle/spill; that does not exclude connector-local sort/replay. Default off has LIMIT +2.38% / full -0.26% midpoint observations, not proof of zero overhead. All raw read samples, CPU/GC/deserialization, per-JVM heap/RSS/I/O, correctness bindings and limitations are included. No throughput claim is made from this single-host experiment.
Validation and reproduction of the measured revision
The controlled SELECT/LIMIT acceptance above is independent of MERGE acceptance. The production three-million-file exit137 incident remains unclassified and is not claimed fixed.