[ 
https://issues.apache.org/jira/browse/GEODE-7739?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17241022#comment-17241022
 ] 

ASF GitHub Bot commented on GEODE-7739:
---------------------------------------

kirklund commented on a change in pull request #5778:
URL: https://github.com/apache/geode/pull/5778#discussion_r532882325



##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/ManagementCacheListener.java
##########
@@ -109,8 +108,15 @@ public void afterUpdate(EntryEvent<String, Object> event) {
 
   }
 
-  void markReady() {
-    readyForEvents = true;
+  private void blockUntilReady() {
+    try {
+      readyForEvents.await();
+    } catch (InterruptedException e) {
+      // ignored

Review comment:
       Anytime you catch an InterruptedException, you should reset the 
interrupt bit unless the thread is locally owned and it will actually terminate 
when interrupted:
   ```
   try {
     readyForEvents.await();
   } catch (InterruptedException e) {
     Thread.interrupt();
     // recommended: throw new RunnableException(e); -- use an appropriate 
GemFire exception here
   }
   ```
   @upthewaterspout wrote an article but about this but I'm not sure where it 
is.

##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/NotificationCacheListener.java
##########
@@ -15,100 +15,47 @@
 package org.apache.geode.management.internal;
 
 
+import java.util.concurrent.CountDownLatch;
+
 import javax.management.Notification;
 
-import org.apache.geode.cache.CacheListener;
 import org.apache.geode.cache.EntryEvent;
-import org.apache.geode.cache.RegionEvent;
+import org.apache.geode.cache.util.CacheListenerAdapter;
 
 /**
  * This listener will be attached to each notification region corresponding to 
a member
- *
  */
-public class NotificationCacheListener implements 
CacheListener<NotificationKey, Notification> {
-
-  /**
-   * For the
-   */
-  private NotificationHubClient notifClient;
+public class NotificationCacheListener extends 
CacheListenerAdapter<NotificationKey, Notification> {
 
-  private volatile boolean readyForEvents;
+  private final NotificationHubClient notifClient;
+  private final CountDownLatch readyForEvents;
 
   public NotificationCacheListener(MBeanProxyFactory proxyHelper) {
-
     notifClient = new NotificationHubClient(proxyHelper);
-    this.readyForEvents = false;
-
+    this.readyForEvents = new CountDownLatch(1);
   }
 
   @Override
   public void afterCreate(EntryEvent<NotificationKey, Notification> event) {
-    if (!readyForEvents) {
-      return;
-    }
+    blockUntilReady();
     notifClient.sendNotification(event);
-
-  }
-
-  @Override
-  public void afterDestroy(EntryEvent<NotificationKey, Notification> event) {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void afterInvalidate(EntryEvent<NotificationKey, Notification> event) 
{
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void afterRegionClear(RegionEvent<NotificationKey, Notification> 
event) {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void afterRegionCreate(RegionEvent<NotificationKey, Notification> 
event) {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void afterRegionDestroy(RegionEvent<NotificationKey, Notification> 
event) {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void afterRegionInvalidate(RegionEvent<NotificationKey, Notification> 
event) {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void afterRegionLive(RegionEvent<NotificationKey, Notification> 
event) {
-    // TODO Auto-generated method stub
-
   }
 
   @Override
   public void afterUpdate(EntryEvent<NotificationKey, Notification> event) {
-    if (!readyForEvents) {
-      return;
-    }
+    blockUntilReady();
     notifClient.sendNotification(event);
-
   }
 
-  @Override
-  public void close() {
-    // TODO Auto-generated method stub
-
+  private void blockUntilReady() {
+    try {
+      readyForEvents.await();

Review comment:
       Same problems as described for ManagementCacheListener apply here.

##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/ManagementCacheListener.java
##########
@@ -109,8 +108,15 @@ public void afterUpdate(EntryEvent<String, Object> event) {
 
   }
 
-  void markReady() {
-    readyForEvents = true;
+  private void blockUntilReady() {
+    try {
+      readyForEvents.await();
+    } catch (InterruptedException e) {
+      // ignored

Review comment:
       Also: If you don't rethrow the InterruptedException within a runtime 
exception, then this code probably needs to perform some sort of loop that 
checks a CancelCriterion. Grepping 'catch (InterruptedException' on the Geode 
product code (not tests) should give some good examples.

##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/ManagementCacheListener.java
##########
@@ -33,20 +35,18 @@
 
   private static final Logger logger = LogService.getLogger();
 
-  private MBeanProxyFactory proxyHelper;
+  private final MBeanProxyFactory proxyHelper;
 
-  private volatile boolean readyForEvents;
+  private final CountDownLatch readyForEvents;

Review comment:
       The latch should probably be an instance of StoppableCountDownLatch so 
that it will abort (by throwing) if the cache is closed while threads are 
waiting on the latch. Otherwise, this has the potential to hang.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> JMX managers may fail to federate mbeans for other members
> ----------------------------------------------------------
>
>                 Key: GEODE-7739
>                 URL: https://issues.apache.org/jira/browse/GEODE-7739
>             Project: Geode
>          Issue Type: Bug
>          Components: jmx
>            Reporter: Kirk Lund
>            Assignee: Kirk Lund
>            Priority: Major
>              Labels: GeodeOperationAPI, pull-request-available
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> JMX Manager may fail to federate one or more MXBeans for other members 
> because of a race condition during startup. When ManagementCacheListener is 
> first constructed, it is in a state that will ignore all callbacks because 
> the field readyForEvents is false.
> ----
> Debugging with JMXMBeanReconnectDUnitTest revealed this bug.
> The test starts two locators with jmx manager configured and started. 
> Locator1 always has all of locator2's mbeans, but locator2 is intermittently 
> missing the personal mbeans of locator1. 
> I think this is caused by some sort of race condition in the code that 
> creates the monitoring regions for other members in locator2.
> It's possible that the jmx manager that hits this bug might fail to have 
> mbeans for servers as well as other locators but I haven't seen a test case 
> for this scenario.
> The exposure of this bug means that a user running more than one locator 
> might have a locator that is missing one or more mbeans for the cluster.
> ----
> Studying the JMX code also reveals the existence of *GEODE-8012*.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to