Search in sources :

Example 1 with LocalAddressRegistry

use of com.hazelcast.internal.server.tcp.LocalAddressRegistry in project hazelcast by hazelcast.

the class TcpIpJoiner method searchForOtherClusters.

@Override
public void searchForOtherClusters() {
    final Collection<Address> possibleAddresses;
    try {
        possibleAddresses = getPossibleAddresses();
    } catch (Throwable e) {
        logger.severe(e);
        return;
    }
    LocalAddressRegistry addressRegistry = node.getLocalAddressRegistry();
    possibleAddresses.removeAll(addressRegistry.getLocalAddresses());
    node.getClusterService().getMembers().forEach(member -> {
        LinkedAddresses addresses = addressRegistry.linkedAddressesOf(member.getUuid());
        if (addresses != null) {
            Set<Address> knownMemberAddresses = addresses.getAllAddresses();
            possibleAddresses.removeAll(knownMemberAddresses);
        } else {
            // do not expect this case in the normal conditions, except for disconnections happens
            // at the same time
            possibleAddresses.remove(member.getAddress());
        }
    });
    if (possibleAddresses.isEmpty()) {
        return;
    }
    SplitBrainJoinMessage request = node.createSplitBrainJoinMessage();
    for (Address address : possibleAddresses) {
        SplitBrainMergeCheckResult result = sendSplitBrainJoinMessageAndCheckResponse(address, request);
        if (result == SplitBrainMergeCheckResult.LOCAL_NODE_SHOULD_MERGE) {
            logger.warning(node.getThisAddress() + " is merging [tcp/ip] to " + address);
            setTargetAddress(address);
            startClusterMerge(address, request.getMemberListVersion());
            return;
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) LocalAddressRegistry(com.hazelcast.internal.server.tcp.LocalAddressRegistry) LinkedAddresses(com.hazelcast.internal.server.tcp.LinkedAddresses) SplitBrainMergeCheckResult(com.hazelcast.internal.cluster.impl.SplitBrainJoinMessage.SplitBrainMergeCheckResult)

Example 2 with LocalAddressRegistry

use of com.hazelcast.internal.server.tcp.LocalAddressRegistry in project hazelcast by hazelcast.

the class TcpIpJoiner method isThisNodeMasterCandidate.

@SuppressWarnings("checkstyle:NestedIfDepth")
private boolean isThisNodeMasterCandidate(Collection<Address> addresses) {
    int thisHashCode = node.getThisAddress().hashCode();
    for (Address address : addresses) {
        if (isBlacklisted(address)) {
            continue;
        }
        if (node.getServer().getConnectionManager(MEMBER).get(address) != null) {
            LocalAddressRegistry addressRegistry = node.getLocalAddressRegistry();
            UUID memberUuid = addressRegistry.uuidOf(address);
            if (memberUuid != null) {
                Address primaryAddress = addressRegistry.getPrimaryAddress(memberUuid);
                if (primaryAddress != null) {
                    if (thisHashCode > primaryAddress.hashCode()) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) LocalAddressRegistry(com.hazelcast.internal.server.tcp.LocalAddressRegistry) UUID(java.util.UUID)

Aggregations

Address (com.hazelcast.cluster.Address)2 LocalAddressRegistry (com.hazelcast.internal.server.tcp.LocalAddressRegistry)2 InetAddress (java.net.InetAddress)2 SplitBrainMergeCheckResult (com.hazelcast.internal.cluster.impl.SplitBrainJoinMessage.SplitBrainMergeCheckResult)1 LinkedAddresses (com.hazelcast.internal.server.tcp.LinkedAddresses)1 UUID (java.util.UUID)1