Skip to content

Commit

Permalink
GEODE-7698: Extracting a superclass of InternalDistributedMember
Browse files Browse the repository at this point in the history
GEODE-7698: Extracting a superclass of InternalDistributedMember

We need a concrete MemberIdentifier implementation in geode-membership
to test membership.

Extracting a superclass of InternalDistributedMember,
MemberIdentifierImpl, which contains pretty much all of the
InternalDistributedMember logic. InternalDistributedMember now just
extends that class and implements DistributedMember.

Removing unecessary use of SocketCreator during IDM deserialization. We were 
using flags and methods on SocketCreator to either change or cache the hostName
that we read off the wire from the remote member. We don't want to do either of
those things during deserialization. We should just keep the hostname we read
as is. This logic was used to change the toString value of ids that come from
clients to use the ip address instead of the hostname. Instead of changing the
deserialization logic, we change the addFixedToString logic.

Check for IP address rather than SocketCreator.resolve_dns in addFixedToString. 
InternalDistributedMember has a dependency on this mutable static flag in it's
to string, which is not ideal. It looks like the intention was to only shorten
the hostname if it is dns name, not an ip address.
  • Loading branch information
upthewaterspout authored Jan 15, 2020
1 parent 1fe0183 commit 5a8b992
Show file tree
Hide file tree
Showing 39 changed files with 1,224 additions and 1,171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* the License.
*/

package org.apache.geode.distributed.internal.membership.gms;
package org.apache.geode.distributed.internal.membership.api;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -24,10 +24,6 @@
import org.junit.Before;
import org.junit.Test;

import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
import org.apache.geode.distributed.internal.membership.api.MemberData;
import org.apache.geode.distributed.internal.membership.api.MemberDataBuilder;
import org.apache.geode.distributed.internal.membership.api.MemberIdentifier;
import org.apache.geode.internal.inet.LocalHostUtil;
import org.apache.geode.internal.serialization.Version;

