Skip to content

Commit

Permalink
Revert "[HZ-581] Address issues with hostnames (hazelcast#20014)"
Browse files Browse the repository at this point in the history
This reverts commit 16ec195.
  • Loading branch information
Ufuk Yılmaz committed Jan 12, 2022
1 parent 913bbc8 commit fa84ddd
Show file tree
Hide file tree
Showing 58 changed files with 405 additions and 2,282 deletions.
Expand Up @@ -316,9 +316,9 @@ public boolean bind(final ClientEndpoint endpoint) {
// On such a case, `ClientEngine#connectionRemoved` will not be called for this connection since
// we did not register the connection.
// Endpoint removal logic(inside `ClientEngine#connectionRemoved`) will not be able to run, instead endpoint
// will be cleaned up by ClientHeartbeatMonitor#cleanupEndpointsWithDeadConnections later.
if (conn.getRemoteAddress() != null && endpoint.getUuid() != null) {
node.getServer().getConnectionManager(CLIENT).register(conn.getRemoteAddress(), endpoint.getUuid(), conn);
// will be cleaned up by ClientHearbeatMonitor#cleanupEndpointsWithDeadConnections later.
if (conn.getRemoteAddress() != null) {
node.getServer().getConnectionManager(CLIENT).register(conn.getRemoteAddress(), conn);
}
}

Expand Down Expand Up @@ -438,11 +438,7 @@ public void connectionRemoved(Connection c) {
logger.finest("connectionRemoved: No endpoint for connection:" + connection);
return;
}
UUID clientUuid = endpoint.getUuid();
if (clientUuid != null) {
node.getLocalAddressRegistry().tryRemoveRegistration(clientUuid,
endpoint.getConnection().getRemoteAddress());
}

endpointManager.removeEndpoint(endpoint);
}
}
Expand Down Expand Up @@ -484,8 +480,10 @@ Map<UUID, String> getClientsInCluster() {
if (endpoints == null) {
continue;
}
// Merge connected clients according to their UUID
clientsMap.putAll(endpoints);
//Merge connected clients according to their UUID
for (Map.Entry<UUID, String> entry : endpoints.entrySet()) {
clientsMap.put(entry.getKey(), entry.getValue());
}
} catch (Exception e) {
logger.warning("Cannot get client information from: " + target.toString(), e);
}
Expand Down
Expand Up @@ -21,6 +21,7 @@
import com.hazelcast.internal.nio.Connection;

import java.util.Map;
import java.util.UUID;

/**
* The ClientConnection is connection that lives on the client side on behalf of a Java client.
Expand All @@ -47,4 +48,5 @@ public interface ClientConnection extends Connection {
// used in tests
Map<Long, EventHandler> getEventHandlers();

UUID getRemoteUuid();
}
Expand Up @@ -45,7 +45,6 @@ public ClientClusterProxy(ClientClusterServiceImpl clusterService) {
}

@Override
@Nonnull
public UUID addMembershipListener(@Nonnull MembershipListener listener) {
return clusterService.addMembershipListener(listener);
}
Expand All @@ -56,14 +55,12 @@ public boolean removeMembershipListener(@Nonnull UUID registrationId) {
}

@Override
@Nonnull
public Set<Member> getMembers() {
final Collection<Member> members = clusterService.getMemberList();
return new LinkedHashSet<>(members);
}

@Override
@Nonnull
public Member getLocalMember() {
throw new UnsupportedOperationException("Client has no local member!");
}
Expand All @@ -85,7 +82,6 @@ public void changeClusterState(@Nonnull ClusterState newState) {
}

@Override
@Nonnull
public Version getClusterVersion() {
throw new UnsupportedOperationException();
}
Expand All @@ -96,7 +92,6 @@ public HotRestartService getHotRestartService() {
}

@Override
@Nonnull
public PersistenceService getPersistenceService() {
throw new UnsupportedOperationException();
}
Expand Down
5 changes: 0 additions & 5 deletions hazelcast/src/main/java/com/hazelcast/cluster/Cluster.java
Expand Up @@ -54,7 +54,6 @@ public interface Cluster {
* @throws java.lang.NullPointerException if listener is null
* @see #removeMembershipListener(UUID)
*/
@Nonnull
UUID addMembershipListener(@Nonnull MembershipListener listener);

/**
Expand All @@ -80,7 +79,6 @@ public interface Cluster {
*
* @return current members in the cluster
*/
@Nonnull
Set<Member> getMembers();

/**
Expand All @@ -95,7 +93,6 @@ public interface Cluster {
*
* @return this Hazelcast instance member
*/
@Nonnull
Member getLocalMember();

/**
Expand Down Expand Up @@ -228,7 +225,6 @@ public interface Cluster {
* @return the version at which this cluster operates.
* @since 3.8
*/
@Nonnull
Version getClusterVersion();

/**
Expand All @@ -250,7 +246,6 @@ public interface Cluster {
* supported on this instance (e.g. on client)
* @since 5.0
*/
@Nonnull
PersistenceService getPersistenceService();

