1717
1818//! JNI bridge to the JVM `CometS3CredentialDispatcher` SPI, exposed as
1919//! `object_store::CredentialProvider` (raw Parquet path) and `reqsign_core::ProvideCredential`
20- //! (Iceberg via `opendal`).
21- //!
22- //! ```text
23- //! JVM Native (Rust)
24- //! --- -------------
25- //!
26- //! spark.hadoop.fs.s3a.comet.credential parquet/objectstore/s3.rs (object_store)
27- //! .provider.class execution/operators/iceberg_scan.rs (opendal)
28- //! | |
29- //! v v
30- //! CometS3CredentialDispatcher CometS3CredentialBridge
31- //! ^ |
32- //! | ensureInitialized -> long handle |
33- //! +<--- getCredentialsForPath(handle, ...) ------+
34- //! v
35- //! vendor CometS3CredentialProvider -> CometS3Credentials
36- //! ```
20+ //! (Iceberg via `opendal`). See `docs/source/contributor-guide/s3-credential-provider-design.md`.
3721
3822use crate :: execution:: operators:: ExecutionError ;
3923use crate :: jvm_bridge:: { jni_new_global_ref, jni_static_call, JVMClasses } ;
@@ -61,35 +45,29 @@ use std::time::Duration;
6145/// executor from holding a stale credential for the entire job lifetime.
6246const DEFAULT_EXPIRY_WHEN_UNKNOWN : Duration = Duration :: from_secs ( 300 ) ;
6347
64- /// Once-per-process latch for the "missing expiry" warning; bridges are per-scan so a per-bridge
65- /// latch would log once per scan on the same misbehaving provider .
48+ /// Once-per-process latch for the "missing expiry" warning. Bridges are per-scan, so a per-bridge
49+ /// latch would re- log on every scan .
6650static WARNED_MISSING_EXPIRY : OnceCell < ( ) > = OnceCell :: new ( ) ;
6751
6852/// Access intent forwarded to the Java SPI. Ordinal must match the JVM `CometS3AccessMode` enum.
6953#[ derive( Debug , Clone , Copy ) ]
7054pub enum AccessMode {
7155 Read = 0 ,
72- /// No native write path yet; kept so the SPI contract is complete.
7356 #[ allow( dead_code) ]
7457 Write = 1 ,
7558}
7659
77- /// Per-scan credential provider that delegates to the JVM SPI via JNI.
78- ///
79- /// `handle` is the JVM-allocated identity for the `(provider_class, dispatch_key,
80- /// catalog_properties)` triple, returned by `ensureInitialized` at construction. Per-request
81- /// calls carry `(handle, bucket, path, mode)`, which lets the JVM disambiguate multi-tenant
82- /// providers without re-sending the property bag and saves one JNI string allocation on the hot
83- /// path. `bucket` and `path` are immutable for the bridge's lifetime so we cache them as JNI
84- /// global refs.
60+ /// Per-scan credential provider that delegates to the JVM SPI via JNI. `handle` is the JVM-side
61+ /// identity for the `(provider_class, dispatch_key, catalog_properties)` triple returned by
62+ /// `ensureInitialized`. `bucket_jstr` / `path_jstr` are interned once at construction to avoid
63+ /// per-call `new_string` allocations on the hot path.
8564pub struct CometS3CredentialBridge {
8665 provider_class : String ,
8766 dispatch_key : String ,
8867 bucket : String ,
8968 path : String ,
9069 mode : AccessMode ,
9170 handle : i64 ,
92- /// Cached JNI globals for the two constant String arguments to `getCredentialsForPath`.
9371 bucket_jstr : Arc < Global < JString < ' static > > > ,
9472 path_jstr : Arc < Global < JString < ' static > > > ,
9573}
@@ -108,9 +86,6 @@ impl fmt::Debug for CometS3CredentialBridge {
10886}
10987
11088impl CometS3CredentialBridge {
111- /// Run `ensureInitialized` synchronously and stash the returned handle for the bridge's
112- /// lifetime. `dispatch_key` is the bucket on the Parquet path, the catalog name on the Iceberg
113- /// path. `catalog_properties` is forwarded into the vendor's `initialize(Map)`.
11489 pub fn new (
11590 provider_class : impl Into < String > ,
11691 dispatch_key : impl Into < String > ,
@@ -232,7 +207,7 @@ fn ensure_initialized(
232207}
233208
234209/// Construct a `java.util.HashMap<String,String>` and populate it. Called once per bridge at
235- /// construction (per-scan) , so the per-call HashMap/put cost is amortized away from the hot path.
210+ /// construction, so per-call HashMap/put cost stays off the hot path.
236211fn build_java_string_map < ' a > (
237212 env : & mut jni:: Env < ' a > ,
238213 map : & HashMap < String , String > ,
0 commit comments