Search in sources :

Example 1 with Address

use of com.hazelcast.nio.Address in project neo4j by neo4j.

the class HazelcastClusterTopologyTest method shouldLogAndExcludeMembersWithMissingAttributes.

@Test
public void shouldLogAndExcludeMembersWithMissingAttributes() throws Exception {
    // given
    Set<Member> hazelcastMembers = new HashSet<>();
    List<MemberId> coreMembers = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        MemberId memberId = new MemberId(UUID.randomUUID());
        coreMembers.add(memberId);
        Config config = Config.defaults();
        HashMap<String, String> settings = new HashMap<>();
        settings.put(new BoltConnector("bolt").type.name(), "BOLT");
        settings.put(new BoltConnector("bolt").enabled.name(), "true");
        settings.put(new BoltConnector("bolt").advertised_address.name(), "bolt:" + (i + 1));
        settings.put(new BoltConnector("http").type.name(), "HTTP");
        settings.put(new BoltConnector("http").enabled.name(), "true");
        settings.put(new BoltConnector("http").advertised_address.name(), "http:" + (i + 1));
        config.augment(settings);
        Map<String, Object> attributes = buildMemberAttributesForCore(memberId, config).getAttributes();
        if (i == 2) {
            attributes.remove(HazelcastClusterTopology.RAFT_SERVER);
        }
        hazelcastMembers.add(new MemberImpl(new Address("localhost", i), null, attributes, false));
    }
    // when
    Map<MemberId, CoreServerInfo> map = toCoreMemberMap(hazelcastMembers, NullLog.getInstance(), hzInstance);
    // then
    assertThat(map.keySet(), hasItems(coreMembers.get(0), coreMembers.get(1), coreMembers.get(3)));
    assertThat(map.keySet(), not(hasItems(coreMembers.get(2))));
}
Also used : Address(com.hazelcast.nio.Address) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) HashMap(java.util.HashMap) BoltConnector(org.neo4j.kernel.configuration.BoltConnector) Config(org.neo4j.kernel.configuration.Config) MemberImpl(com.hazelcast.client.impl.MemberImpl) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) MemberId(org.neo4j.causalclustering.identity.MemberId) Member(com.hazelcast.core.Member) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class ClusterHeartbeatManager method sendMasterConfirmation.

/**
     * Sends a {@link MasterConfirmationOperation} to the master if this node is joined, it is not in the
     * {@link NodeState#SHUT_DOWN} state and is not the master node.
     */
public void sendMasterConfirmation() {
    if (!node.joined() || node.getState() == NodeState.SHUT_DOWN || node.isMaster()) {
        return;
    }
    Address masterAddress = node.getMasterAddress();
    if (masterAddress == null) {
        logger.fine("Could not send MasterConfirmation, masterAddress is null!");
        return;
    }
    MemberImpl masterMember = clusterService.getMember(masterAddress);
    if (masterMember == null) {
        logger.fine("Could not send MasterConfirmation, masterMember is null!");
        return;
    }
    if (logger.isFineEnabled()) {
        logger.fine("Sending MasterConfirmation to " + masterMember);
    }
    nodeEngine.getOperationService().send(new MasterConfirmationOperation(clusterClock.getClusterTime()), masterAddress);
}
Also used : MasterConfirmationOperation(com.hazelcast.internal.cluster.impl.operations.MasterConfirmationOperation) Address(com.hazelcast.nio.Address) MemberImpl(com.hazelcast.instance.MemberImpl)

Example 3 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class ClusterJoinManager method checkIfJoinRequestFromAnExistingMember.

