Search in sources :

Example 1 with PartitionRuntimeState

use of com.hazelcast.internal.partition.PartitionRuntimeState 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 2 with PartitionRuntimeState

use of com.hazelcast.internal.partition.PartitionRuntimeState in project hazelcast by hazelcast.

the class MigrationManager method commitMigrationToDestination.

private boolean commitMigrationToDestination(Address destination, MigrationInfo migration) {
    assert migration != null : "No migrations to commit! destination=" + destination;
    if (node.getThisAddress().equals(destination)) {
        if (logger.isFinestEnabled()) {
            logger.finest("Shortcutting migration commit, since destination is master. -> " + migration);
        }
        return true;
    }
    MemberImpl member = node.getClusterService().getMember(destination);
    if (member == null) {
        logger.warning("Destination " + destination + " is not member anymore");
        return false;
    }
    try {
        if (logger.isFinestEnabled()) {
            logger.finest("Sending commit operation to " + destination + " for " + migration);
        }
        PartitionRuntimeState partitionState = partitionService.createMigrationCommitPartitionState(migration);
        String destinationUuid = member.getUuid();
        MigrationCommitOperation operation = new MigrationCommitOperation(partitionState, destinationUuid);
        Future<Boolean> future = nodeEngine.getOperationService().createInvocationBuilder(SERVICE_NAME, operation, destination).setTryCount(Integer.MAX_VALUE).setCallTimeout(Long.MAX_VALUE).invoke();
        boolean result = future.get();
        if (logger.isFinestEnabled()) {
            logger.finest("Migration commit result " + result + " from " + destination + " for " + migration);
        }
        return result;
    } catch (Throwable t) {
        logMigrationCommitFailure(destination, migration, t);
    }
    return false;
}
Also used : MigrationCommitOperation(com.hazelcast.internal.partition.operation.MigrationCommitOperation) MemberImpl(com.hazelcast.instance.MemberImpl) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 3 with PartitionRuntimeState

use of com.hazelcast.internal.partition.PartitionRuntimeState in project hazelcast by hazelcast.

the class PartitionStateOperation method readInternal.

@Override
protected void readInternal(ObjectDataInput in) throws IOException {
    super.readInternal(in);
    partitionState = new PartitionRuntimeState();
    partitionState.readData(in);
    sync = in.readBoolean();
}
Also used : PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState)

Example 4 with PartitionRuntimeState

use of com.hazelcast.internal.partition.PartitionRuntimeState in project hazelcast by hazelcast.

the class MigrationCommitOperation method readInternal.

@Override
protected void readInternal(ObjectDataInput in) throws IOException {
    super.readInternal(in);
    expectedMemberUuid = in.readUTF();
    partitionState = new PartitionRuntimeState();
    partitionState.readData(in);
}
Also used : PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState)

Example 5 with PartitionRuntimeState

use of com.hazelcast.internal.partition.PartitionRuntimeState 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)

Aggregations

PartitionRuntimeState (com.hazelcast.internal.partition.PartitionRuntimeState)14 MemberImpl (com.hazelcast.instance.MemberImpl)3 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)3 FetchPartitionStateOperation (com.hazelcast.internal.partition.operation.FetchPartitionStateOperation)3 PartitionStateOperation (com.hazelcast.internal.partition.operation.PartitionStateOperation)3 Address (com.hazelcast.cluster.Address)2 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)2 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)2 FinalizeJoinOp (com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOp)2 OnJoinOp (com.hazelcast.internal.cluster.impl.operations.OnJoinOp)2 InternalPartition (com.hazelcast.internal.partition.InternalPartition)2 ReadonlyInternalPartition (com.hazelcast.internal.partition.ReadonlyInternalPartition)2 AssignPartitions (com.hazelcast.internal.partition.operation.AssignPartitions)2 MigrationCommitOperation (com.hazelcast.internal.partition.operation.MigrationCommitOperation)2 ClusterState (com.hazelcast.cluster.ClusterState)1 Member (com.hazelcast.cluster.Member)1 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 MemberLeftException (com.hazelcast.core.MemberLeftException)1 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)1 AuthenticationFailureOperation (com.hazelcast.internal.cluster.impl.operations.AuthenticationFailureOperation)1