yuqi1129 commented on code in PR #15006:
URL: https://github.com/apache/gravitino/pull/15006#discussion_r4596451662


##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/GravitinoJdbcCatalog.java:
##########
@@ -108,6 +122,7 @@ protected TableCatalog createAndInitSparkCatalog(
    */
   @Override
   protected Table loadSparkTable(Identifier ident) {
+    verifyJdbcConnectionUnchanged();

Review Comment:
   [Important] This check runs too late for DDL callers. 
`BaseCatalog.createTable()` calls `createGravitinoTable()` before 
`loadSparkTable()`, and `BaseCatalog.alterTable()` likewise performs the remote 
alteration first. If the catalog settings have already changed, the operation 
can take effect and then report this restart error, leaving the caller with a 
failed operation that actually mutated the database. A focused test confirms 
the create API is invoked before the new exception is thrown; the alter path 
has the same ordering. Could we validate before these external mutations and 
test that rejected operations never invoke the create/alter API? The 
create-order test used a mocked remote API, not a live server DDL operation.



##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/GravitinoJdbcCatalog.java:
##########
@@ -108,6 +122,7 @@ protected TableCatalog createAndInitSparkCatalog(
    */
   @Override
   protected Table loadSparkTable(Identifier ident) {
+    verifyJdbcConnectionUnchanged();

Review Comment:
   [Important] This guard only runs when Spark resolves the table, so an 
already resolved DataFrame can still access the old source. I reproduced this 
with Spark 3.5 and H2: create `df = spark.table(...)`, change the catalog URL, 
then call `df.collectAsList()`. A fresh `spark.table(...)` correctly throws the 
restart error, but the existing DataFrame still reads a row from the old 
database. `SparkJdbcTable.newScanBuilder()` does not revalidate the connection 
settings. Could we also validate when building scans/writes and add a 
regression test using a retained DataFrame? Please explicitly define the 
boundary for plans that have already been built; the current PR description 
promises a check before source access.



##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/GravitinoJdbcCatalog.java:
##########
@@ -124,6 +139,48 @@ protected Table loadSparkTable(Identifier ident) {
     }
   }
 
+  private void verifyJdbcConnectionUnchanged() {
+    Catalog currentCatalog = refreshGravitinoCatalog();
+    Map<String, String> currentOptions =
+        getPropertiesConverter()
+            .toSparkCatalogProperties(
+                new CaseInsensitiveStringMap(sparkCatalogOptions),
+                propsWithSecrets(currentCatalog));
+    applyJdbcCredential(currentCatalog, currentOptions);

Review Comment:
   [Nit] `propsWithSecrets(currentCatalog)` already calls 
`supportsCredentials().getCredentials()`, and `applyJdbcCredential()` 
immediately fetches the credentials again. The real client performs an uncached 
REST request each time; a focused test confirms two credential calls per 
verification. This adds catalog + secrets + two credentials requests to every 
table load, even on a catalog-cache hit. Could we fetch credentials once and 
reuse the result for both property enrichment and JDBC option overrides? Also 
consider lowering the reused `loadCatalog()` success log to DEBUG now that it 
runs on every verification. I verified the call count, but did not benchmark 
throughput.



-- 
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]

Reply via email to