Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HZ-581] Address issues with hostnames #20014

Merged
merged 86 commits into from Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
4a05f70
WIP - Handle TcpServerConnections with UUID
Nov 30, 2021
f8595d3
WIP - Adjust test classes
Nov 30, 2021
0215da4
WIP
Nov 30, 2021
3f43451
Update the Node#thisUuid in cluster service reset
Dec 1, 2021
40bcf59
Do more proper null handling in mock network classes
Dec 1, 2021
fbcaf94
Tidy up handshake processing
Dec 1, 2021
898209b
Add member uuid into MockServerContext
Dec 1, 2021
46f5afd
Register/deregister address-uuid entries upon membership changes
Dec 1, 2021
f5820d9
Small cleanup
Dec 1, 2021
c3d74a6
Fix style
Dec 1, 2021
f48d286
Tidy up LinkedAddresses and LocalAddressRegistry
Dec 1, 2021
e384c90
Handle uuid-address registration for the client connections
Dec 1, 2021
8c60b97
Fix style
Dec 2, 2021
3232a1e
Cleanup
Dec 2, 2021
c8b0256
Reflect the changes to TcpServerControlTest
Dec 6, 2021
d60fd90
Remove address registration stuff from MembershipManager
Dec 7, 2021
1dc1127
Fix style
Dec 7, 2021
c67a0f3
Reset address registry on split-brain-merge
vbekiaris Dec 7, 2021
8b31af4
Change the address registry removal timing
Dec 7, 2021
3f00596
Handle duplicate connections between members
Dec 8, 2021
940b8c3
Fix style
Dec 8, 2021
3b35445
Add some tests for address registry
Dec 9, 2021
226bb0f
Enhance TcpServerControlTest
Dec 10, 2021
34987a2
Add javadoc and more tests to the address registry
Dec 13, 2021
601c02b
Add tests
Dec 13, 2021
dcbe5ae
Add local member's addresses to the address registry
Dec 14, 2021
3800be9
Use public address as a primary address in any case
Dec 14, 2021
88ba1ce
Do address registrations in ConnectionManager#register
Dec 16, 2021
57a2eba
Merge remote-tracking branch 'upstream/master' into 5.1/hostname-fix-…
Dec 16, 2021
4e24b37
Remove LocalAddressRegistry#getPrimaryAddress(Address)
Dec 17, 2021
7aa1f7a
Perform address registration in MockNetwork
Dec 20, 2021
20152e1
Add all local addresses to address registry
Dec 21, 2021
5e9e2da
Merge remote-tracking branch 'upstream/master' into 5.1/hostname-fix-…
Dec 21, 2021
33cdc0f
Handle local addresses separately in LocalAddressRegistry
Dec 21, 2021
815e993
Fix shouldConnectTo
Dec 21, 2021
fa5af7f
Fix up Handle local addresses separately in LocalAddressRegistry
Dec 21, 2021
20c2b73
Fix NPE in mock tests
Dec 21, 2021
dcdd5bb
Resolve the given address before perform lookup
Dec 21, 2021
4d09104
Add javadocs to address picker methods
Dec 22, 2021
7382ecc
Give explicit priority to the member protocol public address in addre…
Dec 22, 2021
ab3b931
Fix TcpIpJoiner#isLocalAddress
Dec 21, 2021
828d47a
Improve logging on blacklist
Dec 20, 2021
e114bb1
Handle blacklisted addresses in ClusterMismatchOp
Dec 17, 2021
7d20c8c
Fix style
Dec 22, 2021
70c7370
Fix local address registration issue
Dec 22, 2021
6070012
Add TcpIpHostnameJoinTest
Dec 17, 2021
5134a4e
Add trace logs to hostname join tests
Dec 20, 2021
da4ca54
Add null check to serverSocketChannel access
Dec 22, 2021
b9ba29d
Try not to lose targetAddress of the connection
Dec 23, 2021
a604e91
Address part of the reviews
Dec 23, 2021
03106c8
Add null check to registered target address
Dec 23, 2021
4db748c
Handle duplicate connections after addresses registered
Dec 23, 2021
dff3925
Fix isThisNodeMasterCandidate
Dec 23, 2021
a06d690
Fix style
Dec 23, 2021
ace549c
Adjust the address registry logs
Dec 24, 2021
6169f11
Fix tests that include mock logger
Dec 24, 2021
8044273
Remove reverse DNS lookup from address resolution
Dec 29, 2021
6339821
Fix any local address check
Dec 29, 2021
928e681
Make Node#thisUuid private
Dec 29, 2021
1c45ac9
Fix minor issues
Dec 29, 2021
2855d25
Remove ip address resolution from hot path
Dec 29, 2021
a2ac119
Improve the javadocs of ServerConnectionManager
Dec 29, 2021
a65d437
Do not skip any network interfaces
Dec 29, 2021
e142559
Try to handle self connections
Dec 29, 2021
b5bbbbf
Merge remote-tracking branch 'upstream/master' into 5.1/hostname-fix-…
Dec 30, 2021
9856887
Handle self connections second attempt
Dec 30, 2021
c36a8fa
Handle error cases inside connection registration
Dec 30, 2021
e369dff
Revert unnecessary change on join
Jan 2, 2022
8910935
Refactor connection manager
Jan 2, 2022
71c6482
Address parts of the review
Jan 2, 2022
55d88e7
fixup! Address parts of the review
Jan 2, 2022
dd70a03
Reduce the number of hostname->ip resolutions
Jan 2, 2022
7f3153f
Remove synchronized block from removeConnectionInProgress
Jan 3, 2022
95aae26
Fixup
Jan 3, 2022
6e0fd77
Fix npe in mock server
Jan 3, 2022
6919437
Remove stale todo item
Jan 3, 2022
28e10c4
Capture remove connection in progress into synchronized block
Jan 4, 2022
ea1ead2
Improve duplicate connection handling
Jan 4, 2022
f508686
Fix TcpIpJoiner#searchForOtherClusters
Jan 5, 2022
2d28144
Merge remote-tracking branch 'upstream/master' into 5.1/hostname-fix-…
Jan 6, 2022
aff02d3
Revert connection in progress handling
Jan 7, 2022
5f5c6c3
Remove duplicate connections handling
Jan 10, 2022
a068eb6
Merge remote-tracking branch 'upstream/master' into 5.1/hostname-fix-…
Jan 10, 2022
0b0caad
Remove one unnecessary LocalAddressRegistry#uuidOf call
Jan 10, 2022
6825d69
Adapt address registry integration test to duplicate conns
Jan 10, 2022
1860672
Merge remote-tracking branch 'upstream/master' into 5.1/hostname-fix-…
Jan 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 ClientHearbeatMonitor#cleanupEndpointsWithDeadConnections later.
if (conn.getRemoteAddress() != null) {
node.getServer().getConnectionManager(CLIENT).register(conn.getRemoteAddress(), conn);
// will be cleaned up by ClientHeartbeatMonitor#cleanupEndpointsWithDeadConnections later.
if (conn.getRemoteAddress() != null && endpoint.getUuid() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in which case can endpoint.getUuid() be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this value after the client endpoint is authenticated, it has no chance of being null in the production code. But if the some staff is mocked, it can be.

node.getServer().getConnectionManager(CLIENT).register(conn.getRemoteAddress(), endpoint.getUuid(), conn);
}
}

Expand Down Expand Up @@ -438,7 +438,11 @@ 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 @@ -480,10 +484,8 @@ Map<UUID, String> getClientsInCluster() {
if (endpoints == null) {
continue;
}
//Merge connected clients according to their UUID
for (Map.Entry<UUID, String> entry : endpoints.entrySet()) {
clientsMap.put(entry.getKey(), entry.getValue());
}
// Merge connected clients according to their UUID
clientsMap.putAll(endpoints);
} catch (Exception e) {
logger.warning("Cannot get client information from: " + target.toString(), e);
}
Expand Down
Expand Up @@ -21,7 +21,6 @@
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 @@ -48,5 +47,4 @@ public interface ClientConnection extends Connection {
// used in tests
Map<Long, EventHandler> getEventHandlers();

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

@Override
@Nonnull
public UUID addMembershipListener(@Nonnull MembershipListener listener) {
return clusterService.addMembershipListener(listener);
}
Expand All @@ -55,12 +56,14 @@ 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 @@ -82,6 +85,7 @@ public void changeClusterState(@Nonnull ClusterState newState) {
}

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

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

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

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

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

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

/**
Expand Down
20 changes: 20 additions & 0 deletions hazelcast/src/main/java/com/hazelcast/instance/AddressPicker.java
Expand Up @@ -53,8 +53,28 @@ 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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add the javadoc (and also fill the missing one in the getPublicAddressMap?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added related javadocs.


/**
* Returns a server channel.
*
Expand Down
Expand Up @@ -92,6 +92,16 @@ 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,6 +439,13 @@ 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,13 +24,14 @@
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.TcpServerContext;
import com.hazelcast.internal.server.tcp.TcpServerConnectionChannelErrorHandler;
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.util.InstantiationUtils;
import com.hazelcast.logging.ILogger;
import com.hazelcast.logging.impl.LoggingServiceImpl;
Expand Down Expand Up @@ -143,7 +144,7 @@ public Joiner createJoiner(Node node) {
}

@Override
public Server createServer(Node node, ServerSocketRegistry registry) {
public Server createServer(Node node, ServerSocketRegistry registry, LocalAddressRegistry addressRegistry) {
TcpServerContext context = new TcpServerContext(node, node.nodeEngine);
Networking networking = createNetworking(node);
Config config = node.getConfig();
Expand All @@ -152,6 +153,7 @@ public Server createServer(Node node, ServerSocketRegistry registry) {
return new TcpServer(config,
context,
registry,
addressRegistry,
metricsRegistry,
networking,
node.getNodeExtension().createChannelInitializerFn(context));
Expand Down
Expand Up @@ -195,7 +195,15 @@ 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: 22 additions & 8 deletions hazelcast/src/main/java/com/hazelcast/instance/impl/Node.java
Expand Up @@ -71,6 +71,7 @@
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 @@ -162,6 +163,7 @@ 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 @@ -173,8 +175,11 @@ 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 @@ -218,14 +223,15 @@ public Node(HazelcastInstanceImpl hazelcastInstance, Config staticConfig, NodeCo

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

server = nodeContext.createServer(this, serverSocketRegistry);
localAddressRegistry = new LocalAddressRegistry(this, addressPicker);
server = nodeContext.createServer(this, serverSocketRegistry, localAddressRegistry);
healthMonitor = new HealthMonitor(this);
clientEngine = hasClientServerSocket() ? new ClientEngineImpl(this) : new NoOpClientEngine();
JoinConfig joinConfig = getActiveMemberNetworkConfig(this.config).getJoin();
Expand Down Expand Up @@ -428,6 +434,14 @@ 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 @@ -725,6 +739,10 @@ public DiscoveryService getDiscoveryService() {
return discoveryService;
}

public LocalAddressRegistry getLocalAddressRegistry() {
return localAddressRegistry;
}

private enum ShutdownHookPolicy {
TERMINATE,
GRACEFUL
Expand Down Expand Up @@ -857,10 +875,6 @@ 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,6 +18,7 @@

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 @@ -36,6 +37,5 @@ public interface NodeContext {

Joiner createJoiner(Node node);

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