Repository navigation
[CORE] Preserve Java exceptions from memory callbacks - #13563
felipepessoto wants to merge 6 commits into
Conversation
|
Run Gluten Clickhouse CI on x86 |
3ff29f8 to
2984ce1
Compare
|
Run Gluten Clickhouse CI on x86 |
|
Run Gluten Clickhouse CI on x86 |
|
Run Gluten Clickhouse CI on x86 |
2984ce1 to
6b1bf2f
Compare
|
Run Gluten Clickhouse CI on x86 |
6b1bf2f to
cc65fbe
Compare
|
Run Gluten Clickhouse CI on x86 |
|
@felipepessoto The red x86 and Kafka |
cc65fbe to
8ea3b66
Compare
|
Run Gluten Clickhouse CI on x86 |
8ea3b66 to
ddd98ec
Compare
|
Run Gluten Clickhouse CI on x86 |
|
/delta-test |
|
🔄 Delta Spark UT started by @felipepessoto (~2.5 h). View run |
@LuciferYang I can't see any For example, for this PR is seems ok to me:
But when I manually check in my fork, it is actually failing:
|
|
@felipepessoto You're right, and it isn't only for contributors. The three checks were attached to an older PR Bot run on this commit, and the merge box didn't list them. Your rerun also never showed up: reading its jobs kept timing out on GitHub's side. #13644 reports fork runs as commit statuses instead, which show like "Gluten ClickHouse CI" does, and keeps reporting a run whose jobs can't be read. Until it's merged, your fork's Actions tab is the place to check. |
…o allow all actions (#13644) ## What changes are proposed in this pull request? Fixes for #13535's fork status sync, from its first days: - Fork runs are reported as commit statuses, not check runs. A check run joins another workflow run's check suite. On #13563 the three checks sat under an older PR Bot run, and the merge box didn't list them. Check runs from earlier passes are marked neutral after their statuses are written. - If a fork run's jobs can't be read, the status still follows the run. On #13563 each read got a 502, so a rerun was never reported. Jobs are read 30 at a time, and 5xx responses are retried. - A queued run with a started job shows as running. - A fork run with no relevant change no longer checks out a merged commit it never published, which failed docs-only PRs such as #13413. - `CONTRIBUTING.md` asks forks to allow all actions, after #13561's fork allowed only its own. ## How was this patch tested? A unit check of the script with a stubbed GitHub client covers each case above. In luciferyang-ci-demo/gluten, which plays apache/gluten, the statuses show on a [passing PR](https://github.com/luciferyang-ci-demo/gluten/pull/1) and a [failing PR](https://github.com/luciferyang-ci-demo/gluten/pull/3). A fork run with no relevant change now passes `detect-changes`. ## Was this patch authored or co-authored using generative AI tooling? Yes. Generated-by: Claude Opus 5.5 Related issue: #13541
ddd98ec to
68cb0f8
Compare
|
Run Gluten Clickhouse CI on x86 |
…o allow all actions (apache#13644) ## What changes are proposed in this pull request? Fixes for apache#13535's fork status sync, from its first days: - Fork runs are reported as commit statuses, not check runs. A check run joins another workflow run's check suite. On apache#13563 the three checks sat under an older PR Bot run, and the merge box didn't list them. Check runs from earlier passes are marked neutral after their statuses are written. - If a fork run's jobs can't be read, the status still follows the run. On apache#13563 each read got a 502, so a rerun was never reported. Jobs are read 30 at a time, and 5xx responses are retried. - A queued run with a started job shows as running. - A fork run with no relevant change no longer checks out a merged commit it never published, which failed docs-only PRs such as apache#13413. - `CONTRIBUTING.md` asks forks to allow all actions, after apache#13561's fork allowed only its own. ## How was this patch tested? A unit check of the script with a stubbed GitHub client covers each case above. In luciferyang-ci-demo/gluten, which plays apache/gluten, the statuses show on a [passing PR](https://github.com/luciferyang-ci-demo/gluten/pull/1) and a [failing PR](https://github.com/luciferyang-ci-demo/gluten/pull/3). A fork run with no relevant change now passes `detect-changes`. ## Was this patch authored or co-authored using generative AI tooling? Yes. Generated-by: Claude Opus 5.5 Related issue: apache#13541
68cb0f8 to
6c84299
Compare
Velox supplies the JNI allocation listener through a backend factory, as it does for the JNI input iterator, and wraps reserve and unreserve failures so the Java throwable survives the driver. The global listener uses the same factory. If returning reclaimed capacity also fails after a failed reservation, keep the reservation failure and log the second error. The JNI listener never calls Java while an exception is pending: a pending exception fails a reservation, and an unreserve still repays before restoring or propagating it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
7b4d2d0 to
4bc07d5
Compare
Keep irreversible Arrow frees separate from Java block charges, and preserve the first failure across rollback, JNI restoration, and low-memory wrapper construction. Exercise each failure at its caller, including reuse of an outstanding block charge. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
An unreserve exception can arrive after Java has returned some or all of a block. Keep that credit unavailable until the drained pool and Java balance confirm settlement, then require a fresh charge. If the balance is positive or cannot be read, propagate failure rather than guessing. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use the original shared allocators and Java reservation contract. Keep the Velox JNI provider and error precedence on rollback without tracking charged, disputed, or repaid bytes. Compare the Java charge after a callback repays and throws with the plain listener. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve the pending throwable in a guarded JNI entry during ordinary cleanup and arbitration rollback. Keep a completed repayment distinct from a failure to reinstall the throwable, and exercise the worker capture limit and the preallocated-wrapper path. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reject positive growth with the preallocated Velox system error rather than moving an earlier pending throwable into a native exception. A failed best-effort reservation can then return false inside Velox without erasing the exception owed to Java. Cover both optional and required retries after a failed capture. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
JNI exception restoration, low-memory fallbacks, and cross-runtime exception transport require maintainer validation of lifecycle and cleanup guarantees despite reported CI success.
No open issues 🎉
What changed in this PR
Extends the Java exception preservation introduced for native iterators in #13561 to Velox memory callbacks, allowing Spark to receive the original throwable rather than a message-only GlutenException.
Changes:
- Adds backend-specific JNI allocation listener factories and wires Velox listeners into task and global memory managers.
- Preserves pending exceptions through growth rejection, repayment, rollback, and wrapper allocation failures without changing shared memory accounting.
- Adds native and Spark regression tests, reusable allocation-failure injection, and documentation.
| File | Description |
|---|---|
docs/developers/NewToGluten.md |
Documents memory callback exception preservation and failure precedence. |
cpp/velox/tests/VeloxJniAllocationListenerTest.cc |
Tests callback wrapping, pending errors, rollback, and allocation failures. |
cpp/velox/tests/CMakeLists.txt |
Registers the new listener regression test executable. |
cpp/velox/memory/VeloxMemoryManager.cc |
Uses exception-aware reservation rollback. |
cpp/velox/jni/VeloxJniWrapper.cc |
Creates the Velox listener for global memory reservations. |
cpp/velox/jni/VeloxJavaException.h |
Adds fallback wrapping when wrapper allocation fails. |
cpp/velox/jni/VeloxAllocationListener.h |
Declares the Velox listener factory and rollback helper. |
cpp/velox/jni/VeloxAllocationListener.cc |
Implements callback wrapping, pending-error preservation, and rollback handling. |
cpp/velox/compute/VeloxBackend.cc |
Registers the Velox JNI allocation listener factory. |
cpp/velox/CMakeLists.txt |
Includes the new listener implementation in the build. |
cpp/core/tests/utils/TestAllocationFailure.h |
Declares the shared allocation-failure injection flag. |
cpp/core/tests/utils/TestAllocationFailure.cc |
Implements allocation-failure injection for dedicated test executables. |
cpp/core/tests/JavaExceptionAllocationTest.cc |
Reuses the extracted allocation-failure test utility. |
cpp/core/tests/CMakeLists.txt |
Links the shared utility into existing exception tests. |
cpp/core/jni/JniWrapper.cc |
Creates task memory listeners through the backend factory. |
cpp/core/jni/JniCommon.h |
Exposes listener factory APIs and reusable callback methods. |
cpp/core/jni/JniCommon.cc |
Implements factory registration and guarded JNI environment lookup. |
backends-velox/src/test/scala/org/apache/spark/sql/execution/GlutenJniExceptionSuite.scala |
Adds throwable-identity, direct unreserve, and off-heap exhaustion regressions. |
Review effort: Balanced
|
@zhztheplayer @rdtr, this is ready for review. The change follows the JNI input iterator pattern and keeps shared memory accounting unchanged. I would appreciate your review, especially of how the original Java throwable is preserved during reservation and rollback. |


Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
3ef35d12f123b5a5481cc82c448f8abe67a69423↑ Normal charge traces matched the exact base; Spark 3.5 and 4.1 passed with shared and isolated C++ runtimes.
↑ Fork x86 (attempt 2), ARM, and Kafka CI passed on this revision.
↓ No maintainer has reviewed this revision yet.
GlutenException. Onb654a76a1,maybeReservereturned normally to Java after consuming a pre-existing error; the mandatory control retained it.maybeReserveimplementation and object identity at the JNI return.↓ Compound capture, rollback and allocation failures were injected rather than observed in production.
What changes are proposed in this pull request?
Preserve the Java throwable from a Velox memory callback. On
main, a failedReservationListener.reservecan reach Spark as a message-onlyGlutenExceptionbecause the Velox driver sees an ordinary C++ exception. Following the JNI input iterator pattern (#13561), Velox supplies the JNI listener for task and global memory managers and wraps callback errors before the driver sees them. Direct JNI unreserve continues to return the original throwable.In a guarded JNI entry, a pre-existing throwable stays pending for Java. New growth is rejected without invoking Java, even when Velox's best-effort
maybeReservecatches the native error. Repayment still runs: save the throwable locally, clear it for the callback, then restore it. This applies to ordinary cleanup and arbitration rollback. If JNI cannot reinstall the throwable, use the JNI fallback rather than treating a successful repayment as rejected.When rollback also throws, a captured or still-pending reservation error stays primary. On a worker without a JNI return boundary, a failed capture leaves no pending throwable, so a subsequent rollback failure can be reported instead. If capture succeeded but allocating the usual Velox wrapper fails, the preallocated system-error wrapper retains the original as a nested cause.
No shared accounting change:
BlockAllocationListener,ListenableMemoryAllocator, and the JavaReservationListenercontract are unchanged frommain. This PR does not reconcile balances, decide whether a throwing callback repaid memory, or introduce a new rule for future allocations.How was this patch tested?
73dae76e1) returnedGlutenExceptionfor the throwing native operator reservation and Spark off-heap OOM. On this revision, all 11 suite cases passed on Spark 3.5 and 4.1, both with shared libraries and with the JNI listener in a separately initialized private C++ runtime.main, including its residual native estimate after a throwing callback. 30 native exception tests, 12 adjacent memory tests, 14 JNI bridge tests, and all nine listener cases in the isolated-runtime harness passed. Format, license and scalastyle checks passed.Was this patch authored or co-authored using generative AI tooling?
Generated-by: GitHub Copilot 1.0.102-0.unstable.r40949665530.gab1eef5 (GPT-6 Astra)
Generated-by: GitHub Copilot 1.0.106-8.unstable.r43162459260.gbfc9f50 (GPT-6 Astra; post-merge maintenance)
Generated-by: GitHub Copilot 1.0.115-7 (GPT-6.2 Astra; standalone port)
Generated-by: GitHub Copilot 1.0.115-7 (Claude Opus 5.5; rebuild on the backend factory pattern)