geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jensde...@apache.org
Subject [30/51] [abbrv] geode git commit: GEODE-3152: Changed to create a region name appropriate to the client version
Date Mon, 10 Jul 2017 18:00:53 GMT
GEODE-3152: Changed to create a region name appropriate to the client version


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/55f7a1c9
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/55f7a1c9
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/55f7a1c9

Branch: refs/heads/feature/GEODE-3109
Commit: 55f7a1c9f1f152a6d2f8643d5e71fe3fa9986a51
Parents: b1f793f
Author: Barry Oglesby <boglesby@pivotal.io>
Authored: Tue Jun 27 17:42:11 2017 -0700
Committer: Barry Oglesby <boglesby@pivotal.io>
Committed: Fri Jun 30 09:50:23 2017 -0700

----------------------------------------------------------------------
 .../membership/InternalDistributedMember.java   | 156 ++++++++++---------
 .../tier/sockets/ClientProxyMembershipID.java   |  17 +-
 .../RollingUpgrade2DUnitTest.java               |  88 +++++++++--
 3 files changed, 173 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/55f7a1c9/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/InternalDistributedMember.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/InternalDistributedMember.java
b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/InternalDistributedMember.java
index 2060934..85c2bea 100755
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/InternalDistributedMember.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/InternalDistributedMember.java
@@ -657,82 +657,8 @@ public class InternalDistributedMember implements DistributedMember,
Externaliza
   public String toString() {
     String result = cachedToString;
     if (result == null) {
-      String host;
-
-      InetAddress add = getInetAddress();
-      if (add.isMulticastAddress())
-        host = add.getHostAddress();
-      else {
-        // host = shortName(add.getHostName());
-        host = SocketCreator.resolve_dns ? shortName(this.hostName) : this.hostName;
-      }
       final StringBuilder sb = new StringBuilder();
-
-      sb.append(host);
-
-      String myName = getName();
-      int vmPid = netMbr.getProcessId();
-      int vmKind = netMbr.getVmKind();
-      if (vmPid > 0 || vmKind != DistributionManager.NORMAL_DM_TYPE || !"".equals(myName))
{
-        sb.append("(");
-
-        if (!"".equals(myName)) {
-          sb.append(myName);
-          if (vmPid > 0) {
-            sb.append(':');
-          }
-        }
-
-        if (vmPid > 0)
-          sb.append(Integer.toString(vmPid));
-
-        String vmStr = "";
-        switch (vmKind) {
-          case DistributionManager.NORMAL_DM_TYPE:
-            // vmStr = ":local"; // let this be silent
-            break;
-          case DistributionManager.LOCATOR_DM_TYPE:
-            vmStr = ":locator";
-            break;
-          case DistributionManager.ADMIN_ONLY_DM_TYPE:
-            vmStr = ":admin";
-            break;
-          case DistributionManager.LONER_DM_TYPE:
-            vmStr = ":loner";
-            break;
-          default:
-            vmStr = ":<unknown:" + vmKind + ">";
-            break;
-        }
-        sb.append(vmStr);
-        sb.append(")");
-      }
-      if (vmKind != DistributionManager.LONER_DM_TYPE && netMbr.preferredForCoordinator())
{
-        sb.append("<ec>");
-      }
-      int vmViewId = getVmViewId();
-      if (vmViewId >= 0) {
-        sb.append("<v" + vmViewId + ">");
-      }
-      sb.append(":");
-      sb.append(getPort());
-
-      // if (dcPort > 0 && vmKind != DistributionManager.LONER_DM_TYPE) {
-      // sb.append("/");
-      // sb.append(Integer.toString(dcPort));
-      // }
-
-      if (vmKind == DistributionManager.LONER_DM_TYPE) {
-        // add some more info that was added in 4.2.1 for loner bridge clients
-        // impact on non-bridge loners is ok
-        if (this.uniqueTag != null && this.uniqueTag.length() != 0) {
-          sb.append(":").append(this.uniqueTag);
-        }
-        String name = getName();
-        if (name.length() != 0) {
-          sb.append(":").append(name);
-        }
-      }
+      addFixedToString(sb);
 
       // add version if not current
       short version = netMbr.getVersionOrdinal();
@@ -756,6 +682,86 @@ public class InternalDistributedMember implements DistributedMember,
Externaliza
     return result;
   }
 
+  public void addFixedToString(StringBuilder sb) {
+    // Note: This method is used to generate the HARegion name. If it is changed, memory
and GII
+    // issues will occur in the case of clients with subscriptions during rolling upgrade.
+    String host;
+
+    InetAddress add = getInetAddress();
+    if (add.isMulticastAddress())
+      host = add.getHostAddress();
+    else {
+      // host = shortName(add.getHostName());
+      host = SocketCreator.resolve_dns ? shortName(this.hostName) : this.hostName;
+    }
+
+    sb.append(host);
+
+    String myName = getName();
+    int vmPid = netMbr.getProcessId();
+    int vmKind = netMbr.getVmKind();
+    if (vmPid > 0 || vmKind != DistributionManager.NORMAL_DM_TYPE || !"".equals(myName))
{
+      sb.append("(");
+
+      if (!"".equals(myName)) {
+        sb.append(myName);
+        if (vmPid > 0) {
+          sb.append(':');
+        }
+      }
+
+      if (vmPid > 0)
+        sb.append(Integer.toString(vmPid));
+
+      String vmStr = "";
+      switch (vmKind) {
+        case DistributionManager.NORMAL_DM_TYPE:
+          // vmStr = ":local"; // let this be silent
+          break;
+        case DistributionManager.LOCATOR_DM_TYPE:
+          vmStr = ":locator";
+          break;
+        case DistributionManager.ADMIN_ONLY_DM_TYPE:
+          vmStr = ":admin";
+          break;
+        case DistributionManager.LONER_DM_TYPE:
+          vmStr = ":loner";
+          break;
+        default:
+          vmStr = ":<unknown:" + vmKind + ">";
+          break;
+      }
+      sb.append(vmStr);
+      sb.append(")");
+    }
+    if (vmKind != DistributionManager.LONER_DM_TYPE && netMbr.preferredForCoordinator())
{
+      sb.append("<ec>");
+    }
+    int vmViewId = getVmViewId();
+    if (vmViewId >= 0) {
+      sb.append("<v" + vmViewId + ">");
+    }
+    sb.append(":");
+    sb.append(getPort());
+
+    // if (dcPort > 0 && vmKind != DistributionManager.LONER_DM_TYPE) {
+    // sb.append("/");
+    // sb.append(Integer.toString(dcPort));
+    // }
+
+    if (vmKind == DistributionManager.LONER_DM_TYPE) {
+      // add some more info that was added in 4.2.1 for loner bridge clients
+      // impact on non-bridge loners is ok
+      if (this.uniqueTag != null && this.uniqueTag.length() != 0) {
+        sb.append(":").append(this.uniqueTag);
+      }
+      String name = getName();
+      if (name.length() != 0) {
+        sb.append(":").append(name);
+      }
+    }
+  }
+
   private short readVersion(int flags, DataInput in) throws IOException {
     if ((flags & VERSION_BIT) != 0) {
       short version = Version.readOrdinal(in);

http://git-wip-us.apache.org/repos/asf/geode/blob/55f7a1c9/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProxyMembershipID.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProxyMembershipID.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProxyMembershipID.java
index 2fd508b..074034a 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProxyMembershipID.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientProxyMembershipID.java
@@ -336,14 +336,27 @@ public class ClientProxyMembershipID
     }
     // don't cache if we haven't connected to the server yet
     if (((InternalDistributedMember) getDistributedMember()).getPort() == 0) {
-      return getDistributedMember().toString();
+      return getMemberIdAsString();
     }
     if (memberIdString == null) {
-      memberIdString = getDistributedMember().toString();
+      memberIdString = getMemberIdAsString();
     }
     return memberIdString;
   }
 
+  private String getMemberIdAsString() {
+    String memberIdAsString = null;
+    InternalDistributedMember idm = (InternalDistributedMember) getDistributedMember();
+    if (getClientVersion().compareTo(Version.GFE_90) < 0) {
+      memberIdAsString = idm.toString();
+    } else {
+      StringBuilder sb = new StringBuilder();
+      idm.addFixedToString(sb);
+      memberIdAsString = sb.toString();
+    }
+    return memberIdAsString;
+  }
+
   /**
    * this method uses CacheClientNotifier to try to obtain an ID that is equal to this one.
This is
    * used during deserialization to reduce storage overhead.

http://git-wip-us.apache.org/repos/asf/geode/blob/55f7a1c9/geode-core/src/test/java/org/apache/geode/internal/cache/rollingupgrade/RollingUpgrade2DUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/rollingupgrade/RollingUpgrade2DUnitTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/rollingupgrade/RollingUpgrade2DUnitTest.java
index beb3a9a..3d606d8 100755
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/rollingupgrade/RollingUpgrade2DUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/rollingupgrade/RollingUpgrade2DUnitTest.java
@@ -57,10 +57,12 @@ import org.apache.geode.distributed.internal.InternalLocator;
 import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
 import org.apache.geode.internal.AvailablePortHelper;
 import org.apache.geode.internal.Version;
+import org.apache.geode.internal.cache.CacheServerImpl;
 import org.apache.geode.internal.cache.DiskInitFile;
 import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.Oplog;
 import org.apache.geode.internal.cache.Oplog.OPLOG_TYPE;
+import org.apache.geode.internal.cache.tier.sockets.CacheClientProxy;
 import org.apache.geode.internal.i18n.LocalizedStrings;
 import org.apache.geode.test.dunit.Assert;
 import org.apache.geode.test.dunit.AsyncInvocation;
@@ -330,7 +332,8 @@ public class RollingUpgrade2DUnitTest extends JUnit4DistributedTestCase
{
       invokeRunnableInVMs(invokeStartCacheServer(csPorts[1]), server3);
 
       invokeRunnableInVMs(
-          invokeCreateClientCache(getClientSystemProperties(), hostNames, locatorPorts),
client);
+          invokeCreateClientCache(getClientSystemProperties(), hostNames, locatorPorts, false),
+          client);
       // invokeRunnableInVMs(invokeAssertVersion(oldOrdinal), server2, server3, client);
       invokeRunnableInVMs(invokeCreateRegion(regionName, shortcut), server2, server3);
       invokeRunnableInVMs(invokeCreateClientRegion(regionName, ClientRegionShortcut.PROXY),
client);
@@ -351,7 +354,7 @@ public class RollingUpgrade2DUnitTest extends JUnit4DistributedTestCase
{
       putAndVerify(objectType, server2, regionName, 30, 40, server3, client);
 
       client = rollClientToCurrentAndCreateRegion(client, ClientRegionShortcut.PROXY, regionName,
-          hostNames, locatorPorts);
+          hostNames, locatorPorts, false);
       putAndVerify(objectType, client, regionName, 35, 45, server2, server3);
       putAndVerify(objectType, server2, regionName, 40, 50, server3, client);
 
@@ -1073,6 +1076,53 @@ public class RollingUpgrade2DUnitTest extends JUnit4DistributedTestCase
{
     }
   }
 
+  @Test
+  public void testHARegionNameOnDifferentServerVersions() throws Exception {
+    doTestHARegionNameOnDifferentServerVersions(false, oldVersion);
+  }
+
+  public void doTestHARegionNameOnDifferentServerVersions(boolean partitioned, String oldVersion)
+      throws Exception {
+    final Host host = Host.getHost(0);
+    VM locator = host.getVM(oldVersion, 0);
+    VM server1 = host.getVM(oldVersion, 1);
+    VM server2 = host.getVM(2);
+    VM client = host.getVM(oldVersion, 3);
+
+    int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(3);
+    int[] locatorPorts = new int[] {ports[0]};
+    int[] csPorts = new int[] {ports[1], ports[2]};
+
+    DistributedTestUtils.deleteLocatorStateFile(locatorPorts);
+
+    String hostName = NetworkUtils.getServerHostName(host);
+    String[] hostNames = new String[] {hostName};
+    String locatorString = getLocatorString(locatorPorts);
+    try {
+      locator.invoke(invokeStartLocator(hostName, locatorPorts[0], getTestMethodName(),
+          getLocatorPropertiesPre91(locatorString)));
+      invokeRunnableInVMs(invokeCreateCache(getSystemProperties(locatorPorts)), server1,
server2);
+      invokeRunnableInVMs(invokeStartCacheServer(csPorts[0]), server1);
+      invokeRunnableInVMs(invokeStartCacheServer(csPorts[1]), server2);
+
+      invokeRunnableInVMs(
+          invokeCreateClientCache(getClientSystemProperties(), hostNames, locatorPorts, true),
+          client);
+
+      // Get HARegion name on server1
+      String server1HARegionName = server1.invoke(() -> getHARegionName());
+
+      // Get HARegionName on server2
+      String server2HARegionName = server2.invoke(() -> getHARegionName());
+
+      // Verify they are equal
+      assertEquals(server1HARegionName, server2HARegionName);
+    } finally {
+      invokeRunnableInVMs(true, invokeStopLocator(), locator);
+      invokeRunnableInVMs(true, invokeCloseCache(), server1, server2, client);
+    }
+  }
+
   // ******** TEST HELPER METHODS ********/
   private void putAndVerify(String objectType, VM putter, String regionName, int start, int
end,
       VM check1, VM check2, VM check3) throws Exception {
@@ -1218,12 +1268,12 @@ public class RollingUpgrade2DUnitTest extends JUnit4DistributedTestCase
{
     return rollServer;
   }
 
-  private VM rollClientToCurrent(VM oldClient, String[] hostNames, int[] locatorPorts)
-      throws Exception {
+  private VM rollClientToCurrent(VM oldClient, String[] hostNames, int[] locatorPorts,
+      boolean subscriptionEnabled) throws Exception {
     oldClient.invoke(invokeCloseCache());
     VM rollClient = Host.getHost(0).getVM(oldClient.getPid());
-    rollClient
-        .invoke(invokeCreateClientCache(getClientSystemProperties(), hostNames, locatorPorts));
+    rollClient.invoke(invokeCreateClientCache(getClientSystemProperties(), hostNames, locatorPorts,
+        subscriptionEnabled));
     rollClient.invoke(invokeAssertVersion(Version.CURRENT_ORDINAL));
     return rollClient;
   }
@@ -1275,8 +1325,9 @@ public class RollingUpgrade2DUnitTest extends JUnit4DistributedTestCase
{
    * @throws Exception
    */
   private VM rollClientToCurrentAndCreateRegion(VM oldClient, ClientRegionShortcut shortcut,
-      String regionName, String[] hostNames, int[] locatorPorts) throws Exception {
-    VM rollClient = rollClientToCurrent(oldClient, hostNames, locatorPorts);
+      String regionName, String[] hostNames, int[] locatorPorts, boolean subscriptionEnabled)
+      throws Exception {
+    VM rollClient = rollClientToCurrent(oldClient, hostNames, locatorPorts, subscriptionEnabled);
     // recreate region on "rolled" client
     invokeRunnableInVMs(invokeCreateClientRegion(regionName, shortcut), rollClient);
     return rollClient;
@@ -1418,11 +1469,12 @@ public class RollingUpgrade2DUnitTest extends JUnit4DistributedTestCase
{
   }
 
   private CacheSerializableRunnable invokeCreateClientCache(final Properties systemProperties,
-      final String[] hosts, final int[] ports) {
+      final String[] hosts, final int[] ports, boolean subscriptionEnabled) {
     return new CacheSerializableRunnable("execute: createClientCache") {
       public void run2() {
         try {
-          RollingUpgrade2DUnitTest.cache = createClientCache(systemProperties, hosts, ports);
+          RollingUpgrade2DUnitTest.cache =
+              createClientCache(systemProperties, hosts, ports, subscriptionEnabled);
         } catch (Exception e) {
           fail("Error creating client cache", e);
         }
@@ -1638,8 +1690,12 @@ public class RollingUpgrade2DUnitTest extends JUnit4DistributedTestCase
{
   }
 
   public static ClientCache createClientCache(Properties systemProperties, String[] hosts,
-      int[] ports) throws Exception {
+      int[] ports, boolean subscriptionEnabled) throws Exception {
     ClientCacheFactory cf = new ClientCacheFactory(systemProperties);
+    if (subscriptionEnabled) {
+      cf.setPoolSubscriptionEnabled(true);
+      cf.setPoolSubscriptionRedundancy(-1);
+    }
     int hostsLength = hosts.length;
     for (int i = 0; i < hostsLength; i++) {
       cf.addPoolLocator(hosts[i], ports[i]);
@@ -1913,6 +1969,16 @@ public class RollingUpgrade2DUnitTest extends JUnit4DistributedTestCase
{
     return Host.getHost(0).getHostName();
   }
 
+  private String getHARegionName() {
+    assertEquals(1, ((GemFireCacheImpl) cache).getCacheServers().size());
+    CacheServerImpl bs =
+        (CacheServerImpl) ((GemFireCacheImpl) cache).getCacheServers().iterator().next();
+    assertEquals(1, bs.getAcceptor().getCacheClientNotifier().getClientProxies().size());
+    CacheClientProxy ccp =
+        bs.getAcceptor().getCacheClientNotifier().getClientProxies().iterator().next();
+    return ccp.getHARegion().getName();
+  }
+
   public static class GetDataSerializableFunction implements Function {
 
     @Override


Mime
View raw message