/**
Expand Down
20 changes: 0 additions & 20 deletions hazelcast/src/main/java/com/hazelcast/instance/AddressPicker.java
Expand Up @@ -53,28 +53,8 @@ public interface AddressPicker {
*/
Address getPublicAddress(EndpointQualifier qualifier);

/**
* Returns all public {@link Address}es of this member which are advertised to other
* members, mapped by corresponding {@link EndpointQualifier}. Also, see
* {@link com.hazelcast.internal.cluster.impl.MemberHandshake} and
* {@link com.hazelcast.internal.server.tcp.SendMemberHandshakeTask}.
*
* @return a {@code Map<EndpointQualifier, Address>} of this member's public addresses
* or an empty map if called before {@link #pickAddress()}
* @since 3.12
*/
Map<EndpointQualifier, Address> getPublicAddressMap();

/**
* Returns all bound server socket {@link Address}es of this member, mapped by
* corresponding {@link EndpointQualifier}
*
* @return a {@code Map<EndpointQualifier, Address>} of the bound addresses of
* this member's server sockets or an empty map if called before {@link #pickAddress()}
* @since 5.1
*/
Map<EndpointQualifier, Address> getBindAddressMap();

/**
* Returns a server channel.
*
Expand Down
Expand Up @@ -92,16 +92,6 @@ public Map<EndpointQualifier, Address> getPublicAddressMap() {
return pubAddressMap;
}

@Override
public Map<EndpointQualifier, Address> getBindAddressMap() {
Map<EndpointQualifier, Address> bindAddressMap = new HashMap<>(pickers.size());
for (Map.Entry<EndpointQualifier, AddressPicker> entry : pickers.entrySet()) {
bindAddressMap.put(entry.getKey(), entry.getValue().getBindAddress(entry.getKey()));
}

return bindAddressMap;
}

@Override
public ServerSocketChannel getServerSocketChannel(EndpointQualifier qualifier) {
return pickers.get(qualifier).getServerSocketChannel(qualifier);
Expand Down
Expand Up @@ -439,13 +439,6 @@ public Map<EndpointQualifier, Address> getPublicAddressMap() {
return publicAddressMap;
}

@Override
public Map<EndpointQualifier, Address> getBindAddressMap() {
HashMap<EndpointQualifier, Address> bindAddressMap = new HashMap<>();
bindAddressMap.put(MEMBER, bindAddress);
return bindAddressMap;
}

void setHostnameResolver(HostnameResolver hostnameResolver) {
this.hostnameResolver = checkNotNull(hostnameResolver);
}
Expand Down
Expand Up @@ -24,14 +24,13 @@
import com.hazelcast.internal.metrics.MetricsRegistry;
import com.hazelcast.internal.networking.ChannelErrorHandler;
import com.hazelcast.internal.networking.Networking;
import com.hazelcast.internal.server.tcp.ServerSocketRegistry;
import com.hazelcast.internal.networking.nio.NioNetworking;
import com.hazelcast.internal.nio.ClassLoaderUtil;
import com.hazelcast.internal.server.Server;
import com.hazelcast.internal.server.tcp.LocalAddressRegistry;
import com.hazelcast.internal.server.tcp.ServerSocketRegistry;
import com.hazelcast.internal.server.tcp.TcpServer;
import com.hazelcast.internal.server.tcp.TcpServerConnectionChannelErrorHandler;
import com.hazelcast.internal.server.tcp.TcpServerContext;
import com.hazelcast.internal.server.tcp.TcpServerConnectionChannelErrorHandler;
import com.hazelcast.internal.server.tcp.TcpServer;
import com.hazelcast.internal.util.InstantiationUtils;
import com.hazelcast.logging.ILogger;
import com.hazelcast.logging.impl.LoggingServiceImpl;
Expand Down Expand Up @@ -144,7 +143,7 @@ public Joiner createJoiner(Node node) {
}

@Override
public Server createServer(Node node, ServerSocketRegistry registry, LocalAddressRegistry addressRegistry) {
public Server createServer(Node node, ServerSocketRegistry registry) {
TcpServerContext context = new TcpServerContext(node, node.nodeEngine);
Networking networking = createNetworking(node);
Config config = node.getConfig();
Expand All @@ -153,7 +152,6 @@ public Server createServer(Node node, ServerSocketRegistry registry, LocalAddres
return new TcpServer(config,
context,
registry,
addressRegistry,
metricsRegistry,
networking,
node.getNodeExtension().createChannelInitializerFn(context));
Expand Down
Expand Up @@ -195,15 +195,7 @@ public Map<EndpointQualifier, Address> getPublicAddressMap() {
for (Map.Entry<EndpointQualifier, InetSocketAddress> entry : publicAddresses.entrySet()) {
mappings.put(entry.getKey(), new Address(entry.getValue()));
}
return mappings;
}

@Override
public Map<EndpointQualifier, Address> getBindAddressMap() {
Map<EndpointQualifier, Address> mappings = new HashMap<>(bindAddresses.size());
for (Map.Entry<EndpointQualifier, InetSocketAddress> entry : bindAddresses.entrySet()) {
mappings.put(entry.getKey(), new Address(entry.getValue()));
}
return mappings;
}
}
30 changes: 8 additions & 22 deletions hazelcast/src/main/java/com/hazelcast/instance/impl/Node.java
Expand Up @@ -71,7 +71,6 @@
import com.hazelcast.internal.serialization.InternalSerializationService;
import com.hazelcast.internal.serialization.impl.compact.schema.MemberSchemaService;
import com.hazelcast.internal.server.Server;
import com.hazelcast.internal.server.tcp.LocalAddressRegistry;
import com.hazelcast.internal.server.tcp.ServerSocketRegistry;
import com.hazelcast.internal.services.GracefulShutdownAwareService;
import com.hazelcast.internal.usercodedeployment.UserCodeDeploymentClassLoader;
Expand Down Expand Up @@ -163,7 +162,6 @@ public class Node {
*/
public final Address address;
public final SecurityContext securityContext;