private boolean checkIfJoinRequestFromAnExistingMember(JoinMessage joinMessage, Connection connection) {
    Address target = joinMessage.getAddress();
    MemberImpl member = clusterService.getMember(target);
    if (member == null) {
        return checkIfUsingAnExistingMemberUuid(joinMessage);
    }
    if (joinMessage.getUuid().equals(member.getUuid())) {
        sendMasterAnswer(target);
        if (node.isMaster()) {
            if (logger.isFineEnabled()) {
                logger.fine(format("Ignoring join request, member already exists: %s", joinMessage));
            }
            // send members update back to node trying to join again...
            Operation[] postJoinOps = nodeEngine.getPostJoinOperations();
            boolean isPostJoinOperation = postJoinOps != null && postJoinOps.length > 0;
            PostJoinOperation postJoinOp = isPostJoinOperation ? new PostJoinOperation(postJoinOps) : null;
            PartitionRuntimeState partitionRuntimeState = node.getPartitionService().createPartitionState();
            List<MemberInfo> memberInfos = createMemberInfoList(clusterService.getMemberImpls());
            Operation operation = new FinalizeJoinOperation(member.getUuid(), memberInfos, postJoinOp, clusterClock.getClusterTime(), clusterService.getClusterId(), clusterClock.getClusterStartTime(), clusterStateManager.getState(), clusterService.getClusterVersion(), partitionRuntimeState, false);
            nodeEngine.getOperationService().send(operation, target);
        }
        return true;
    }
    //   and wants to join back, so drop old member and process join request if this node becomes master
    if (node.isMaster() || target.equals(node.getMasterAddress())) {
        String msg = format("New join request has been received from an existing endpoint %s." + " Removing old member and processing join request...", member);
        logger.warning(msg);
        clusterService.doRemoveAddress(target, msg, false);
        Connection existing = node.connectionManager.getConnection(target);
        if (existing != connection) {
            if (existing != null) {
                existing.close(msg, null);
            }
            node.connectionManager.registerConnection(target, connection);
        }
        return false;
    }
    return true;
}
Also used : FinalizeJoinOperation(com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOperation) Address(com.hazelcast.nio.Address) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) MemberImpl(com.hazelcast.instance.MemberImpl) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) Connection(com.hazelcast.nio.Connection) PostJoinOperation(com.hazelcast.internal.cluster.impl.operations.PostJoinOperation) FinalizeJoinOperation(com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOperation) MemberInfoUpdateOperation(com.hazelcast.internal.cluster.impl.operations.MemberInfoUpdateOperation) ConfigMismatchOperation(com.hazelcast.internal.cluster.impl.operations.ConfigMismatchOperation) Operation(com.hazelcast.spi.Operation) BeforeJoinCheckFailureOperation(com.hazelcast.internal.cluster.impl.operations.BeforeJoinCheckFailureOperation) SetMasterOperation(com.hazelcast.internal.cluster.impl.operations.SetMasterOperation) GroupMismatchOperation(com.hazelcast.internal.cluster.impl.operations.GroupMismatchOperation) PostJoinOperation(com.hazelcast.internal.cluster.impl.operations.PostJoinOperation) MasterDiscoveryOperation(com.hazelcast.internal.cluster.impl.operations.MasterDiscoveryOperation) JoinRequestOperation(com.hazelcast.internal.cluster.impl.operations.JoinRequestOperation) AuthenticationFailureOperation(com.hazelcast.internal.cluster.impl.operations.AuthenticationFailureOperation)

Example 4 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class ClusterServiceImpl method repairPartitionTableIfReturningMember.

private void repairPartitionTableIfReturningMember(MemberImpl member) {
    if (!isMaster()) {
        return;
    }
    if (getClusterState() == ClusterState.ACTIVE) {
        return;
    }
    if (!node.getNodeExtension().isStartCompleted()) {
        return;
    }
    Address address = member.getAddress();
    MemberImpl memberRemovedWhileClusterIsNotActive = getMemberRemovedWhileClusterIsNotActive(member.getUuid());
    if (memberRemovedWhileClusterIsNotActive != null) {
        Address oldAddress = memberRemovedWhileClusterIsNotActive.getAddress();
        if (!oldAddress.equals(address)) {
            assert !isMemberRemovedWhileClusterIsNotActive(address);
            logger.warning(member + " is returning with a new address. Old one was: " + oldAddress + ". Will update partition table with the new address.");
            InternalPartitionServiceImpl partitionService = node.partitionService;
            partitionService.replaceAddress(oldAddress, address);
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) MemberImpl(com.hazelcast.instance.MemberImpl) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)

Example 5 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class ClusterServiceImpl method sendMemberRemoveOperation.

private void sendMemberRemoveOperation(Member deadMember) {
    for (Member member : getMembers()) {
        Address address = member.getAddress();
        if (!thisAddress.equals(address) && !address.equals(deadMember.getAddress())) {
            MemberRemoveOperation op = new MemberRemoveOperation(deadMember.getAddress(), deadMember.getUuid());
            nodeEngine.getOperationService().send(op, address);
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) MemberRemoveOperation(com.hazelcast.internal.cluster.impl.operations.MemberRemoveOperation) Member(com.hazelcast.core.Member)

Aggregations

Address (com.hazelcast.nio.Address)274 Test (org.junit.Test)44 QuickTest (com.hazelcast.test.annotation.QuickTest)36 HashMap (java.util.HashMap)33 ParallelTest (com.hazelcast.test.annotation.ParallelTest)29 Member (com.hazelcast.core.Member)27 ArrayList (java.util.ArrayList)27 Map (java.util.Map)26 ILogger (com.hazelcast.logging.ILogger)25 InetAddress (java.net.InetAddress)25 MemberImpl (com.hazelcast.instance.MemberImpl)21 List (java.util.List)20 HashSet (java.util.HashSet)18 Connection (com.hazelcast.nio.Connection)17 NodeEngine (com.hazelcast.spi.NodeEngine)16 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)16 IOException (java.io.IOException)16 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 IPartitionService (com.hazelcast.spi.partition.IPartitionService)13