Copilot commented on code in PR #11407:
URL: https://github.com/apache/gravitino/pull/11407#discussion_r3347386821
##########
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:
`catalogCache.invalidate(ident)` unconditionally removes (and closes via
removalListener) whatever value is currently cached for `ident`. In a
concurrent reload scenario, that can close a freshly reloaded wrapper inserted
between the initial `get` and this invalidate. Prefer a conditional remove so
only the observed closed wrapper is removed, avoiding closing a concurrently
refreshed wrapper.
##########
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:
`loadCatalogAndWrap(ident)` already populates the cache. After
`closedWrapper.close()`, the cached value for `ident` is already the closed
wrapper, so `catalogManager.getCatalogCache().put(ident, closedWrapper);` is
redundant and may trigger an unnecessary replacement/removal callback. Consider
asserting the closed wrapper is in cache instead of re-putting it.
--
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]