dpol1 commented on code in PR #3017:
URL: https://github.com/apache/hugegraph/pull/3017#discussion_r3209101567


##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/cache/CachedGraphTransaction.java:
##########
@@ -184,17 +185,29 @@ private void listenChanges() {
             }
             return false;
         };
-        if (graphCacheListenStatus.putIfAbsent(this.params().spaceGraphName(), 
true) == null) {
-            EventHub graphEventHub = this.params().graphEventHub();
+        EventHub graphEventHub = this.params().graphEventHub();
+        EventListener previous =
+                graphCacheEventListeners.putIfAbsent(
+                        this.params().spaceGraphName(), listener);
+        if (previous == null) {
+            this.cacheEventListener = listener;
+            this.registeredCacheEventListener = true;
             graphEventHub.listen(Events.CACHE, this.cacheEventListener);
+        } else {
+            this.cacheEventListener = previous;
+            this.registeredCacheEventListener = false;
         }
     }
 
     private void unlistenChanges() {
         String graphName = this.params().spaceGraphName();
-        if (graphCacheListenStatus.remove(graphName) != null) {
+        if (this.registeredCacheEventListener) {
             EventHub graphEventHub = this.params().graphEventHub();
-            graphEventHub.unlisten(Events.CACHE, this.cacheEventListener);
+            if (graphCacheEventListeners.remove(graphName,
+                                                this.cacheEventListener)) {
+                graphEventHub.unlisten(Events.CACHE, this.cacheEventListener);
+            }
+            this.registeredCacheEventListener = false;

Review Comment:
     Both fair, thanks.                                                         
                                                                                
           
                                                                          
   1. `storeEventListenStatus` - same ownership bug, the `putIfAbsent` in 
`finally` is a workaround. Follow-up PR with whatever ownership model we land 
on.                 
      
   2. Owner-first-close - realistic, yeah. Two options: ref-counted holder, or 
stop unregistering on tx close (cache is already a `CacheManager` singleton per 
`spaceGraphName`, so listener lifetime = graph, not tx; cleanup moves to graph 
dispose). I'd lean toward the second - kills the race by killing the owner 
concept.
                                                                                
                                                                                
           
     Wouldn't add a test pinning current behavior - codifies a limitation. Real 
test needs the fix first.                                                       
           
      
     #3012 is the action-name + `notifyExcept` fix, so my preference is to 
merge this as-is and do ownership in a follow-up. Can fold either fix in here 
instead - your call.  



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to