Search in sources :

Example 16 with Address

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

the class ClusterJoinManager method ensureValidConfiguration.

private boolean ensureValidConfiguration(JoinMessage joinMessage) {
    Address address = joinMessage.getAddress();
    try {
        if (isValidJoinMessage(joinMessage)) {
            return true;
        }
        logger.warning(format("Received an invalid join request from %s, cause: members part of different cluster", address));
        nodeEngine.getOperationService().send(new ClusterMismatchOp(), address);
    } catch (ConfigMismatchException e) {
        logger.warning(format("Received an invalid join request from %s, cause: %s", address, e.getMessage()));
        OperationService operationService = nodeEngine.getOperationService();
        operationService.send(new ConfigMismatchOp(e.getMessage()), address);
    }
    return false;
}
Also used : ConfigMismatchOp(com.hazelcast.internal.cluster.impl.operations.ConfigMismatchOp) Address(com.hazelcast.cluster.Address) ClusterMismatchOp(com.hazelcast.internal.cluster.impl.operations.ClusterMismatchOp) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 17 with Address

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

the class ClusterJoinManager method handleJoinRequest.

/**
 * Handle a {@link JoinRequestOp}. If this node is not master, reply with a {@link MasterResponseOp} to let the
 * joining node know the current master. Otherwise, if no other join is in progress, execute the {@link JoinRequest}
 *
 * @param joinRequest the join request
 * @param connection the connection to the joining node
 * @see JoinRequestOp
 */
public void handleJoinRequest(JoinRequest joinRequest, ServerConnection connection) {
    if (!ensureNodeIsReady()) {
        return;
    }
    if (!ensureValidConfiguration(joinRequest)) {
        return;
    }
    Address target = joinRequest.getAddress();
    boolean isRequestFromCurrentMaster = target.equals(clusterService.getMasterAddress());
    // because master can somehow dropped its connection and wants to join back
    if (!clusterService.isMaster() && !isRequestFromCurrentMaster) {
        sendMasterAnswer(target);
        return;
    }
    if (joinInProgress) {
        if (logger.isFineEnabled()) {
            logger.fine(format("Join or membership claim is in progress, cannot handle join request from %s at the moment", target));
        }
        return;
    }
    executeJoinRequest(joinRequest, connection);
}
Also used : Address(com.hazelcast.cluster.Address)

Example 18 with Address

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

the class ClusterJoinManager method checkIfJoinRequestFromAnExistingMember.

@SuppressWarnings("checkstyle:cyclomaticcomplexity")
private boolean checkIfJoinRequestFromAnExistingMember(JoinMessage joinMessage, ServerConnection connection) {
    Address targetAddress = joinMessage.getAddress();
    MemberImpl member = clusterService.getMember(targetAddress);
    if (member == null) {
        return checkIfUsingAnExistingMemberUuid(joinMessage);
    }
    if (joinMessage.getUuid().equals(member.getUuid())) {
        sendMasterAnswer(targetAddress);
        if (clusterService.isMaster() && !isMastershipClaimInProgress()) {
            if (logger.isFineEnabled()) {
                logger.fine(format("Ignoring join request, member already exists: %s", joinMessage));
            }
            // send members update back to node trying to join again...
            boolean deferPartitionProcessing = isMemberRestartingWithPersistence(member.getAttributes());
            OnJoinOp preJoinOp = preparePreJoinOps();
            OnJoinOp postJoinOp = preparePostJoinOp();
            PartitionRuntimeState partitionRuntimeState = node.getPartitionService().createPartitionState();
            Operation op = new FinalizeJoinOp(member.getUuid(), clusterService.getMembershipManager().getMembersView(), preJoinOp, postJoinOp, clusterClock.getClusterTime(), clusterService.getClusterId(), clusterClock.getClusterStartTime(), clusterStateManager.getState(), clusterService.getClusterVersion(), partitionRuntimeState, deferPartitionProcessing);
            op.setCallerUuid(clusterService.getThisUuid());
            invokeClusterOp(op, targetAddress);
        }
        return true;
    }
    // after I suspect from the target.
    if (clusterService.isMaster() || targetAddress.equals(clusterService.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.suspectMember(member, msg, false);
        ServerConnection existing = node.getServer().getConnectionManager(MEMBER).get(targetAddress);
        if (existing != connection) {
            if (existing != null) {
                existing.close(msg, null);
            }
            node.getServer().getConnectionManager(MEMBER).register(targetAddress, joinMessage.getUuid(), connection);
        }
    }
    return true;
}
Also used : Address(com.hazelcast.cluster.Address) OnJoinOp(com.hazelcast.internal.cluster.impl.operations.OnJoinOp) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) ServerConnection(com.hazelcast.internal.server.ServerConnection) Operation(com.hazelcast.spi.impl.operationservice.Operation) FinalizeJoinOp(com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOp)

