You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/02/16 16:39:37 UTC

[GitHub] [geode] kamilla1201 opened a new pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

kamilla1201 opened a new pull request #6037:
URL: https://github.com/apache/geode/pull/6037


   Thank you for submitting a contribution to Apache Geode.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   - [ ] Does `gradlew build` run cleanly?
   
   - [ ] Have you written or updated unit tests to verify your changes?
   
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   
   ### Note:
   Please ensure that once the PR is submitted, check Concourse for build issues and
   submit an update to your PR as soon as possible. If you need help, please send an
   email to dev@geode.apache.org.
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r580636410



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);
   }
 
   @Override
   public Set<ID> getMembersNotShuttingDown() {
-    latestViewReadLock.lock();
-    try {
-      return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
+    synchronized (shutdownMembers) {

Review comment:
       Previously reading threads waited for the `latestViewReadLock`.
   
   But also there was previously a latent bug here, to wit, puts to the non-concurrent collection `shutdownMembers` were protected (via synchronization on the collection) whereas the read access to that collection by the `filter()` loop here was not protected via synchronization.
   
   I think synchronization here is a valid fix for that problem.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] bschuchardt commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
bschuchardt commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r582353294



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);

Review comment:
       @pivotal-jbarrett shutdownMembers and memberShutdown are not required to be in sync.  The memberShutdown invocation informs GMSJoinLeave so it can record a LeaveRequest in case this is the membership coordinator or that it should become one.
   The latestViewLock is for protecting the data used in processView() from being altered while a new view is being prepared.  The shutdownMembers field isn't used in processView() and so doesn't need to be protected by this lock.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r579406651



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -273,6 +273,9 @@ boolean isDistributionMessage() {
   /**
    * Members that have sent a shutdown message. This is used to suppress suspect processing that
    * otherwise becomes pretty aggressive when a member is shutting down.
+   *
+   * Accesses to this map should be synchronized on the map to avoid concurrent
+   * modification exceptions

Review comment:
       @bschuchardt points out that this won't work by itself since we'd lose the bounding behavior of the `BoundedLinkedHashMap`. It's ensuring that the collection never holds more than 1000 items. And it's the 1000 most-recent ones.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r579391765



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -273,6 +273,9 @@ boolean isDistributionMessage() {
   /**
    * Members that have sent a shutdown message. This is used to suppress suspect processing that
    * otherwise becomes pretty aggressive when a member is shutting down.
+   *
+   * Accesses to this map should be synchronized on the map to avoid concurrent
+   * modification exceptions

Review comment:
       Since we only ever `shutdownMembers.put(id, id)` this can be a `Set<ID>`. It needn't be a map.
   
   Furthermore, if we made it a concurrent map-based set, we could eliminate all the synchronization below.
   
   This declaration could become:
   
   ```
   private final Set<ID> shutdownMembers = ConcurrentHashMap.newKeySet();
   ```
   
   Then code below like this:
   
   ```
       synchronized (shutdownMembers) {
         if (!shutdownMembers.containsKey(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
       }
   
   ```
   
   changes to this:
   
   ```
         if (!shutdownMembers.contains(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
   ```
   
   and code below like this:
   
   ```
       synchronized (shutdownMembers) {
         return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
             .collect(
                 Collectors.toSet());
       }
   ```
   
   changes to code like this:
   
   ```
       final Set<ID> membersNotShuttingDown = new HashSet<ID>(latestView.getMembers());
       final Set<ID> shutdownMembersStable = this.shutdownMembers;
       membersNotShuttingDown.removeIf(shutdownMembersStable::contains);
       return membersNotShuttingDown;
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] pivotal-jbarrett commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r580687603



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);
   }
 
   @Override
   public Set<ID> getMembersNotShuttingDown() {
-    latestViewReadLock.lock();
-    try {
-      return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
+    synchronized (shutdownMembers) {

Review comment:
       Doing so also allows you to make the "not shutting down" members list cacheable rather than creating a new list every time the method is called.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] kamilla1201 commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
kamilla1201 commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r583993886



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);
   }
 
   @Override
   public Set<ID> getMembersNotShuttingDown() {
-    latestViewReadLock.lock();
-    try {
-      return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
+    synchronized (shutdownMembers) {

Review comment:
       @pivotal-jbarrett We'll consider creating another ticket to optimize the method, as you said. For now, I replaced the synchronized blocks with read/write locks.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] pivotal-jbarrett commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r580563551



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);
   }
 
   @Override
   public Set<ID> getMembersNotShuttingDown() {
-    latestViewReadLock.lock();
-    try {
-      return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
+    synchronized (shutdownMembers) {

Review comment:
       Only a single thread can read this set of members now. Previously all threads could read concurrently.

##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);

Review comment:
       All threads can now concurrently invoke `memberShutdown`, is this desirable?

##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1360,13 +1319,8 @@ public boolean verifyMember(ID mbr, String reason) {
 
   @Override
   public ID[] getAllMembers(final ID[] arrayType) {
-    latestViewReadLock.lock();
-    try {
-      List<ID> keySet = latestView.getMembers();
-      return keySet.toArray(arrayType);
-    } finally {
-      latestViewReadLock.unlock();
-    }
+    final List<ID> keySet = latestView.getMembers();

Review comment:
       Is the latest view and/or members list immutable?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill merged pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill merged pull request #6037:
URL: https://github.com/apache/geode/pull/6037


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r583996957



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1545,7 +1488,7 @@ private boolean isNew(final ID m) {
    * <p>
    * Like isShunned, this method holds the view lock while executing
    *
-   * Concurrency: protected by {@link #latestViewLock} ReentrantReadWriteLock
+   * Concurrency: protected by {@link #latestViewReadLock} ReentrantReadWriteLock

Review comment:
       Typo: it's a re-entrant read lock, not a re-entrant read-write lock




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] pivotal-jbarrett commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r580671010



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);
   }
 
   @Override
   public Set<ID> getMembersNotShuttingDown() {
-    latestViewReadLock.lock();
-    try {
-      return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
+    synchronized (shutdownMembers) {

Review comment:
       Or give `shutdownMembers` the same immutability treatment that `lastView` has.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] kamilla1201 commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
kamilla1201 commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r580652792



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);

Review comment:
       I pushed a commit a few hours ago that makes `shutdownMembers` a `synchronizedSet`. So `shutdownMembers.add(id)` call should be thread-safe here. I'm not sure whether the concurrent invocation of memberShutdown can cause any issues.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] pivotal-jbarrett commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r582343564



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);
   }
 
   @Override
   public Set<ID> getMembersNotShuttingDown() {
-    latestViewReadLock.lock();
-    try {
-      return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
+    synchronized (shutdownMembers) {

Review comment:
       Wait a second, we are creating a new set of members not shutting down for every p2p message sent?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] bschuchardt commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
bschuchardt commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r582349975



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);
   }
 
   @Override
   public Set<ID> getMembersNotShuttingDown() {
-    latestViewReadLock.lock();
-    try {
-      return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
+    synchronized (shutdownMembers) {

Review comment:
       @pivotal-jbarrett yes, we've always created a new collection like this for the reply processors.  This code now seems to create two (if you look at its primary use in ClusterDistributionManager) so that could be made more efficient.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] bschuchardt commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
bschuchardt commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r581153205



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);
   }
 
   @Override
   public Set<ID> getMembersNotShuttingDown() {
-    latestViewReadLock.lock();
-    try {
-      return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
+    synchronized (shutdownMembers) {

Review comment:
       Since this is a potentially long linked list I don't think copy-on-write is a good pattern to use for shutdownMembers.
   This method is invoked on every message-send, so maybe using a synchronized collection isn't a great idea and we should use the read/write lock instead.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] pivotal-jbarrett commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r583994435



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);
   }
 
   @Override
   public Set<ID> getMembersNotShuttingDown() {
-    latestViewReadLock.lock();
-    try {
-      return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
+    synchronized (shutdownMembers) {

Review comment:
       Awesome! Thanks!




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r580630554



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1360,13 +1319,8 @@ public boolean verifyMember(ID mbr, String reason) {
 
   @Override
   public ID[] getAllMembers(final ID[] arrayType) {
-    latestViewReadLock.lock();
-    try {
-      List<ID> keySet = latestView.getMembers();
-      return keySet.toArray(arrayType);
-    } finally {
-      latestViewReadLock.unlock();
-    }
+    final List<ID> keySet = latestView.getMembers();

Review comment:
       `latestView` isa `MembershipView` and yes, this PR makes `MembershipView` immutable (see `MembershipView.java`)




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] pivotal-jbarrett commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r580671626



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);

Review comment:
       The other concern here is now updates to `shutdownMembers` and the call to `memberShutdown` can be concurrently interleaved. 




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r579391765



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -273,6 +273,9 @@ boolean isDistributionMessage() {
   /**
    * Members that have sent a shutdown message. This is used to suppress suspect processing that
    * otherwise becomes pretty aggressive when a member is shutting down.
+   *
+   * Accesses to this map should be synchronized on the map to avoid concurrent
+   * modification exceptions

Review comment:
       Since we only ever `shutdownMembers.put(id, id)` this can be a `Set<ID>`. It needn't be a map.
   
   Furthermore, if we made it a concurrent map-based set, we could eliminate all the synchronization below.
   
   This declaration could become:
   
   ```
   private final Set<ID> shutdownMembers = ConcurrentHashMap.newKeySet();
   ```
   
   Then code below like this:
   
   ```java
       synchronized (shutdownMembers) {
         if (!shutdownMembers.containsKey(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
       }
   
   ```
   
   changes to this:
   
   ```
         if (!shutdownMembers.contains(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
   ```
   
   and code below like this:
   
   
   ```
       synchronized (shutdownMembers) {
         return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
             .collect(
                 Collectors.toSet());
       }
   ```
   
   changes to code like this:
   
   ```
       final Set<ID> shutdownMembersStable = shutdownMembers;
       return latestView.getMembers().stream().filter(id -> !shutdownMembersStable.contains(id))
           .collect(
               Collectors.toSet());
   ```
   
   or maybe:
   
   ```
       final Set<ID> membersNotShuttingDown = new HashSet<ID>(latestView.getMembers());
       final Set<ID> shutdownMembersStable = shutdownMembers;
       membersNotShuttingDown.removeIf(shutdownMembersStable::contains);
       return membersNotShuttingDown;
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r580637810



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);

Review comment:
       My bigger concern in this version of this method is the lack of synchronization around `shutdownMembers.add(id)` since that collection is not thread-safe.
   
   @pivotal-jbarrett I believe @kamilla1201 has a new commit coming to fix CI…




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] kamilla1201 commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
kamilla1201 commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r580657139



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);
   }
 
   @Override
   public Set<ID> getMembersNotShuttingDown() {
-    latestViewReadLock.lock();
-    try {
-      return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
+    synchronized (shutdownMembers) {

Review comment:
       Yes, as Bill said, `shutdownMembers` was a non-concurrent collection, and the read access to it wasn't synched. Although `shutdownMembers` is a `synchronizedSet` now, synchronization is still needed around `stream()` operation.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] pivotal-jbarrett commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r580672965



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1360,13 +1319,8 @@ public boolean verifyMember(ID mbr, String reason) {
 
   @Override
   public ID[] getAllMembers(final ID[] arrayType) {
-    latestViewReadLock.lock();
-    try {
-      List<ID> keySet = latestView.getMembers();
-      return keySet.toArray(arrayType);
-    } finally {
-      latestViewReadLock.unlock();
-    }
+    final List<ID> keySet = latestView.getMembers();

Review comment:
       So if the view is immutable, what is the r/w lock protecting anymore?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r579391765



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -273,6 +273,9 @@ boolean isDistributionMessage() {
   /**
    * Members that have sent a shutdown message. This is used to suppress suspect processing that
    * otherwise becomes pretty aggressive when a member is shutting down.
+   *
+   * Accesses to this map should be synchronized on the map to avoid concurrent
+   * modification exceptions

Review comment:
       Since we only ever `shutdownMembers.put(id, id)` this can be a `Set<ID>`. It needn't be a map.
   
   Furthermore, if we made it a concurrent map-based set, we could eliminate all the synchronization below.
   
   This declaration could become:
   
   ```
   private final Set<ID> shutdownMembers = ConcurrentHashMap.newKeySet();
   ```
   
   Then code below like this:
   
   ```
       synchronized (shutdownMembers) {
         if (!shutdownMembers.containsKey(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
       }
   
   ```
   
   changes to this:
   
   ```
         if (!shutdownMembers.containsKey(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
   ```
   
   and code below like this:
   
   ```
       synchronized (shutdownMembers) {
         return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
             .collect(
                 Collectors.toSet());
       }
   ```
   
   changes to code like this:
   
   ```
       final Set<ID> membersNotShuttingDown = new HashSet<ID>(latestView.getMembers());
       final Set<ID> shutdownMembersStable = this.shutdownMembers;
       membersNotShuttingDown.removeIf(shutdownMembersStable::contains);
       return membersNotShuttingDown;
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] bschuchardt commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
bschuchardt commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r579399721



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -273,6 +273,9 @@ boolean isDistributionMessage() {
   /**
    * Members that have sent a shutdown message. This is used to suppress suspect processing that
    * otherwise becomes pretty aggressive when a member is shutting down.
+   *
+   * Accesses to this map should be synchronized on the map to avoid concurrent
+   * modification exceptions
    */
   private final Map<ID, Object> shutdownMembers = new BoundedLinkedHashMap<>();

Review comment:
       I'm wondering if this could be made a synchronized collection with Collections.synchronizedMap().  Then we could get rid of the external synchronization.

##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -677,10 +658,12 @@ private void removeWithViewLock(ID dm, boolean crashed, String reason) {
       return; // Explicit deletion, no upcall.
     }
 
-    if (!shutdownMembers.containsKey(dm)) {
-      // if we've received a shutdown message then DistributionManager will already have
-      // notified listeners
-      listener.memberDeparted(dm, crashed, reason);
+    synchronized (shutdownMembers) {
+      if (!shutdownMembers.containsKey(dm)) {
+        // if we've received a shutdown message then DistributionManager will already have
+        // notified listeners
+        listener.memberDeparted(dm, crashed, reason);

Review comment:
       Is it necessary to hold the lock on shutdownMembers while invoking a listener?  The point of this check is to avoid invoking memberDeparted if a shutdown message from **dm** has already been processed.  In that case we've already invoked memberDeparted on the listener.

##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1524,15 +1487,9 @@ public boolean isShunned(ID m) {
   }
 
   private boolean isShunnedOrNew(final ID m) {
-    latestViewReadLock.lock();
-    try {
-      return shunnedMembers.containsKey(m) || isNew(m);
-    } finally { // synchronized
-      latestViewReadLock.unlock();
-    }
+    return shunnedMembers.containsKey(m) || isNew(m);
   }
 
-  // must be invoked under view read or write lock
   private boolean isNew(final ID m) {
     return !latestView.contains(m) && !surpriseMembers.containsKey(m);

Review comment:
       I think the read-lock is still needed here.  While the "shunned" state of the member is disconnected from the other two checks, surpriseMembers is modified while forming a new membership view and we want these two checks to be atomic.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r584016314



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1545,7 +1488,7 @@ private boolean isNew(final ID m) {
    * <p>
    * Like isShunned, this method holds the view lock while executing
    *
-   * Concurrency: protected by {@link #latestViewLock} ReentrantReadWriteLock
+   * Concurrency: protected by {@link #latestViewReadLock} ReentrantReadWriteLock

Review comment:
       I misspoke and the comment is still wrong. This would be better:
   
   ```java
   * Concurrency: protected by {@link #latestViewReadLock}
   ```
   
   no such thing as a "ReentrantReadWriteLock". Sorry for the confusion!




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r579391765



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -273,6 +273,9 @@ boolean isDistributionMessage() {
   /**
    * Members that have sent a shutdown message. This is used to suppress suspect processing that
    * otherwise becomes pretty aggressive when a member is shutting down.
+   *
+   * Accesses to this map should be synchronized on the map to avoid concurrent
+   * modification exceptions

Review comment:
       Since we only ever `shutdownMembers.put(id, id)` this can be a `Set<ID>`. It needn't be a map.
   
   Furthermore, if we made it a concurrent map-based set, we could eliminate all the synchronization below.
   
   This declaration could become:
   
   ```
   private final Set<ID> shutdownMembers = ConcurrentHashMap.newKeySet();
   ```
   
   Then code below like this:
   
   ```java
       synchronized (shutdownMembers) {
         if (!shutdownMembers.containsKey(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
       }
   
   ```
   
   changes to this:
   
   ```java
         if (!shutdownMembers.contains(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
   ```
   
   and code below like this:
   
   
   ```java
       synchronized (shutdownMembers) {
         return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
             .collect(
                 Collectors.toSet());
       }
   ```
   
   changes to code like this:
   
   ```java
       final Set<ID> shutdownMembersStable = shutdownMembers;
       return latestView.getMembers().stream().filter(id -> !shutdownMembersStable.contains(id))
           .collect(
               Collectors.toSet());
   ```
   
   or maybe:
   
   ```java
       final Set<ID> membersNotShuttingDown = new HashSet<ID>(latestView.getMembers());
       final Set<ID> shutdownMembersStable = shutdownMembers;
       membersNotShuttingDown.removeIf(shutdownMembersStable::contains);
       return membersNotShuttingDown;
   ```
   
   I think I prefer the first variant (the filter-based one) over the second (`removeIf()`) one.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r579391765



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -273,6 +273,9 @@ boolean isDistributionMessage() {
   /**
    * Members that have sent a shutdown message. This is used to suppress suspect processing that
    * otherwise becomes pretty aggressive when a member is shutting down.
+   *
+   * Accesses to this map should be synchronized on the map to avoid concurrent
+   * modification exceptions

Review comment:
       Since we only ever `shutdownMembers.put(id, id)` this can be a `Set<ID>`. It needn't be a map.
   
   Furthermore, if we made it a concurrent map-based set, we could eliminate all the synchronization below.
   
   This declaration could become:
   
   ```
   private final Set<ID> shutdownMembers = ConcurrentHashMap.newKeySet();
   ```
   
   Then code below like this:
   
   ```java
       synchronized (shutdownMembers) {
         if (!shutdownMembers.containsKey(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
       }
   
   ```
   
   changes to this:
   
   ```java
         if (!shutdownMembers.contains(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
   ```
   
   and code below like this:
   
   
   ```java
       synchronized (shutdownMembers) {
         return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
             .collect(
                 Collectors.toSet());
       }
   ```
   
   changes to code like this:
   
   ```java
       final Set<ID> shutdownMembersStable = shutdownMembers;
       return latestView.getMembers().stream().filter(id -> !shutdownMembersStable.contains(id))
           .collect(
               Collectors.toSet());
   ```
   
   or maybe:
   
   ```java
       final Set<ID> membersNotShuttingDown = new HashSet<ID>(latestView.getMembers());
       final Set<ID> shutdownMembersStable = shutdownMembers;
       membersNotShuttingDown.removeIf(shutdownMembersStable::contains);
       return membersNotShuttingDown;
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r579391765



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -273,6 +273,9 @@ boolean isDistributionMessage() {
   /**
    * Members that have sent a shutdown message. This is used to suppress suspect processing that
    * otherwise becomes pretty aggressive when a member is shutting down.
+   *
+   * Accesses to this map should be synchronized on the map to avoid concurrent
+   * modification exceptions

Review comment:
       Since we only ever `shutdownMembers.put(id, id)` this can be a `Set<ID>`. It needn't be a map.
   
   Furthermore, if we made it a concurrent map-based set, we could eliminate all the synchronization below.
   
   This declaration could become:
   
   ```
   private final Set<ID> shutdownMembers = ConcurrentHashMap.newKeySet();
   ```
   
   Then code below like this:
   
   ```
       synchronized (shutdownMembers) {
         if (!shutdownMembers.containsKey(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
       }
   
   ```
   
   changes to this:
   
   ```
         if (!shutdownMembers.contains(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
   ```
   
   and code below like this:
   
   
   ```
       synchronized (shutdownMembers) {
         return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
             .collect(
                 Collectors.toSet());
       }
   ```
   
   changes to code like this:
   
   ```
       final Set<ID> shutdownMembersStable = this.shutdownMembers;
       return latestView.getMembers().stream().filter(id -> !shutdownMembersStable.contains(id))
           .collect(
               Collectors.toSet());
   ```
   
   or maybe:
   
   ```
       final Set<ID> membersNotShuttingDown = new HashSet<ID>(latestView.getMembers());
       final Set<ID> shutdownMembersStable = this.shutdownMembers;
       membersNotShuttingDown.removeIf(shutdownMembersStable::contains);
       return membersNotShuttingDown;
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] kamilla1201 commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
kamilla1201 commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r580648266



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1360,13 +1319,8 @@ public boolean verifyMember(ID mbr, String reason) {
 
   @Override
   public ID[] getAllMembers(final ID[] arrayType) {
-    latestViewReadLock.lock();
-    try {
-      List<ID> keySet = latestView.getMembers();
-      return keySet.toArray(arrayType);
-    } finally {
-      latestViewReadLock.unlock();
-    }
+    final List<ID> keySet = latestView.getMembers();

Review comment:
       This PR also makes `members` list unmodifiable.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] pivotal-jbarrett commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r582342689



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);
   }
 
   @Override
   public Set<ID> getMembersNotShuttingDown() {
-    latestViewReadLock.lock();
-    try {
-      return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
+    synchronized (shutdownMembers) {

Review comment:
       If the list isn't updated frequently even a long list with copy on write would be better less intrusive than frequently grabbing a read lock. If this method is called for every p2p message we certainly can't have it synchronizing, it should do the least amount of blocking as possible.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r579413256



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -273,6 +273,9 @@ boolean isDistributionMessage() {
   /**
    * Members that have sent a shutdown message. This is used to suppress suspect processing that
    * otherwise becomes pretty aggressive when a member is shutting down.
+   *
+   * Accesses to this map should be synchronized on the map to avoid concurrent
+   * modification exceptions

Review comment:
       We could keep the synchronization and improve things a tiny bit by declaring the field this way:
   
   ```
     private final Set<ID> shutdownMembers = new BoundedLinkedHashMap<ID,ID>().keySet();
   ```
   
   That'd let us `shutdownMembers.put(id)` and use `shutdownMembers.contains(id)` instead of `shutdownMembers.containsKey(id)`.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r579391765



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -273,6 +273,9 @@ boolean isDistributionMessage() {
   /**
    * Members that have sent a shutdown message. This is used to suppress suspect processing that
    * otherwise becomes pretty aggressive when a member is shutting down.
+   *
+   * Accesses to this map should be synchronized on the map to avoid concurrent
+   * modification exceptions

Review comment:
       Since we only ever `shutdownMembers.put(id, id)` this can be a `Set<ID>`. It needn't be a map.
   
   Furthermore, if we made it a concurrent map-based set, we could eliminate all the synchronization below.
   
   This declaration could become:
   
   ```
   private final Set<ID> shutdownMembers = ConcurrentHashMap.newKeySet();
   ```
   
   Then code below like this:
   
   ```
       synchronized (shutdownMembers) {
         if (!shutdownMembers.containsKey(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
       }
   
   ```
   
   changes to this:
   
   ```
         if (!shutdownMembers.contains(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
   ```
   
   and code below like this:
   
   ```
       final Set<ID> shutdownMembersStable = this.shutdownMembers;
       return latestView.getMembers().stream().filter(id -> !shutdownMembersStable.contains(id))
           .collect(
               Collectors.toSet());
   ```
   
   changes to code like this:
   
   ```
       synchronized (shutdownMembers) {
         return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
             .collect(
                 Collectors.toSet());
       }
   ```
   
   or maybe:
   
   ```
       final Set<ID> membersNotShuttingDown = new HashSet<ID>(latestView.getMembers());
       final Set<ID> shutdownMembersStable = this.shutdownMembers;
       membersNotShuttingDown.removeIf(shutdownMembersStable::contains);
       return membersNotShuttingDown;
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r579391765



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -273,6 +273,9 @@ boolean isDistributionMessage() {
   /**
    * Members that have sent a shutdown message. This is used to suppress suspect processing that
    * otherwise becomes pretty aggressive when a member is shutting down.
+   *
+   * Accesses to this map should be synchronized on the map to avoid concurrent
+   * modification exceptions

Review comment:
       Since we only ever `shutdownMembers.put(id, id)` this can be a `Set<ID>`. It needn't be a map.
   
   Furthermore, if we made it a concurrent map-based set, we could eliminate all the synchronization below.
   
   This declaration could become:
   
   ```
   private final Set<ID> shutdownMembers = ConcurrentHashMap.newKeySet();
   ```
   
   Then code below like this:
   
   ```
       synchronized (shutdownMembers) {
         if (!shutdownMembers.containsKey(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
       }
   
   ```
   
   changes to this:
   
   ```
         if (!shutdownMembers.contains(dm)) {
           // if we've received a shutdown message then DistributionManager will already have
           // notified listeners
           listener.memberDeparted(dm, crashed, reason);
         }
   ```
   
   and code below like this:
   
   
   ```
       synchronized (shutdownMembers) {
         return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
             .collect(
                 Collectors.toSet());
       }
   ```
   
   changes to code like this:
   
   ```
       final Set<ID> shutdownMembersStable = shutdownMembers;
       return latestView.getMembers().stream().filter(id -> !shutdownMembersStable.contains(id))
           .collect(
               Collectors.toSet());
   ```
   
   or maybe:
   
   ```
       final Set<ID> membersNotShuttingDown = new HashSet<ID>(latestView.getMembers());
       final Set<ID> shutdownMembersStable = shutdownMembers;
       membersNotShuttingDown.removeIf(shutdownMembersStable::contains);
       return membersNotShuttingDown;
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] pivotal-jbarrett commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r580666049



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);
   }
 
   @Override
   public Set<ID> getMembersNotShuttingDown() {
-    latestViewReadLock.lock();
-    try {
-      return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
+    synchronized (shutdownMembers) {

Review comment:
       You are saying that currently the shutdownMembers collection can be mutated without acquiring the write lock? If that is the case wouldn't the more appropriate fix be to acquire the write lock before mutation rather than adding a serializing synchronization block here?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] bschuchardt commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
bschuchardt commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r582353925



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1360,13 +1319,8 @@ public boolean verifyMember(ID mbr, String reason) {
 
   @Override
   public ID[] getAllMembers(final ID[] arrayType) {
-    latestViewReadLock.lock();
-    try {
-      List<ID> keySet = latestView.getMembers();
-      return keySet.toArray(arrayType);
-    } finally {
-      latestViewReadLock.unlock();
-    }
+    final List<ID> keySet = latestView.getMembers();

Review comment:
       The lock is protecting new view formation in processView().  This data needs to be stable while the new view is created.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [geode] pivotal-jbarrett commented on a change in pull request #6037: GEODE-7245: Remove most uses of latestViewReadLock in GMSMembership

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on a change in pull request #6037:
URL: https://github.com/apache/geode/pull/6037#discussion_r582368198



##########
File path: geode-membership/src/main/java/org/apache/geode/distributed/internal/membership/gms/GMSMembership.java
##########
@@ -1231,23 +1197,16 @@ public void shutdownMessageReceived(ID id, String reason) {
     if (logger.isDebugEnabled()) {
       logger.debug("Membership: recording shutdown status of {}", id);
     }
-    synchronized (this.shutdownMembers) {
-      this.shutdownMembers.put(id, id);
-      services.getHealthMonitor()
-          .memberShutdown(id, reason);
-      services.getJoinLeave().memberShutdown(id, reason);
-    }
+    this.shutdownMembers.add(id);
+    services.getJoinLeave().memberShutdown(id, reason);
   }
 
   @Override
   public Set<ID> getMembersNotShuttingDown() {
-    latestViewReadLock.lock();
-    try {
-      return latestView.getMembers().stream().filter(id -> !shutdownMembers.containsKey(id))
+    synchronized (shutdownMembers) {

Review comment:
       If the `shutdownMembers` list isn't changing frequently, like every ms, then repeatedly recreating the same set is just adding pressure to the GC and CPU time all while under a synchronized lock for no real gain. I assume this `shutdownMembers` list is updated with the member id of the member that has said it is or has gone down, which isn't a frequent event in production. Seems like we should be optimizing this method to be returning a rather static list of members known not to be shutting down even if that means the infrequent setting of a shutting down member takes a bit more time to handle, by copying lists and invalidating or updating the not shutdown servers list. 
   
   At the very least the addition of this synchronized block is going to have a noticeable impact on the p2p messaging at scale since all messages will be serialized through this lock. If we deem refactoring out the list creation is out of scope for this PR then using a read/write lock here should be in scope as a first step.




----------------------------------------------------------------
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:
users@infra.apache.org