Expand Down Expand Up @@ -112,21 +108,21 @@ public void testSetVersionOrdinal() {
public void membersAreEqual() {
MemberData memberData = MemberDataBuilder.newBuilderForLocalHost("hostname")
.setMembershipPort(1).build();
InternalDistributedMember member1 = factory.create(memberData);
MemberIdentifierImpl member1 = factory.create(memberData);
memberData = MemberDataBuilder.newBuilderForLocalHost("hostname")
.setMembershipPort(1).build();
InternalDistributedMember member2 = factory.create(memberData);
MemberIdentifierImpl member2 = factory.create(memberData);
assertThat(factory.getComparator().compare(member1, member2)).isZero();
}

@Test
public void membersAreNotEqual() {
MemberData memberData = MemberDataBuilder.newBuilderForLocalHost("hostname")
.setMembershipPort(1).build();
InternalDistributedMember member1 = factory.create(memberData);
MemberIdentifierImpl member1 = factory.create(memberData);
memberData = MemberDataBuilder.newBuilderForLocalHost("hostname")
.setMembershipPort(2).build();
InternalDistributedMember member2 = factory.create(memberData);
MemberIdentifierImpl member2 = factory.create(memberData);
assertThat(factory.getComparator().compare(member1, member2)).isLessThan(0);
assertThat(factory.getComparator().compare(member2, member1)).isGreaterThan(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
import org.apache.geode.distributed.internal.membership.api.LifecycleListener;
import org.apache.geode.distributed.internal.membership.api.MemberIdentifier;
import org.apache.geode.distributed.internal.membership.api.MemberIdentifierFactoryImpl;
import org.apache.geode.distributed.internal.membership.api.MemberIdentifierImpl;
import org.apache.geode.distributed.internal.membership.api.MemberStartupException;
import org.apache.geode.distributed.internal.membership.api.Membership;
import org.apache.geode.distributed.internal.membership.api.MembershipBuilder;
Expand Down Expand Up @@ -115,10 +117,10 @@ public int getVmKind() {
TcpClient locatorClient = new TcpClient(socketCreator, dsfidSerializer.getObjectSerializer(),
dsfidSerializer.getObjectDeserializer());

LifecycleListener<InternalDistributedMember> lifeCycleListener = mock(LifecycleListener.class);
LifecycleListener<MemberIdentifierImpl> lifeCycleListener = mock(LifecycleListener.class);

final Membership<InternalDistributedMember> membership =
MembershipBuilder.<InternalDistributedMember>newMembershipBuilder(
final Membership<MemberIdentifierImpl> membership =
MembershipBuilder.<MemberIdentifierImpl>newMembershipBuilder(
socketCreator, locatorClient, dsfidSerializer, memberIdFactory)
.setConfig(config)
.setLifecycleListener(lifeCycleListener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@
import org.apache.geode.distributed.internal.membership.api.MemberData;
import org.apache.geode.distributed.internal.membership.api.MemberDataBuilder;
import org.apache.geode.distributed.internal.membership.api.MemberIdentifier;
import org.apache.geode.distributed.internal.membership.api.MemberIdentifierFactoryImpl;
import org.apache.geode.distributed.internal.membership.api.MemberStartupException;
import org.apache.geode.distributed.internal.membership.api.MembershipConfig;
import org.apache.geode.distributed.internal.membership.gms.GMSMembershipView;
import org.apache.geode.distributed.internal.membership.gms.MemberIdentifierFactoryImpl;
import org.apache.geode.distributed.internal.membership.gms.Services;
import org.apache.geode.distributed.internal.membership.gms.Services.Stopper;
import org.apache.geode.distributed.internal.membership.gms.fd.GMSHealthMonitor.ClientSocketHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -58,14 +59,15 @@
import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
import org.apache.geode.distributed.internal.membership.adapter.ServiceConfig;
import org.apache.geode.distributed.internal.membership.api.Authenticator;
import org.apache.geode.distributed.internal.membership.api.MemberData;
import org.apache.geode.distributed.internal.membership.api.MemberDataBuilder;
import org.apache.geode.distributed.internal.membership.api.MemberIdentifier;
import org.apache.geode.distributed.internal.membership.api.MemberIdentifierFactory;
import org.apache.geode.distributed.internal.membership.api.MemberStartupException;
import org.apache.geode.distributed.internal.membership.api.MembershipConfig;
import org.apache.geode.distributed.internal.membership.api.MembershipConfigurationException;
import org.apache.geode.distributed.internal.membership.gms.GMSMembershipView;
import org.apache.geode.distributed.internal.membership.gms.GMSUtil;
import org.apache.geode.distributed.internal.membership.gms.MemberIdentifierFactoryImpl;
import org.apache.geode.distributed.internal.membership.gms.Services;
import org.apache.geode.distributed.internal.membership.gms.Services.Stopper;
import org.apache.geode.distributed.internal.membership.gms.interfaces.HealthMonitor;
Expand Down Expand Up @@ -142,7 +144,18 @@ public void initMocks(boolean enableNetworkPartition, boolean useTestGMSJoinLeav
when(services.getCancelCriterion()).thenReturn(stopper);
when(services.getManager()).thenReturn(manager);
when(services.getHealthMonitor()).thenReturn(healthMonitor);
when(services.getMemberFactory()).thenReturn(new MemberIdentifierFactoryImpl());
when(services.getMemberFactory())
.thenReturn(new MemberIdentifierFactory<InternalDistributedMember>() {
@Override
public InternalDistributedMember create(MemberData memberInfo) {
return new InternalDistributedMember(memberInfo);
}

@Override
public Comparator<InternalDistributedMember> getComparator() {
return InternalDistributedMember::compareTo;
}
});

gmsJoinLeaveMemberId = services.getMemberFactory().create(
MemberDataBuilder.newBuilderForLocalHost("localhost")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
import org.apache.geode.distributed.internal.membership.adapter.ServiceConfig;
import org.apache.geode.distributed.internal.membership.api.MemberDisconnectedException;
import org.apache.geode.distributed.internal.membership.api.MemberIdentifier;
import org.apache.geode.distributed.internal.membership.api.MemberIdentifierFactoryImpl;
import org.apache.geode.distributed.internal.membership.api.MembershipClosedException;
import org.apache.geode.distributed.internal.membership.api.MembershipConfig;
import org.apache.geode.distributed.internal.membership.api.Message;
import org.apache.geode.distributed.internal.membership.gms.GMSMembershipView;
import org.apache.geode.distributed.internal.membership.gms.MemberIdentifierFactoryImpl;
import org.apache.geode.distributed.internal.membership.gms.Services;
import org.apache.geode.distributed.internal.membership.gms.Services.Stopper;
import org.apache.geode.distributed.internal.membership.gms.interfaces.HealthMonitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,11 @@ org/apache/geode/distributed/internal/locks/NonGrantorDestroyedProcessor$NonGran
fromData,17
toData,17

org/apache/geode/distributed/internal/membership/InternalDistributedMember,6
fromData,39
fromDataPre_GFE_7_1_0_0,310
fromDataPre_GFE_9_0_0_0,310
toData,35
toDataPre_GFE_7_1_0_0,279
toDataPre_GFE_9_0_0_0,275
org/apache/geode/distributed/internal/membership/InternalDistributedMember,4
fromDataPre_GFE_7_1_0_0,7
fromDataPre_GFE_9_0_0_0,7
toDataPre_GFE_7_1_0_0,7
toDataPre_GFE_9_0_0_0,7

org/apache/geode/distributed/internal/membership/adapter/LocalViewMessage,2
fromData,8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ public static void writeObjectAsByteArray(Object obj, DataOutput out) throws IOE
if (object instanceof HeapDataOutputStream) {
hdos = (HeapDataOutputStream) object;
} else {
Version v = InternalDataSerializer.getVersionForDataStreamOrNull(out);
Version v = StaticSerialization.getVersionForDataStreamOrNull(out);
if (v == null) {
v = Version.CURRENT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.apache.geode.internal.cache.tier.sockets.ServerQueueStatus;
import org.apache.geode.internal.security.SecurityService;
import org.apache.geode.internal.serialization.ByteArrayDataInput;
import org.apache.geode.internal.serialization.StaticSerialization;
import org.apache.geode.internal.serialization.Version;
import org.apache.geode.internal.serialization.VersionedDataInputStream;
import org.apache.geode.internal.serialization.VersionedDataOutputStream;
Expand Down Expand Up @@ -269,7 +270,7 @@ public ServerQueueStatus handshakeWithServer(Connection conn, ServerLocation loc
private InternalDistributedMember readServerMember(DataInputStream p_dis) throws IOException {

byte[] memberBytes = DataSerializer.readByteArray(p_dis);
Version v = InternalDataSerializer.getVersionForDataStreamOrNull(p_dis);
Version v = StaticSerialization.getVersionForDataStreamOrNull(p_dis);
ByteArrayDataInput dis = new ByteArrayDataInput(memberBytes, v);
try {
return DataSerializer.readObject(dis);
Expand Down
Loading

0 comments on commit 5a8b992

Please sign in to comment.