geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hiteshkhame...@apache.org
Subject incubator-geode git commit: GEODE-1372 Removed un used field from GMSMember while sending message.
Date Thu, 11 Aug 2016 16:52:42 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-1372 deb363182 -> 8860d9b35


GEODE-1372 Removed un used field from GMSMember while sending message.

These fields were extra which doesn't require with each messsage.
Now we get sender id from prepared view if we don't find in current
view. Did some other cleanup. Added test for it


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

Branch: refs/heads/feature/GEODE-1372
Commit: 8860d9b35d2a45a54b5f6e79488ad8c79a2f5df1
Parents: deb3631
Author: Hitesh Khamesra <hiteshk25@yahoo.com>
Authored: Thu Aug 11 09:49:38 2016 -0700
Committer: Hitesh Khamesra <hiteshk25@yahoo.com>
Committed: Thu Aug 11 09:49:38 2016 -0700

----------------------------------------------------------------------
 .../internal/membership/gms/GMSMember.java      | 59 +++++++++++++++-----
 .../membership/gms/interfaces/JoinLeave.java    |  8 +++
 .../membership/gms/membership/GMSJoinLeave.java | 34 ++++++++++-
 .../gms/messenger/JGroupsMessenger.java         | 43 +++++++-------
 .../membership/gms/GMSMemberJUnitTest.java      | 24 ++++++++
 .../messenger/JGroupsMessengerJUnitTest.java    |  2 +-
 6 files changed, 131 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8860d9b3/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMember.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMember.java
b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMember.java
index d5d0b8e..b7754ce 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMember.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMember.java
@@ -24,6 +24,7 @@ import com.gemstone.gemfire.distributed.internal.membership.NetMember;
 import com.gemstone.gemfire.internal.DataSerializableFixedID;
 import com.gemstone.gemfire.internal.Version;
 import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
+
 import org.jgroups.util.UUID;
 
 import java.io.DataInput;
@@ -130,6 +131,16 @@ public class GMSMember implements NetMember, DataSerializableFixedID
{
     this.uuidMSBs = msbs;
     this.uuidLSBs = lsbs;
   }