private final ILogger logger;
private final AtomicBoolean shuttingDown = new AtomicBoolean(false);
private final NodeShutdownHookThread shutdownHookThread;
Expand All @@ -175,11 +173,8 @@ public class Node {
private final BuildInfo buildInfo;
private final HealthMonitor healthMonitor;
private final Joiner joiner;
private final LocalAddressRegistry localAddressRegistry;
private ManagementCenterService managementCenterService;

// it can be changed on cluster service reset see: ClusterServiceImpl#resetLocalMemberUuid
private volatile UUID thisUuid;
private volatile NodeState state = NodeState.STARTING;

/**
Expand Down Expand Up @@ -223,15 +218,14 @@ public Node(HazelcastInstanceImpl hazelcastInstance, Config staticConfig, NodeCo

try {
boolean liteMember = config.isLiteMember();
nodeExtension = nodeContext.createNodeExtension(this);
address = addressPicker.getPublicAddress(MEMBER);
thisUuid = nodeExtension.createMemberUuid();
nodeExtension = nodeContext.createNodeExtension(this);
final Map<String, String> memberAttributes = findMemberAttributes(
new MemberAttributeConfigReadOnly(config.getMemberAttributeConfig()));
MemberImpl localMember = new MemberImpl.Builder(addressPicker.getPublicAddressMap())
.version(version)
.localMember(true)
.uuid(thisUuid)
.uuid(nodeExtension.createMemberUuid())
.attributes(memberAttributes)
.liteMember(liteMember)
.instance(hazelcastInstance)
Expand All @@ -254,8 +248,8 @@ public Node(HazelcastInstanceImpl hazelcastInstance, Config staticConfig, NodeCo
config.onSecurityServiceUpdated(getSecurityService());
MetricsRegistry metricsRegistry = nodeEngine.getMetricsRegistry();
metricsRegistry.provideMetrics(nodeExtension);
localAddressRegistry = new LocalAddressRegistry(this, addressPicker);
server = nodeContext.createServer(this, serverSocketRegistry, localAddressRegistry);

server = nodeContext.createServer(this, serverSocketRegistry);
healthMonitor = new HealthMonitor(this);
clientEngine = hasClientServerSocket() ? new ClientEngineImpl(this) : new NoOpClientEngine();
JoinConfig joinConfig = getActiveMemberNetworkConfig(this.config).getJoin();
Expand Down Expand Up @@ -434,14 +428,6 @@ public Address getThisAddress() {
return address;
}

public UUID getThisUuid() {
return thisUuid;
}

public void setThisUuid(UUID uuid) {
thisUuid = uuid;
}

public MemberImpl getLocalMember() {
return clusterService.getLocalMember();
}
Expand Down Expand Up @@ -739,10 +725,6 @@ public DiscoveryService getDiscoveryService() {
return discoveryService;
}

public LocalAddressRegistry getLocalAddressRegistry() {
return localAddressRegistry;
}

private enum ShutdownHookPolicy {
TERMINATE,
GRACEFUL
Expand Down Expand Up @@ -875,6 +857,10 @@ private boolean usePublicAddress(JoinConfig join) {
|| allUsePublicAddress(AliasedDiscoveryConfigUtils.aliasedDiscoveryConfigsFrom(join));
}

public UUID getThisUuid() {
return clusterService.getThisUuid();
}

public Config getConfig() {
return config;
}
Expand Down
Expand Up @@ -18,7 +18,6 @@

import com.hazelcast.internal.cluster.Joiner;
import com.hazelcast.instance.AddressPicker;
import com.hazelcast.internal.server.tcp.LocalAddressRegistry;
import com.hazelcast.internal.server.tcp.ServerSocketRegistry;
import com.hazelcast.internal.server.Server;

Expand All @@ -37,5 +36,6 @@ public interface NodeContext {

Joiner createJoiner(Node node);

Server createServer(Node node, ServerSocketRegistry registry, LocalAddressRegistry addressRegistry);
// TODO Consider the changes here (JET?)
Server createServer(Node node, ServerSocketRegistry registry);
}

0 comments on commit fa84ddd

Please sign in to comment.