You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2021/05/14 22:40:24 UTC

[geode] branch GEM-3288-network-interfaces created (now f7835ca)

This is an automated email from the ASF dual-hosted git repository.

klund pushed a change to branch GEM-3288-network-interfaces
in repository https://gitbox.apache.org/repos/asf/geode.git.


      at f7835ca  Add main to LocalHostUtil

This branch includes the following new commits:

     new f7835ca  Add main to LocalHostUtil

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[geode] 01/01: Add main to LocalHostUtil

Posted by kl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

klund pushed a commit to branch GEM-3288-network-interfaces
in repository https://gitbox.apache.org/repos/asf/geode.git

commit f7835ca9c58254f37b7168ecceb2070e717a0abc
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Fri May 14 14:01:48 2021 -0700

    Add main to LocalHostUtil
---
 .../apache/geode/internal/inet/LocalHostUtil.java  |  4 +++
 .../internal/cache/PRHARedundancyProvider.java     | 40 +++++++++++++---------
 .../cache/PartitionedRegionBucketMgmtHelper.java   | 26 ++++++--------
 3 files changed, 37 insertions(+), 33 deletions(-)

diff --git a/geode-common/src/main/java/org/apache/geode/internal/inet/LocalHostUtil.java b/geode-common/src/main/java/org/apache/geode/internal/inet/LocalHostUtil.java
index 2e917f6..b0b1ec1 100644
--- a/geode-common/src/main/java/org/apache/geode/internal/inet/LocalHostUtil.java
+++ b/geode-common/src/main/java/org/apache/geode/internal/inet/LocalHostUtil.java
@@ -180,6 +180,10 @@ public class LocalHostUtil {
     }
   }
 
+  public static void main(String[] args) throws Exception {
+    System.out.println("getMyAddresses: " + getMyAddresses());
+  }
+
   /**
    * This method uses JNDI to look up an address in DNS and return its name
    *
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/PRHARedundancyProvider.java b/geode-core/src/main/java/org/apache/geode/internal/cache/PRHARedundancyProvider.java
index e07ab55..e29ee75 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/PRHARedundancyProvider.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/PRHARedundancyProvider.java
@@ -54,7 +54,6 @@ import org.apache.geode.cache.RegionDestroyedException;
 import org.apache.geode.cache.persistence.PartitionOfflineException;
 import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.internal.DistributionManager;
-import org.apache.geode.distributed.internal.LonerDistributionManager;
 import org.apache.geode.distributed.internal.MembershipListener;
 import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
 import org.apache.geode.internal.Assert;
@@ -625,22 +624,7 @@ public class PRHARedundancyProvider {
 
           InternalDistributedMember candidate = createBucketInstance(bucketId, newBucketSize,
               excludedMembers, acceptedMembers, failedMembers, timeOut, allStores);
-          if (candidate != null) {
-            if (partitionedRegion.getDistributionManager().enforceUniqueZone()) {
-              // enforceUniqueZone property has no effect for a loner
-              if (!(partitionedRegion
-                  .getDistributionManager() instanceof LonerDistributionManager)) {
-                Set<InternalDistributedMember> exm = getBuddyMembersInZone(candidate, allStores);
-                exm.remove(candidate);
-                exm.removeAll(acceptedMembers);
-                excludedMembers.addAll(exm);
-              } else {
-                // log a warning if Loner
-                logger.warn(
-                    "enforce-unique-host and redundancy-zone properties have no effect for a LonerDistributedSystem.");
-              }
-            }
-          }
+          validateCandidateStore(excludedMembers, acceptedMembers, allStores, candidate);
 
           // Get an updated list of bucket owners, which should include
           // buckets created concurrently with this createBucketAtomically call
@@ -767,6 +751,28 @@ public class PRHARedundancyProvider {
     }
   }
 
+  private void validateCandidateStore(Set<InternalDistributedMember> excludedMembers,
+      Collection<InternalDistributedMember> acceptedMembers,
+      Set<InternalDistributedMember> allStores,
+      InternalDistributedMember candidate) {
+    if (candidate != null) {
+      DistributionManager distributionManager = partitionedRegion.getDistributionManager();
+      if (distributionManager.enforceUniqueZone()) {
+        // enforceUniqueZone property has no effect for a loner
+        if (!distributionManager.isLoner()) {
+          Set<InternalDistributedMember> exm = getBuddyMembersInZone(candidate, allStores);
+          exm.remove(candidate);
+          exm.removeAll(acceptedMembers);
+          excludedMembers.addAll(exm);
+        } else {
+          // log a warning if Loner
+          logger.warn(
+              "enforce-unique-host and redundancy-zone properties have no effect for a LonerDistributedSystem.");
+        }
+      }
+    }
+  }
+
   /**
    * Figure out which member should be primary for a bucket among the members that have created the
    * bucket, and tell that member to become the primary.
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionBucketMgmtHelper.java b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionBucketMgmtHelper.java
index dceb46a..b575827 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionBucketMgmtHelper.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionBucketMgmtHelper.java
@@ -12,7 +12,6 @@
  * or implied. See the License for the specific language governing permissions and limitations under
  * the License.
  */
-
 package org.apache.geode.internal.cache;
 
 import java.util.Collections;
@@ -22,30 +21,25 @@ import java.util.Set;
 import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
 import org.apache.geode.internal.cache.partitioned.Bucket;
 
-
 /**
  * This class encapsulates the Bucket Related heuristics/algos for a PR.
- *
- *
  */
 class PartitionedRegionBucketMgmtHelper {
 
   /**
-   *
-   * @param b Bucket to evaluate
+   * @param bucket Bucket to evaluate
    * @return true if it is allowed to be recovered
    * @since GemFire 5.9
    */
-  static boolean bucketIsAllowedOnThisHost(Bucket b, InternalDistributedMember moveSource) {
-    if (b.getDistributionManager().enforceUniqueZone()) {
-      Set<InternalDistributedMember> hostingMembers = b.getBucketOwners();
-      Set<InternalDistributedMember> buddyMembers =
-          new HashSet(b.getDistributionManager().getMembersInThisZone());
-      boolean disjoint = Collections.disjoint(hostingMembers, buddyMembers);
-      boolean sourceIsOneThisHost = moveSource != null && buddyMembers.contains(moveSource);
-      return disjoint || sourceIsOneThisHost;
-    } else {
-      return true;
+  static boolean bucketIsAllowedOnThisHost(Bucket bucket, InternalDistributedMember fromMember) {
+    if (bucket.getDistributionManager().enforceUniqueZone()) {
+      Set<InternalDistributedMember> hostingMembers = bucket.getBucketOwners();
+      Set<InternalDistributedMember> membersInThisZone =
+          new HashSet<>(bucket.getDistributionManager().getMembersInThisZone());
+      boolean hostMemberAreNotInThisZone = Collections.disjoint(hostingMembers, membersInThisZone);
+      boolean fromMemberIsOnThisHost = fromMember != null && membersInThisZone.contains(fromMember);
+      return hostMemberAreNotInThisZone || fromMemberIsOnThisHost;
     }
+    return true;
   }
 }