Copilot commented on code in PR #14657:
URL: https://github.com/apache/gravitino/pull/14657#discussion_r4478233128


##########
flink-connector/v2.2/flink/build.gradle.kts:
##########
@@ -142,6 +142,7 @@ dependencies {
   testImplementation(libs.metrics.core)
   testImplementation(libs.minikdc)
   testImplementation(libs.mockito.core)

Review Comment:
   `mockito-inline` is typically used as a replacement for `mockito-core` (it 
provides the inline mock maker). Keeping both can lead to redundant/duplicated 
artifacts on the test classpath and makes dependency resolution harder to 
reason about. Prefer swapping `libs.mockito.core` for `libs.mockito.inline` 
(and apply the same change to the other Flink version modules updated in this 
PR) unless there’s a concrete reason to keep both.



##########
flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -1216,7 +1218,22 @@ protected static Representation[] 
buildSqlRepresentation(String dialect, String
   }
 
   protected Catalog catalog() {
-    return GravitinoCatalogManager.get().getGravitinoCatalogInfo(getName());
+    // The Gravitino client has no catalog cache and Flink calls catalog() 
before nearly every
+    // schema or table request, so load the catalog once per instance. Load it 
again when the
+    // shared manager has been replaced, since the handle keeps using the REST 
client of the
+    // manager that loaded it.
+    GravitinoCatalogManager manager = GravitinoCatalogManager.get();
+    LoadedCatalog loaded = loadedCatalog;
+    if (loaded == null || loaded.manager != manager) {
+      synchronized (this) {
+        loaded = loadedCatalog;
+        if (loaded == null || loaded.manager != manager) {
+          loaded = new LoadedCatalog(manager, 
manager.getGravitinoCatalogInfo(getName()));
+          loadedCatalog = loaded;
+        }
+      }
+    }
+    return loaded.catalog;

Review Comment:
   There’s a race window where `GravitinoCatalogManager.get()` can start 
returning a new manager after line 1225, but this call can still return a 
catalog handle loaded from the old manager (or skip reload because it compares 
against the stale `manager` local). If the old manager has been closed, 
returning a handle bound to its REST client can fail. Consider re-fetching the 
manager inside the synchronized block (and using that manager for the second 
check/load), or performing an additional `GravitinoCatalogManager.get()` check 
immediately before returning to ensure the returned handle matches the current 
manager.



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