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


##########
core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java:
##########
@@ -438,18 +579,27 @@ public CatalogManager(
   }
 
   /**
-   * Closes the CatalogManager and releases any resources associated with it. 
This method
-   * invalidates all cached catalog instances and clears the cache.
+   * Closes the CatalogManager and invalidates all cached catalog instances. 
Idle resources are
+   * released immediately; resources protected by active leases are released 
when their last lease
+   * is closed.
    */
   @Override
   public void close() {
+    if (!closed.compareAndSet(false, true)) {

Review Comment:
   Addressed in 5bb66e7814. close() now holds the lifecycle write lock 
throughout teardown and sets closed only after listener unregistration, wrapper 
retirement, and graceful pool shutdown complete. Expected cleanup failures are 
contained and logged, so callers never observe an early closed state or a 
partially skipped teardown.



##########
core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java:
##########
@@ -438,18 +579,27 @@ public CatalogManager(
   }
 
   /**
-   * Closes the CatalogManager and releases any resources associated with it. 
This method
-   * invalidates all cached catalog instances and clears the cache.
+   * Closes the CatalogManager and invalidates all cached catalog instances. 
Idle resources are
+   * released immediately; resources protected by active leases are released 
when their last lease
+   * is closed.
    */
   @Override
   public void close() {
+    if (!closed.compareAndSet(false, true)) {
+      return;
+    }
     if (catalogChangeLogListener != null) {
       ((SupportsEntityChangeLog) 
store).unregisterEntityChangeLogListener(catalogChangeLogListener);
       trackLocalMutations = false;
       localMutationCounts.clear();
     }
+    List<CatalogWrapper> wrappers = new 
ArrayList<>(catalogCache.asMap().values());

Review Comment:
   Addressed in 5bb66e7814. Every cache load and publication path, including 
create and alter, now holds the lifecycle read lock; close() holds the write 
lock while snapshotting and invalidating the cache. No wrapper can therefore be 
inserted while the snapshot is taken. I also added deterministic coverage for 
concurrent cache load and publication.



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