mbutrovich commented on code in PR #4309:
URL: https://github.com/apache/datafusion-comet/pull/4309#discussion_r3242718251


##########
common/src/main/java/org/apache/comet/cloud/CometCloudCredentialDispatcher.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.comet.cloud;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ServiceLoader;
+import java.util.stream.Collectors;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// spotless:off
+/*
+ * Architecture Overview:
+ *
+ *                 JVM Side                              |                  
Native Side
+ *   ┌──────────────────────────────────────────┐       |     
┌──────────────────────────────────────────┐
+ *   │     CometCloudCredentialDispatcher       │       |     │        S3 
Object Reading                 │
+ *   │                                          │       |     │                
                          │
+ *   │  ┌────────────────────────────────────┐  │       |     │  
┌────────────────────────────────────┐  │
+ *   │  │  ServiceLoader discovery:          │  │       |     │  │  DataFusion 
      iceberg-rust     │  │
+ *   │  │  META-INF/services/                │  │       |     │  │  
object_store        opendal       │  │
+ *   │  │   o.a.c.cloud.CometCloudCred...    │  │       |     │  
└────────────────────────────────────┘  │
+ *   │  └────────────────────────────────────┘  │       |     │             │  
            │             │
+ *   │              │                           │       |     │             ▼  
            ▼             │
+ *   │              ▼                           │       |     │  
┌────────────────────────────────────┐  │
+ *   │  ┌────────────────────────────────────┐  │       |     │  │   
CometCredentialBridge (Rust)     │  │
+ *   │  │  CometCloudCredentialProvider      │  │       |     │  │    impl 
object_store::             │  │
+ *   │  │   (single instance, cached)        │  │       |     │  │         
CredentialProvider         │  │
+ *   │  └────────────────────────────────────┘  │       |     │  │    impl 
reqsign_core::             │  │
+ *   │              │                           │       |     │  │         
ProvideCredential          │  │
+ *   │              ▼                           │       |     │  
└────────────────────────────────────┘  │
+ *   │  ┌────────────────────────────────────┐  │       |     │               
│                          │
+ *   │  │  .getCredentialsForPath(...)       │◄─┼───────┼─────┼──╗            
▼                          │
+ *   │  └────────────────────────────────────┘  │       |     │  
╔════════════════════════════════════╗  │
+ *   │              │                           │       |     │  ║          
JNI CALL:                 ║  │
+ *   │              ▼                           │       |     │  ║    
getCredentialsForPath(          ║  │
+ *   │  ┌────────────────────────────────────┐  │       |     │  ║      
bucket, path, mode)           ║  │
+ *   │  │  return CometCredentials POJO      │──┼───────┼─────┼─►║             
                       ║  │
+ *   │  │  (access key, secret, token,       │  │       |     │  
╚════════════════════════════════════╝  │
+ *   │  │   region, expiration)              │  │       |     │              │ 
                          │
+ *   │  └────────────────────────────────────┘  │       |     │              ▼ 
                          │
+ *   │                                          │       |     │  
┌────────────────────────────────────┐  │
+ *   │                                          │       |     │  │   
AwsCredential                    │  │
+ *   │                                          │       |     │  │   used to 
sign S3 requests         │  │
+ *   │                                          │       |     │  
└────────────────────────────────────┘  │
+ *   └──────────────────────────────────────────┘       |     
└──────────────────────────────────────────┘
+ *                                                      |
+ *                                              JNI Boundary
+ *
+ * Setup Phase (one-time per executor):
+ * 1. Vendor JAR ships an impl of CometCloudCredentialProvider via 
META-INF/services.
+ * 2. CometCloudCredentialDispatcher resolves it via ServiceLoader on first 
class-load.
+ * 3. Native side caches dispatcher class + static method ID in OnceCell.
+ *
+ * Runtime Phase (per S3 request):
+ * 4. object_store / opendal calls its async credential trait on 
CometCredentialBridge.
+ * 5. Bridge enters JNI, invokes dispatcher.getCredentialsForPath(bucket, 
path, mode).
+ * 6. Provider returns a CometCredentials POJO; vendor may call its own STS / 
authorization service.
+ * 7. Rust reads fields via JNI accessors, returns AwsCredential for request 
signing.
+ */
+// spotless:on
+
+/**
+ * Static entry point invoked from Comet's native code (via JNI) to fetch AWS 
credentials for an S3
+ * request.
+ *
+ * <p>Resolution rules at first class-load:
+ *
+ * <ul>
+ *   <li>Zero impls registered via {@code ServiceLoader} → {@link 
#isProviderRegistered()} returns
+ *       false; native callers fall through to the existing AWS credential 
chain.
+ *   <li>Exactly one impl registered → cached and used for every credential 
request.
+ *   <li>Multiple impls registered → throws {@link IllegalStateException} at 
class-load, failing the
+ *       executor loudly. Operators should remove all but one bridge jar.
+ * </ul>
+ *
+ * <p>Discovery is via classpath only; there is no Comet-specific config knob 
for selecting a
+ * provider. This keeps the credentials Comet uses identical to whatever the 
same JVM would use if a
+ * query fell back to Spark execution mid-flight.
+ */
+public final class CometCloudCredentialDispatcher {

Review Comment:
   Yep, renamed already to `CometS3CredentialDispatcher`.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to