You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "comphead (via GitHub)" <gi...@apache.org> on 2026/08/05 17:23:34 UTC
[PR] chore: load Comet lazily [datafusion-comet]
comphead opened a new pull request, #5275:
URL: https://github.com/apache/datafusion-comet/pull/5275
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #5724.
## Rationale for this change
Make the native library load lazily. The library is only loaded when a code path that actually needs JNI executes:
- Remove the static-initializer `load()` call.
- Add a `protected NativeBase()` constructor that calls a new `ensureLoaded()` helper, so `new Native()` (the subclass used by every native code path) triggers the load.
- Make `isLoaded()` call `ensureLoaded()` so `CometSparkSessionExtensions.isCometLoaded` (already gated on `COMET_ENABLED` etc.) triggers the load only when Comet is confirmed enabled.
- Change `releaseNative()` to read the `loaded` field directly instead of going through `isLoaded()`, so plugin shutdown never lazy-loads a library that was never used. Wrap `release()` in try/catch so
shutdown never propagates.
- Wrap the two public static native entry points (`isFeatureEnabled`, `isObjectStoreSchemeSupported`) so they call `ensureLoaded()` before invoking the renamed private native methods `nativeIsFeatureEnabled`
/ `nativeIsObjectStoreSchemeSupported`. This keeps the public API stable while avoiding `UnsatisfiedLinkError`.
- Rename the corresponding JNI symbols in `native/core/src/lib.rs` to match.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: load Comet lazily [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #5275:
URL: https://github.com/apache/datafusion-comet/pull/5275#discussion_r3722706574
##########
native/core/src/lib.rs:
##########
@@ -142,7 +142,7 @@ const LOG_PATTERN: &str = "{d(%y/%m/%d %H:%M:%S)} {l} {f}: {m}{n}";
/// * `1` (true) if the feature is enabled
/// * `0` (false) if the feature is disabled or unknown
#[no_mangle]
-pub extern "system" fn Java_org_apache_comet_NativeBase_isFeatureEnabled(
Review Comment:
Why does the function need to be renamed? It seems redundant to have `native` in the name twice?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: load Comet lazily [datafusion-comet]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #5275:
URL: https://github.com/apache/datafusion-comet/pull/5275#issuecomment-5195076597
please review it carefully
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: load Comet lazily [datafusion-comet]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #5275:
URL: https://github.com/apache/datafusion-comet/pull/5275#discussion_r3722739434
##########
native/core/src/lib.rs:
##########
@@ -142,7 +142,7 @@ const LOG_PATTERN: &str = "{d(%y/%m/%d %H:%M:%S)} {l} {f}: {m}{n}";
/// * `1` (true) if the feature is enabled
/// * `0` (false) if the feature is disabled or unknown
#[no_mangle]
-pub extern "system" fn Java_org_apache_comet_NativeBase_isFeatureEnabled(
Review Comment:
it is, yes
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: load Comet on demand [datafusion-comet]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead closed pull request #5275: chore: load Comet on demand
URL: https://github.com/apache/datafusion-comet/pull/5275
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: load Comet on demand [datafusion-comet]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #5275:
URL: https://github.com/apache/datafusion-comet/pull/5275#issuecomment-5198352152
> This seems like a complex/risky change just to suppress a log line saying that the driver has loaded. Does it matter that the driver loads even if Comet is disabled? If the user doesn't want the driver to load then they could just not specify the driver as a plugin in the first place?
its more than 1 line, so if Comet disabled the static init still calls
```
NativeBase.load()
```
which effectively preloads the Comet codebase, but doesn't enable it. It might confuse the user with Comet related entries even if Comet is disabled. Some cases were reported with failing on Comet class linking however comet was disabled in the first place.
However the change is risky, and if you like I can split it into 2 PRs, simple hide message for now, and second discuss how to behave correctly for Comet code eager load
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: load Comet lazily [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #5275:
URL: https://github.com/apache/datafusion-comet/pull/5275#issuecomment-5195567041
Flagging one ordering risk with moving `load()` out of the static initializer, since it's subtle and not visible in the diff.
`load()` calls `setArrowProperties()`, which sets `arrow.enable_unsafe_memory_access` and `arrow.enable_null_check_for_get`. Arrow reads both in **static initializers** (`BoundsChecking`, `NullCheckingForGet`), so they only take effect if they're set before the corresponding Arrow class is initialized. Setting them afterwards is silently ignored — no warning, no error, just the non-default behavior quietly persisting.
That was previously guaranteed by `NativeBase`'s static block firing on first touch of the class. After this PR the properties are set at the first `new Native()` instead, so correctness now depends on `new Native()` running before any Arrow vector work on every path, on every executor.
Small repro against arrow-vector 19.0.0 showing the latch is real:
```java
// vectorFirst: touch an IntVector, then set the property
IntVector v = new IntVector("x", allocator);
v.allocateNew(1); v.set(0, 1); v.get(0); v.close();
System.setProperty("arrow.enable_null_check_for_get", "false");
// -> NULL_CHECKING_ENABLED = true (property ignored)
// propFirst: set the property, then touch the vector
// -> NULL_CHECKING_ENABLED = false (property honored)
```
To be clear about scope, two things bound this:
- Comet relocates Arrow to `org.apache.comet.shaded.arrow`, so Spark's own Arrow usage can't latch Comet's copy. Only Comet code touching Comet's Arrow matters.
- In the paths I checked the ordering does still hold — e.g. `CometExecIterator` and `CometBlockStoreShuffleReader` both construct `new Native()` immediately before `new NativeUtil()`.
So I'm not claiming a live bug. The concern is that a previously structural guarantee has become an incidental one that nothing enforces or documents: any future path that touches Arrow before instantiating `Native` would silently lose these settings, and the symptom would be a quiet performance regression rather than a failure. Worth either a comment at the `new Native()` sites noting the ordering is load-bearing, or setting the Arrow properties somewhere that doesn't depend on native-library load at all — they're pure JVM system properties and don't actually need the library.
Two smaller notes while I was in here:
- `ensureLoaded()` latches `loadErr` permanently and `setLoaded()` doesn't clear it, which breaks it as a test reset. `CometSparkSessionExtensionsSuite` fails on this branch — the `isCometLoaded` test sets `os.name=foo` to force a load failure, caches the throwable, and the next test (`isCometLoaded requires CometShuffleManager when shuffle.enabled=true`) then rethrows the stale error and fails with `was false`. I ran it locally with the native lib built: 7/7 on `main`, 6/7 here, and 7/7 again after adding `loadErr = null;` to `setLoaded`.
- The description says `Closes #5724`, but that issue doesn't exist — I think you want #5274, otherwise it won't auto-close.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: load Comet lazily [datafusion-comet]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #5275:
URL: https://github.com/apache/datafusion-comet/pull/5275#issuecomment-5196947980
Thanks @andygrove I also see tests failed because Comet initialized multiple times, it should be initialized once may be static but only if Comet is enabled. Moving this to draft for now
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: load Comet on demand [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #5275:
URL: https://github.com/apache/datafusion-comet/pull/5275#discussion_r3724487266
##########
spark/src/main/java/org/apache/comet/NativeBase.java:
##########
@@ -53,6 +53,28 @@ public abstract class NativeBase {
private static final AtomicBoolean released = new AtomicBoolean(false);
static {
+ // Arrow's BoundsChecking / NullCheckingForGet latch these in their static initializers, so
+ // later writes are silently ignored. Set them here (not in load()) so ordering does not
+ // depend on which Comet path runs first. These are pure JVM properties, no native lib needed.
+ if (!(boolean) CometConf.COMET_DEBUG_ENABLED().get()) {
Review Comment:
The value of `COMET_DEBUG_ENABLED` can change over the lifetime of the driver - not sure of the impact here
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: load Comet on demand [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #5275:
URL: https://github.com/apache/datafusion-comet/pull/5275#issuecomment-5198063655
This seems like a complex/risky change just to suppress a log line saying that the driver has loaded. Does it matter that the driver loads even if Comet is disabled? If the user doesn't want the driver to load then they could just not specify the driver as a plugin in the first place?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org