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


##########
core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java:
##########
@@ -1008,6 +1008,12 @@ private boolean containsUserCreatedSchemas(
    * @throws NoSuchCatalogException If the specified catalog does not exist.
    */
   public CatalogWrapper loadCatalogAndWrap(NameIdentifier ident) throws 
NoSuchCatalogException {
+    CatalogWrapper wrapper = catalogCache.get(ident, 
this::loadCatalogInternal);
+    if (wrapper.catalog() != null) {
+      return wrapper;
+    }
+
+    catalogCache.invalidate(ident);
     return catalogCache.get(ident, this::loadCatalogInternal);

Review Comment:
   Fixed by replacing the unconditional `catalogCache.invalidate(ident)` with 
`catalogCache.asMap().remove(ident, wrapper)`, so only the observed closed 
wrapper is removed. Added 
`testLoadCatalogAndWrapDoesNotInvalidateConcurrentlyReloadedWrapper` to cover 
the concurrent fresh-wrapper case.



##########
core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java:
##########
@@ -1027,6 +1027,37 @@ void testDropCatalogInvalidatesCacheAfterStoreDelete() 
throws Exception {
     
Assertions.assertNull(catalogManager.getCatalogCache().getIfPresent(ident));
   }
 
+  @Test
+  void testDropCatalogReloadsClosedCachedWrapper() throws Exception {
+    NameIdentifier ident = NameIdentifier.of("metalake", 
"closed_cache_drop_test");
+    Map<String, String> props =
+        ImmutableMap.of(
+            "provider",
+            "test",
+            PROPERTY_KEY1,
+            "value1",
+            PROPERTY_KEY2,
+            "value2",
+            PROPERTY_KEY5_PREFIX + "1",
+            "value3");
+
+    Catalog catalog =
+        catalogManager.createCatalog(ident, Catalog.Type.RELATIONAL, provider, 
"comment", props);
+    Assertions.assertDoesNotThrow(() -> catalogManager.disableCatalog(ident));
+    CatalogEntity entity = entityStore.get(ident, EntityType.CATALOG, 
CatalogEntity.class);
+    FieldUtils.writeField(catalog, "entity", entity, true);
+
+    CatalogManager.CatalogWrapper closedWrapper = 
catalogManager.loadCatalogAndWrap(ident);
+    closedWrapper.close();
+    catalogManager.getCatalogCache().put(ident, closedWrapper);

Review Comment:
   Fixed. The redundant `put` was removed and replaced with an assertion that 
the closed wrapper is already cached after `loadCatalogAndWrap(ident)`.



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