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


##########
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:
   The window was already there before this change: the old code also called 
`GravitinoCatalogManager.get()` and then sent the request on that manager's 
client, so a close in between failed the same way. Getting the manager again 
inside the lock or just before returning still leaves a window between the 
return and the request. The first call after the replacement sees the new 
manager and loads the catalog again, which 
`testCatalogHandleReloadedWhenManagerIsReplaced` covers.



##########
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:
   In Mockito 4.11, `mockito-inline` depends on `mockito-core` and only adds 
the inline mock maker configuration, so nothing is duplicated on the classpath. 
Declaring both is how the other modules do it, for example `core` and 
`spark-connector/v3.5/spark`.



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