Skip to content

[core][spark] Reduce Data Evolution metadata memory in scans and commits - #11156

Open
JustinBinber wants to merge 8 commits into
apache:masterfrom
JustinBinber:codex/spark-de-metadata-memory-20261114
Open

JustinBinber wants to merge 8 commits into
apache:masterfrom
JustinBinber:codex/spark-de-metadata-memory-20261114

Conversation

@JustinBinber

@JustinBinber JustinBinber commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

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 (default off). 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-size limits 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 71082ea86a and addressed the four additional review findings on e0be601617:

  • Pass the table SchemaManager to the updated CommitScanner test fixture.
  • Keep the ordinary centroid training-source change validation on the successful streaming path, after range/existence checks and before snapshot RowID checks. Updates of indexed source columns reject stale indexes; unrelated-column updates remain valid.
  • Scan budgets smaller than three pages use ordinary planning before allocating the sorter and seal the unused replay store. Two/three-page SELECT and filtering/LIMIT controls pass. This fallback retains the ordinary planner's heap boundary; it does not increase the configured budget.
  • Replay uses two owner-held RandomAccessFile handles with synchronized seek/read and owner close. Cancellation preserves the interrupt flag and cannot close another slice's handles. Buffered cancellation, independent indexed/sequential replay, cleanup and concurrent replay controls pass. Iterators add no file descriptors. Physical reads serialize per store; no SQL performance gain is claimed from this change.

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-4 was 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 (VariantTestBase missing), also reproduced on clean upstream 71082ea86a. 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 from e0be601617.

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. Upstream 3a8e01f35d8f is merged and the SnapshotReaderImpl content conflict is resolved:

  • Spark fallback/chain and non-FileStore wrappers such as audit-log keep their existing planner. Incremental, latest-delta and internal batch modes also keep that planner; each avoids attaching a replay store that it cannot own/seal. Ordinary single-snapshot ALL scans retain replay planning. These fallback paths retain their original memory boundaries.
  • Safe LIMIT reads retain only a prefix of complete streamed dependency groups, without calling the classic materializing planner. This applies only without data predicates, RowID filtering or deletion vectors, using the actual scan state including preconfigured filters. Candidate metadata is still scanned and externally sorted before the prefix is selected; this is not a claim to read only the needed manifests. Provider row counts are not summed, and scan metrics reflect the selected complete groups. A real 29-file LIMIT 1 case fits 1 KiB. Overlapping-manifest regressions explicitly prohibit classic scan.plan() and preserve complete provider groups for limits 1 and 3.
  • Interleaved partitions retain separate packers under one shared pending-file budget. Complete RowID/provider groups are kept intact during eviction. Real partitioned controls recover the ordinary split count, and the global eviction/provider-integrity regression passes.
  • Fewer than six complete sort-buffer pages select ordinary commit conflict checking before allocating either sorter. Four-page configurations remain valid, untouched column files survive partial updates, and stale same-column updates still conflict. This fallback retains the ordinary checker's heap boundary.

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 --check pass. 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 in 62c90e2279 was 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 3d64be92a161a12130ede4f2719fb4df4a1b8844 against fixed clean base b7cfb397de334d56b8c3eaeb60a2cfa9c9cab627, 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.

Base files Mode SQL median seconds vs upstream median
32 upstream 7.950692 +0.00%
32 off 7.737670 -2.68%
32 lightweight 7.800494 -1.89%
32 streaming 8.083136 +1.67%
65536 upstream 150.318557 +0.00%
65536 off 150.177861 -0.09%
65536 lightweight 150.161253 -0.10%
65536 streaming 107.755112 -28.32%

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.

Query Mode Block 1 / 2 seconds midpoint vs upstream
limit20 upstream 7.335341 / 7.705225 +0.00%
limit20 off 7.818479 / 7.580383 +2.38%
limit20 lightweight 7.554195 / 7.460936 -0.17%
limit20 streaming 9.625539 / 9.759117 +28.88%
full upstream 80.374490 / 81.038505 +0.00%
full off 80.288788 / 80.697623 -0.26%
full lightweight 80.344297 / 80.508822 -0.35%
full streaming 82.950126 / 82.899079 +2.75%

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

  • Normal JDK8 Spark3 and JDK17 Spark4.0/4.1 builds; Core 50 focused risk regressions and Spark3 23 SQL/metadata/concurrency regressions passed. Spark4.1 has 11 tests via normal Maven; Spark4.0 has 11 via direct ScalaTest on the actual normal reactor classpath, not a default UT40 Maven claim. Shared warm Maven dependencies were used with separate verified outputs.
  • Automatic upstream CI run 43611962280: 18 successful, 1 skipped. The earlier run exposed missing generated option references; those were regenerated with the repository formatter, and both Core jobs now pass.
  • Independent source/compatibility review completed. Source-only reproduction kit, commands, exact SQL, all results and resource limits reuse the original helper/controller and distinguish fixture SDK origin from the fixed comparison runtime. The assembled kit has not been rerun as a fresh-host package.

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.

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.
@JustinBinber
JustinBinber marked this pull request as ready for review November 14, 2026 17:13
@JustinBinber JustinBinber changed the title [core][spark] Add opt-in metadata memory optimization for Data Evolution MERGE [core][spark] Reduce Data Evolution metadata memory in scans and commits Nov 14, 2026
@JingsongLi
JingsongLi marked this pull request as draft November 15, 2026 15:57
@JustinBinber
JustinBinber marked this pull request as ready for review November 17, 2026 14:20

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants