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

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

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



##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/ManagementCacheListener.java
##########
@@ -18,35 +18,34 @@
 
 import org.apache.logging.log4j.Logger;
 
+import org.apache.geode.CancelCriterion;
 import org.apache.geode.cache.EntryEvent;
 import org.apache.geode.cache.util.CacheListenerAdapter;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
+import org.apache.geode.internal.util.concurrent.StoppableCountDownLatch;
 import org.apache.geode.logging.internal.log4j.api.LogService;
 
 /**
  * This listener is attached to the Monitoring Region to receive any addition 
or deletion of MBEans
- *
- * It updates the last refreshed time of proxy once it gets the update request 
from the Managed Node
- *
- *
+ * <p>
+ * It updates the last refreshed time of proxy once it gets the update request 
from the Managed
+ * Node
  */
 public class ManagementCacheListener extends CacheListenerAdapter<String, 
Object> {
 
   private static final Logger logger = LogService.getLogger();
+  private final MBeanProxyFactory proxyHelper;
+  private final StoppableCountDownLatch readyForEvents;
 
-  private MBeanProxyFactory proxyHelper;
-
-  private volatile boolean readyForEvents;
-
-  public ManagementCacheListener(MBeanProxyFactory proxyHelper) {
+  public ManagementCacheListener(MBeanProxyFactory proxyHelper,
+      InternalCacheForClientAccess cache) {
     this.proxyHelper = proxyHelper;
-    this.readyForEvents = false;
+    this.readyForEvents = new StoppableCountDownLatch(new 
CacheListenerCancelCriterion(cache), 1);
   }
 
   @Override
   public void afterCreate(EntryEvent<String, Object> event) {
-    if (!readyForEvents) {
-      return;
-    }
+//    blockUntilReady();

Review comment:
       new dead code.

##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/FederatingManager.java
##########
@@ -459,35 +481,18 @@ public boolean hasOwnStats() {
             if (!proxyNotificationRegionCreated) {
               // Destroy the proxy region if proxy notification region is not 
created
               proxyMonitoringRegion.localDestroyRegion();
+              if (logger.isDebugEnabled()) {
+                logger.debug(" Failed to create proxy notification region,"
+                        + "destroying proxy monitoring region with name : {}",
+                    proxyMonitoringRegion.getName());
+              }
             }
           }
 
-          if (logger.isDebugEnabled()) {
-            logger.debug("Management Region created with Name : {}",
-                proxyMonitoringRegion.getName());
-            logger.debug("Notification Region created with Name : {}",
-                proxyNotificationRegion.getName());
-          }
-
           // Only the exception case would have destroyed the proxy
           // regions. We can safely proceed here.
-          repo.putEntryInMonitoringRegionMap(member, proxyMonitoringRegion);
           repo.putEntryInNotifRegionMap(member, proxyNotificationRegion);
-          try {
-            if (!running) {
-              return;
-            }
-            proxyFactory.createAllProxies(member, proxyMonitoringRegion);
-
-            managementCacheListener.markReady();
-            notifListener.markReady();
-          } catch (Exception e) {
-            if (logger.isDebugEnabled()) {
-              logger.debug("Error During GII Proxy creation", e);
-            }
-
-            throw new ManagementException(e);
-          }
+//          notifListener.markReady();  //@todo was dependent on proxies for 
monitoring region being created before we moved it

Review comment:
       new dead code. please remove... No new todo's please submit a bug.

##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/NotificationCacheListener.java
##########
@@ -15,100 +15,76 @@
 package org.apache.geode.management.internal;
 
 
+
 import javax.management.Notification;
 
-import org.apache.geode.cache.CacheListener;
+import org.apache.geode.CancelCriterion;
 import org.apache.geode.cache.EntryEvent;
-import org.apache.geode.cache.RegionEvent;
+import org.apache.geode.cache.util.CacheListenerAdapter;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
+import org.apache.geode.internal.util.concurrent.StoppableCountDownLatch;
 
 /**
  * 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 StoppableCountDownLatch readyForEvents;
 
-  public NotificationCacheListener(MBeanProxyFactory proxyHelper) {
-
-    notifClient = new NotificationHubClient(proxyHelper);
-    this.readyForEvents = false;
+  public NotificationCacheListener(InternalCacheForClientAccess cache,
+      MBeanProxyFactory proxyHelper) {
+    notifClient =
+        new NotificationHubClient(proxyHelper);
 
+    this.readyForEvents =
+        new StoppableCountDownLatch(new CacheListenerCancelCriterion(cache), 
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
-
+  public void afterUpdate(EntryEvent<NotificationKey, Notification> event) {
+    blockUntilReady();
+    notifClient.sendNotification(event);
   }
 
-  @Override
-  public void afterRegionDestroy(RegionEvent<NotificationKey, Notification> 
event) {
-    // TODO Auto-generated method stub
-
+  private void blockUntilReady() {

Review comment:
       unused method

##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/ManagementCacheListener.java
##########
@@ -104,13 +102,41 @@ public void afterUpdate(EntryEvent<String, Object> event) 
{
       if (logger.isDebugEnabled()) {
         logger.debug("Proxy Update failed for {} with exception {}", 
objectName, e.getMessage(), e);
       }
-
     }
+  }
 
+  private void blockUntilReady() {

Review comment:
       unused method

##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/NotificationCacheListener.java
##########
@@ -15,100 +15,76 @@
 package org.apache.geode.management.internal;
 
 
+
 import javax.management.Notification;
 
-import org.apache.geode.cache.CacheListener;
+import org.apache.geode.CancelCriterion;
 import org.apache.geode.cache.EntryEvent;
-import org.apache.geode.cache.RegionEvent;
+import org.apache.geode.cache.util.CacheListenerAdapter;
+import org.apache.geode.internal.cache.InternalCacheForClientAccess;
+import org.apache.geode.internal.util.concurrent.StoppableCountDownLatch;
 
 /**
  * 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 StoppableCountDownLatch readyForEvents;
 
-  public NotificationCacheListener(MBeanProxyFactory proxyHelper) {
-
-    notifClient = new NotificationHubClient(proxyHelper);
-    this.readyForEvents = false;
+  public NotificationCacheListener(InternalCacheForClientAccess cache,
+      MBeanProxyFactory proxyHelper) {
+    notifClient =
+        new NotificationHubClient(proxyHelper);
 
+    this.readyForEvents =
+        new StoppableCountDownLatch(new CacheListenerCancelCriterion(cache), 
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
-
+  public void afterUpdate(EntryEvent<NotificationKey, Notification> event) {
+    blockUntilReady();
+    notifClient.sendNotification(event);
   }
 
-  @Override
-  public void afterRegionDestroy(RegionEvent<NotificationKey, Notification> 
event) {
-    // TODO Auto-generated method stub
-
+  private void blockUntilReady() {
+    try {
+      readyForEvents.await();
+    } catch (InterruptedException e) {
+      Thread.interrupted();
+      throw new RuntimeException(e);
+    }
   }
 
-  @Override
-  public void afterRegionInvalidate(RegionEvent<NotificationKey, Notification> 
event) {
-    // TODO Auto-generated method stub
-
+  void markReady() {

Review comment:
       unused.

##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/ManagementCacheListener.java
##########
@@ -76,16 +75,15 @@ public void afterDestroy(EntryEvent<String, Object> event) {
             e);
       }
     }
-
   }
 
   @Override
   public void afterUpdate(EntryEvent<String, Object> event) {
+//    blockUntilReady();

Review comment:
       new dead code.

##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/ManagementCacheListener.java
##########
@@ -59,11 +58,11 @@ public void afterCreate(EntryEvent<String, Object> event) {
         logger.debug("Proxy Create failed for {} with exception {}", 
objectName, e.getMessage(), e);
       }
     }
-
   }
 
   @Override
   public void afterDestroy(EntryEvent<String, Object> event) {
+//    blockUntilReady();

Review comment:
       new dead code.

##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/FederatingManager.java
##########
@@ -407,11 +406,42 @@ public boolean hasOwnStats() {
           monitorFactory.setDataPolicy(DataPolicy.REPLICATE);
           monitorFactory.setConcurrencyChecksEnabled(false);
           ManagementCacheListener managementCacheListener =
-              new ManagementCacheListener(proxyFactory);
+              new ManagementCacheListener(proxyFactory, cache);
           monitorFactory.addCacheListener(managementCacheListener);
           monitorFactory.setIsUsedForMetaRegion(true);
           monitorFactory.setCachePerfStatsHolder(monitoringRegionStats);
 
+          Region<String, Object> proxyMonitoringRegion;
+
+          if (!running) { return; }
+
+          try {
+            proxyMonitoringRegion = 
monitorFactory.create(monitoringRegionName);
+            if (logger.isDebugEnabled()) {
+              logger.debug("Monitoring Region created with Name : {}",
+                  proxyMonitoringRegion.getName());
+            }
+          } catch (TimeoutException | RegionExistsException e) {
+            if (logger.isDebugEnabled()) {
+              logger.debug("Error During Internal Region creation", e);
+            }
+            throw new ManagementException(e);
+          }
+
+          repo.putEntryInMonitoringRegionMap(member, proxyMonitoringRegion);
+          if (!running) { return; }
+
+          try {
+            proxyFactory.createAllProxies(member, proxyMonitoringRegion);
+//            managementCacheListener.markReady();

Review comment:
       new dead code

##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/ManagementCacheListener.java
##########
@@ -104,13 +102,41 @@ public void afterUpdate(EntryEvent<String, Object> event) 
{
       if (logger.isDebugEnabled()) {
         logger.debug("Proxy Update failed for {} with exception {}", 
objectName, e.getMessage(), e);
       }
-
     }
+  }
 
+  private void blockUntilReady() {
+    try {
+      readyForEvents.await();
+    } catch (InterruptedException e) {
+      Thread.interrupted();
+      throw new RuntimeException(e);
+    }
   }
 
   void markReady() {

Review comment:
       unused method




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