Skip to content

Commit

Permalink
GEODE-7658: Removing hostname resolution from TcpSocketCreatorAdapter
Browse files Browse the repository at this point in the history
We didn't need these methods on TcpSocketCreatorAdapter.
* resolveDns is based on whether network partition detection is enabled, which
we can access directly in membership.

* getHostName uses a static hostname cache that we don't need to use
for membership when creating the local address.

* getLocalHost has moved to a utility in geode-common.
  • Loading branch information
upthewaterspout committed Jan 8, 2020
1 parent edf0663 commit 8850167
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private void initMocks(boolean enableMcast, Properties addProp) throws Exception

socketCreator = asTcpSocketCreator(SocketCreatorFactory.setDistributionConfig(config)
.getSocketCreatorForComponent(SecurableCommunicationChannel.CLUSTER));
messenger = new JGroupsMessenger<MemberIdentifier>(socketCreator);
messenger = new JGroupsMessenger<MemberIdentifier>();
messenger.init(services);

// if I do this earlier then test this return messenger as null
Expand Down Expand Up @@ -878,7 +878,7 @@ public void testUseOldJChannel() throws Exception {
JChannel channel = messenger.myChannel;
tconfig.setOldDSMembershipInfo(new MembershipInformationImpl(channel,
new ConcurrentLinkedQueue<>()));
JGroupsMessenger newMessenger = new JGroupsMessenger(socketCreator);
JGroupsMessenger newMessenger = new JGroupsMessenger();
newMessenger.init(services);
newMessenger.start();
newMessenger.started();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Objects;

import org.apache.geode.distributed.internal.tcpserver.ConnectionWatcher;
import org.apache.geode.distributed.internal.tcpserver.TcpSocketCreator;
import org.apache.geode.internal.inet.LocalHostUtil;
import org.apache.geode.internal.net.SocketCreator;

/**
Expand Down Expand Up @@ -61,16 +59,6 @@ public ServerSocket createServerSocket(final int nport, final int backlog,
return socketCreator.createServerSocket(nport, backlog, bindAddr);
}

@Override
public InetAddress getLocalHost() throws UnknownHostException {
return LocalHostUtil.getLocalHost();
}

@Override
public String getHostName(final InetAddress addr) {
return SocketCreator.getHostName(addr);
}

@Override
public ServerSocket createServerSocketUsingPortRange(final InetAddress ba, final int backlog,
final boolean isBindAddress, final boolean useNIO, final int tcpBufferSize,
Expand Down Expand Up @@ -99,8 +87,4 @@ public void handshakeIfSocketIsSSL(final Socket socket, final int timeout) throw
socketCreator.handshakeIfSocketIsSSL(socket, timeout);
}

@Override
public boolean resolveDns() {
return socketCreator.resolve_dns;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public Services(Manager<ID> membershipManager, MembershipStatistics stats,
this.manager = membershipManager;
this.joinLeave = new GMSJoinLeave<>(locatorClient);
this.healthMon = new GMSHealthMonitor<>(socketCreator);
this.messenger = new JGroupsMessenger<>(socketCreator);
this.messenger = new JGroupsMessenger<>();
this.auth = authenticator;
this.serializer = serializer;
this.memberFactory = memberFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
import org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse;
import org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage;
import org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage;
import org.apache.geode.distributed.internal.tcpserver.TcpSocketCreator;
import org.apache.geode.internal.cache.DistributedCacheOperation;
import org.apache.geode.internal.inet.LocalHostUtil;
import org.apache.geode.internal.serialization.BufferDataOutputStream;
import org.apache.geode.internal.serialization.StaticSerialization;
import org.apache.geode.internal.serialization.Version;
Expand Down Expand Up @@ -135,11 +135,8 @@ public class JGroupsMessenger<ID extends MemberIdentifier> implements Messenger<
ID localAddress;
JGAddress jgAddress;
private Services<ID> services;
private TcpSocketCreator socketCreator;

public JGroupsMessenger(final TcpSocketCreator socketCreator) {
this.socketCreator = socketCreator;
}
public JGroupsMessenger() {}

/** handlers that receive certain classes of messages instead of the Manager */
private final Map<Class<?>, MessageHandler<?>> handlers = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -285,7 +282,7 @@ public void init(Services<ID> s) throws MembershipConfigurationException {
// JGroups UDP protocol requires a bind address
if (str == null || str.length() == 0) {
try {
str = socketCreator.getLocalHost().getHostAddress();
str = LocalHostUtil.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
throw new MembershipConfigurationException(e.getMessage(), e);
}
Expand Down Expand Up @@ -552,7 +549,7 @@ private void establishLocalAddress() throws MemberStartupException {

// establish the DistributedSystem's address
String hostname =
socketCreator.resolveDns() ? socketCreator.getHostName(jgAddress.getInetAddress())
!config.isNetworkPartitionDetectionEnabled() ? jgAddress.getInetAddress().getHostName()
: jgAddress.getInetAddress().getHostAddress();
GMSMemberData gmsMember = new GMSMemberData(jgAddress.getInetAddress(),
hostname, jgAddress.getPort(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.net.InetAddress;
import java.util.Properties;
import java.util.concurrent.RejectedExecutionException;

Expand All @@ -42,7 +41,6 @@
import org.apache.geode.distributed.internal.membership.api.MembershipStatistics;
import org.apache.geode.distributed.internal.membership.gms.Services;
import org.apache.geode.distributed.internal.membership.gms.interfaces.Manager;
import org.apache.geode.distributed.internal.tcpserver.TcpSocketCreator;
import org.apache.geode.test.junit.categories.MembershipTest;

/**
Expand Down Expand Up @@ -172,11 +170,9 @@ public void messengerStackHoldsStatRecorder() throws Exception {
when(mockConfig.getMembershipPortRange()).thenReturn(new int[] {0, 10});
when(mockConfig.getSecurityUDPDHAlgo()).thenReturn("");
when(mockServices.getConfig()).thenReturn(mockConfig);
TcpSocketCreator socketCreator = mock(TcpSocketCreator.class);
when(socketCreator.getLocalHost()).thenReturn(InetAddress.getLocalHost());


JGroupsMessenger messenger = new JGroupsMessenger(socketCreator);
JGroupsMessenger messenger = new JGroupsMessenger();
messenger.init(mockServices);
String jgroupsConfig = messenger.jgStackConfig;
System.out.println(jgroupsConfig);
Expand All @@ -187,7 +183,7 @@ public void messengerStackHoldsStatRecorder() throws Exception {
when(mockServices.getConfig()).thenReturn(mockConfig);


messenger = new JGroupsMessenger(socketCreator);
messenger = new JGroupsMessenger();
messenger.init(mockServices);
assertTrue(jgroupsConfig.contains("gms.messenger.StatRecorder"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;


/**
Expand All @@ -33,10 +32,6 @@ public interface TcpSocketCreator {
ServerSocket createServerSocket(int nport, int backlog, InetAddress bindAddr)
throws IOException;

InetAddress getLocalHost() throws UnknownHostException;

String getHostName(InetAddress addr);

ServerSocket createServerSocketUsingPortRange(InetAddress ba, int backlog,
boolean isBindAddress, boolean useNIO, int tcpBufferSize, int[] tcpPortRange,
boolean sslConnection) throws IOException;
Expand All @@ -50,5 +45,4 @@ Socket connect(InetAddress inetadd, int port, int timeout,

void handshakeIfSocketIsSSL(Socket socket, int timeout) throws IOException;

boolean resolveDns();
}

0 comments on commit 8850167

Please sign in to comment.