Example 19 with Address

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

the class ClusterServiceImpl method resetLocalMemberUuid.

private void resetLocalMemberUuid() {
    assert lock.isHeldByCurrentThread() : "Called without holding cluster service lock!";
    assert !isJoined() : "Cannot reset local member UUID when joined.";
    Map<EndpointQualifier, Address> addressMap = localMember.getAddressMap();
    UUID newUuid = UuidUtil.newUnsecureUUID();
    logger.warning("Resetting local member UUID. Previous: " + localMember.getUuid() + ", new: " + newUuid);
    node.setThisUuid(newUuid);
    localMember = new MemberImpl.Builder(addressMap).version(localMember.getVersion()).localMember(true).uuid(newUuid).attributes(localMember.getAttributes()).liteMember(localMember.isLiteMember()).memberListJoinVersion(localMember.getMemberListJoinVersion()).instance(node.hazelcastInstance).build();
    node.loggingService.setThisMember(localMember);
    node.getLocalAddressRegistry().setLocalUuid(newUuid);
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) UUID(java.util.UUID)

Example 20 with Address

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

the class ClusterServiceImpl method sendExplicitSuspicion.

void sendExplicitSuspicion(MembersViewMetadata endpointMembersViewMetadata) {
    Address endpoint = endpointMembersViewMetadata.getMemberAddress();
    if (endpoint.equals(node.getThisAddress())) {
        logger.warning("Cannot send explicit suspicion for " + endpointMembersViewMetadata + " to itself.");
        return;
    }
    if (!isJoined()) {
        if (logger.isFineEnabled()) {
            logger.fine("Cannot send explicit suspicion, not joined yet!");
        }
        return;
    }
    Version clusterVersion = getClusterVersion();
    assert !clusterVersion.isUnknown() : "Cluster version should not be unknown after join!";
    Operation op = new ExplicitSuspicionOp(endpointMembersViewMetadata);
    nodeEngine.getOperationService().send(op, endpoint);
}
Also used : Address(com.hazelcast.cluster.Address) Version(com.hazelcast.version.Version) ExplicitSuspicionOp(com.hazelcast.internal.cluster.impl.operations.ExplicitSuspicionOp) TriggerExplicitSuspicionOp(com.hazelcast.internal.cluster.impl.operations.TriggerExplicitSuspicionOp) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Aggregations

Address (com.hazelcast.cluster.Address)540 Test (org.junit.Test)211 QuickTest (com.hazelcast.test.annotation.QuickTest)191 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)178 HazelcastInstance (com.hazelcast.core.HazelcastInstance)92 InetAddress (java.net.InetAddress)75 ArrayList (java.util.ArrayList)66 Member (com.hazelcast.cluster.Member)63 Accessors.getAddress (com.hazelcast.test.Accessors.getAddress)54 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)48 Config (com.hazelcast.config.Config)43 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)43 UUID (java.util.UUID)43 ILogger (com.hazelcast.logging.ILogger)37 HashMap (java.util.HashMap)36 Operation (com.hazelcast.spi.impl.operationservice.Operation)35 List (java.util.List)35 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)34 Map (java.util.Map)33 InetSocketAddress (java.net.InetSocketAddress)32