+  
+  public GMSMember(InetAddress i, int p, short version,
+      long msbs, long lsbs, int viewId) {
+    this.inetAddr = i;
+    this.udpPort = p;
+    this.versionOrdinal = version;
+    this.uuidMSBs = msbs;
+    this.uuidLSBs = lsbs;
+    this.vmViewId = viewId;
+  }
 
   public int getPort() {
     return this.udpPort;
@@ -396,6 +407,17 @@ public class GMSMember implements NetMember, DataSerializableFixedID
{
   
   @Override
   public void toData(DataOutput out) throws IOException {
+    writeShallowData(out);
+    out.writeInt(directPort);
+    out.writeByte(memberWeight);
+    out.writeByte(vmKind);
+    out.writeInt(processId);
+    
+    DataSerializer.writeString(name, out);
+    DataSerializer.writeStringArray(groups, out);
+}
+  
+  public void writeShallowData(DataOutput out) throws IOException {
     Version.writeOrdinal(out, this.versionOrdinal, true);
     
     int flags = 0;
@@ -406,18 +428,24 @@ public class GMSMember implements NetMember, DataSerializableFixedID
{
     DataSerializer.writeInetAddress(inetAddr, out);
     out.writeInt(udpPort);
     out.writeInt(vmViewId);
-    out.writeInt(directPort);
-    out.writeByte(memberWeight);
-    out.writeByte(vmKind);
-    out.writeInt(processId);
-    DataSerializer.writeString(name,  out);
-    DataSerializer.writeStringArray(groups, out);
     out.writeLong(uuidMSBs);
     out.writeLong(uuidLSBs);
+    
   }
 
   @Override
   public void fromData(DataInput in) throws IOException, ClassNotFoundException {
+    readShallowData(in);
+    this.directPort = in.readInt();
+    this.memberWeight = in.readByte();
+    this.vmKind = in.readByte();
+    this.processId = in.readInt();
+    
+    this.name = DataSerializer.readString(in);
+    this.groups = DataSerializer.readStringArray(in);
+  } 
+  
+  public void readShallowData(DataInput in) throws IOException, ClassNotFoundException {
     this.versionOrdinal = Version.readOrdinal(in);
     
     int flags = in.readShort();
@@ -427,14 +455,8 @@ public class GMSMember implements NetMember, DataSerializableFixedID
{
     this.inetAddr = DataSerializer.readInetAddress(in);
     this.udpPort = in.readInt();
     this.vmViewId = in.readInt();
-    this.directPort = in.readInt();
-    this.memberWeight = in.readByte();
-    this.vmKind = in.readByte();
-    this.processId = in.readInt();
-    this.name = DataSerializer.readString(in);
-    this.groups = DataSerializer.readStringArray(in);
     this.uuidMSBs = in.readLong();
-    this.uuidLSBs = in.readLong();
+    this.uuidLSBs = in.readLong();    
   }
 
   @Override
@@ -451,4 +473,15 @@ public class GMSMember implements NetMember, DataSerializableFixedID
{
     this.uuidLSBs = in.readLong();
     memberWeight = (byte)(in.readByte() & 0xFF);
   }
+  
+  public static void writeShallowNetMember(GMSMember mbr, DataOutput out) throws IOException
{
+    mbr.writeShallowData(out);
+  }
+  
+  public static GMSMember readShallowNetMember(DataInput in) throws ClassNotFoundException,
IOException {
+    GMSMember mbr = new GMSMember();
+    mbr.readShallowData(in);
+    
+    return mbr;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8860d9b3/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/interfaces/JoinLeave.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/interfaces/JoinLeave.java
b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/interfaces/JoinLeave.java
index 87409c5..3bacaf4 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/interfaces/JoinLeave.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/interfaces/JoinLeave.java
@@ -18,7 +18,9 @@ package com.gemstone.gemfire.distributed.internal.membership.gms.interfaces;
 
 import com.gemstone.gemfire.distributed.DistributedMember;
 import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
+import com.gemstone.gemfire.distributed.internal.membership.NetMember;
 import com.gemstone.gemfire.distributed.internal.membership.NetView;
+import com.gemstone.gemfire.distributed.internal.membership.gms.GMSMember;
 
 public interface JoinLeave extends Service {
 
@@ -50,6 +52,12 @@ public interface JoinLeave extends Service {
   InternalDistributedMember getMemberID();
   
   /**
+   * Get "InternalDistributedMember" from current view or prepared view.
+   * 
+   */
+  InternalDistributedMember getMemberID(NetMember m);
+  
+  /**
    * returns the current membership view
    */
   NetView getView();

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8860d9b3/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
index 080bdb3..5a4994a 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
@@ -25,6 +25,7 @@ import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.distributed.internal.DistributionManager;
 import com.gemstone.gemfire.distributed.internal.DistributionMessage;
 import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
+import com.gemstone.gemfire.distributed.internal.membership.NetMember;
 import com.gemstone.gemfire.distributed.internal.membership.NetView;
 import com.gemstone.gemfire.distributed.internal.membership.gms.GMSMember;
 import com.gemstone.gemfire.distributed.internal.membership.gms.GMSUtil;
@@ -141,7 +142,7 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
   /**
    * a new view being installed
    */
-  private NetView preparedView;
+  private volatile NetView preparedView;
 
   /**
    * the last view that conflicted with view preparation
@@ -2508,4 +2509,35 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
     logger.info("member " + fmbr + " failed availability check");
     return false;
   }
+  
+  private InternalDistributedMember getMemId(NetMember jgId, List<InternalDistributedMember>
members) {
+    for (InternalDistributedMember m : members) {
+      if (((GMSMember) m.getNetMember()).equals(jgId)) {
+        return m;
+      }
+    }
+    return null;
+  }
+
+  @Override
+  public InternalDistributedMember getMemberID(NetMember jgId) {
+    NetView v = currentView;
+    InternalDistributedMember ret = null;
+    if (v != null) {
+      ret = getMemId(jgId, v.getMembers());
+    }
+
+    if (ret == null) {
+      v = preparedView;
+      if (v != null) {
+        ret = getMemId(jgId, v.getMembers());
+      }
+    }
+
+    if (ret == null) {
+      return new InternalDistributedMember(jgId);
+    }
+    
+    return ret;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8860d9b3/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessenger.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessenger.java
b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessenger.java
index 5c0a327..5aca1a2 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessenger.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessenger.java
@@ -17,6 +17,7 @@
 package com.gemstone.gemfire.distributed.internal.membership.gms.messenger;
 
 import com.gemstone.gemfire.*;
+
 import static com.gemstone.gemfire.distributed.internal.membership.gms.GMSUtil.replaceStrings;
 import static com.gemstone.gemfire.internal.DataSerializableFixedID.JOIN_REQUEST;
 import static com.gemstone.gemfire.internal.DataSerializableFixedID.JOIN_RESPONSE;
@@ -47,7 +48,9 @@ import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 import com.gemstone.gemfire.internal.logging.log4j.AlertAppender;
 import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
 import com.gemstone.gemfire.internal.tcp.MemberShunnedException;
+
 import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+
 import org.apache.logging.log4j.Logger;
 import org.jgroups.*;
 import org.jgroups.Message.Flag;
@@ -888,7 +891,8 @@ public class JGroupsMessenger implements Messenger {
   
   byte[] serializeMessage(DistributionMessage gfmsg, HeapDataOutputStream out_stream) throws
IOException {
     
-    DataSerializer.writeObject(this.localAddress.getNetMember(), out_stream);
+    //DataSerializer.writeObject(this.localAddress.getShallowNetMember(), out_stream);
+    GMSMember.writeShallowNetMember((GMSMember)this.localAddress.getNetMember(), out_stream);
     DataSerializer.writeObject(gfmsg, out_stream);
     
     return out_stream.toByteArray();
@@ -960,13 +964,7 @@ public class JGroupsMessenger implements Messenger {
       if(isEncrypted) {
         result = readEncryptedMessage(dis, ordinal, encrypt);
       } else {
-        GMSMember m = DataSerializer.readObject(dis);
-  
-        result = DataSerializer.readObject(dis);
-  
-        DistributionMessage dm = (DistributionMessage)result;
-        
-        setSender(dm, m, ordinal);
+        result = deserializeMessage(dis, ordinal);        
       }
       
       
@@ -1053,12 +1051,8 @@ public class JGroupsMessenger implements Messenger {
           in = new VersionedDataInputStream(in, Version.fromOrdinalNoThrow(ordinal, true));
         }
 
-        GMSMember m = DataSerializer.readObject(in);
-
-        DistributionMessage result = (DistributionMessage) DataSerializer.readObject(in);
-
-        setSender(result, m, ordinal);
-
+        DistributionMessage result = deserializeMessage(in, ordinal);
+        
         if (pk != null) {
           
           /*InternalDistributedMember mbr = null;
@@ -1081,6 +1075,16 @@ public class JGroupsMessenger implements Messenger {
 
   }
   
+  DistributionMessage deserializeMessage(DataInputStream in, short ordinal) throws ClassNotFoundException,
IOException {
+    GMSMember m = GMSMember.readShallowNetMember(in);
+
+    DistributionMessage result = (DistributionMessage) DataSerializer.readObject(in);
+
+    setSender(result, m, ordinal);
+
+    return result;
+  }
+  
   /** look for certain messages that may need to be altered before being sent */
   void filterOutgoingMessage(DistributionMessage m) {
     switch (m.getDSFID()) {
@@ -1165,16 +1169,7 @@ public class JGroupsMessenger implements Messenger {
    * returns the member ID for the given GMSMember object
    */
   private InternalDistributedMember getMemberFromView(GMSMember jgId, short version) {
-    NetView v = services.getJoinLeave().getView();
-    
-    if (v != null) {
-      for (InternalDistributedMember m: v.getMembers()) {
-        if (((GMSMember)m.getNetMember()).equals(jgId)) {
-          return m;
-        }
-      }
-    }
-    return new InternalDistributedMember(jgId);
+    return this.services.getJoinLeave().getMemberID(jgId);
   }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8860d9b3/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMemberJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMemberJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMemberJUnitTest.java
index 7eef594..ef9f1b7 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMemberJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMemberJUnitTest.java
@@ -70,6 +70,30 @@ public class GMSMemberJUnitTest {
   }
   
   @Test
+  public void testShallowMemberEquals() {
+    GMSMember member1 = createGMSMember(new byte[] {1, 1, 1, 1, 1}, 1, 1, 1);
+    GMSMember member2 = new GMSMember(member1.getInetAddress(), 
+        member1.getPort(), 
+        member1.getVersionOrdinal(), 
+        member1.getUuidMSBs(), 
+        member1.getUuidLSBs(), 
+        member1.getVmViewId());
+    assertEquals(0, member1.compareTo(member2));
+  }
+  
+  @Test
+  public void testShallowMemberNotEquals() {
+    GMSMember member1 = createGMSMember(new byte[] {1, 1, 1, 1, 1}, 1, 1, 1);
+    GMSMember member2 = new GMSMember(member1.getInetAddress(), 
+        member1.getPort(), 
+        member1.getVersionOrdinal(), 
+        member1.getUuidMSBs(), 
+        member1.getUuidLSBs(), 
+        100);
+    assertEquals(false, member1.equals(member2));
+  }
+  
+  @Test
   public void testCompareToInetAddressIsShorterThan() {
     GMSMember member1 = createGMSMember(new byte[] {1, 1, 1, 1}, 1, 1, 1);
     GMSMember member2 = createGMSMember(new byte[] {1, 1, 1, 1, 1}, 1, 1, 1);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8860d9b3/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
index 4c6b1dd..476921e 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
@@ -948,7 +948,7 @@ public class JGroupsMessengerJUnitTest {
     initMocks(false, p);
     
     NetView v = createView(otherMbr);
-    
+    when(joinLeave.getMemberID(messenger.getMemberID().getNetMember())).thenReturn(messenger.getMemberID());
     GMSEncrypt otherMbrEncrptor = new GMSEncrypt(services);
     
     messenger.setPublicKey(otherMbrEncrptor.getPublicKeyBytes(), otherMbr);


Mime
View raw message