Search in sources :

Example 11 with PartitionRuntimeState

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

the class PromotionCommitOperation method readInternal.

@Override
protected void readInternal(ObjectDataInput in) throws IOException {
    super.readInternal(in);
    expectedMemberUuid = in.readUTF();
    partitionState = new PartitionRuntimeState();
    partitionState.readData(in);
    int len = in.readInt();
    if (len > 0) {
        promotions = new ArrayList<MigrationInfo>(len);
        for (int i = 0; i < len; i++) {
            MigrationInfo migrationInfo = new MigrationInfo();
            migrationInfo.readData(in);
            promotions.add(migrationInfo);
        }
    }
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState)

Example 12 with PartitionRuntimeState

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

the class ClusterJoinManager method startJoin.

/**
 * Starts join process on master member.
 */
private void startJoin() {
    logger.fine("Starting join...");
    clusterServiceLock.lock();
    try {
        InternalPartitionService partitionService = node.getPartitionService();
        boolean shouldTriggerRepartition = true;
        try {
            joinInProgress = true;
            // pause migrations until join, member-update and post-join operations are completed
            partitionService.pauseMigration();
            MemberMap memberMap = clusterService.getMembershipManager().getMemberMap();
            MembersView newMembersView = MembersView.cloneAdding(memberMap.toMembersView(), joiningMembers.values());
            long time = clusterClock.getClusterTime();
            // member list must be updated on master before preparation of pre-/post-join ops so other operations which have
            // to be executed on stable cluster can detect the member list version change and retry in case of topology change
            UUID thisUuid = clusterService.getThisUuid();
            if (!clusterService.updateMembers(newMembersView, node.getThisAddress(), thisUuid, thisUuid)) {
                return;
            }
            // post join operations must be lock free, that means no locks at all:
            // no partition locks, no key-based locks, no service level locks!
            OnJoinOp preJoinOp = preparePreJoinOps();
            OnJoinOp postJoinOp = preparePostJoinOp();
            // this is the current partition assignment state, not taking into account the
            // currently joining members
            PartitionRuntimeState partitionRuntimeState = partitionService.createPartitionState();
            for (MemberInfo member : joiningMembers.values()) {
                if (isMemberRestartingWithPersistence(member.getAttributes()) && isMemberRejoining(memberMap, member.getAddress(), member.getUuid())) {
                    logger.info(member + " is rejoining the cluster");
                    // do not trigger repartition immediately, wait for joining member to load hot-restart data
                    shouldTriggerRepartition = false;
                }
                long startTime = clusterClock.getClusterStartTime();
                Operation op = new FinalizeJoinOp(member.getUuid(), newMembersView, preJoinOp, postJoinOp, time, clusterService.getClusterId(), startTime, clusterStateManager.getState(), clusterService.getClusterVersion(), partitionRuntimeState, !shouldTriggerRepartition);
                op.setCallerUuid(thisUuid);
                invokeClusterOp(op, member.getAddress());
            }
            for (MemberImpl member : memberMap.getMembers()) {
                if (member.localMember() || joiningMembers.containsKey(member.getAddress())) {
                    continue;
                }
                Operation op = new MembersUpdateOp(member.getUuid(), newMembersView, time, partitionRuntimeState, true);
                op.setCallerUuid(thisUuid);
                invokeClusterOp(op, member.getAddress());
            }
        } finally {
            reset();
            if (shouldTriggerRepartition) {
                partitionService.resumeMigration();
            }
        }
    } finally {
        clusterServiceLock.unlock();
    }
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) MembersUpdateOp(com.hazelcast.internal.cluster.impl.operations.MembersUpdateOp) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) Operation(com.hazelcast.spi.impl.operationservice.Operation) FinalizeJoinOp(com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOp) OnJoinOp(com.hazelcast.internal.cluster.impl.operations.OnJoinOp) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) UUID(java.util.UUID)

Example 13 with PartitionRuntimeState

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

the class InternalPartitionServiceImpl method createPromotionCommitPartitionState.

/**
 * Creates a transient {@link PartitionRuntimeState} to commit promotions by applying the {@code migrationInfos}.
 * The partition table version is incremented by number of promotions.
 * This method will acquire the partition service lock.
 *
 * @param migrationInfos the promotions to be executed on the destination
 * @return the partition table with the executed migrations or {@code null} if the partitions are not initialized (assigned)
 */
PartitionRuntimeState createPromotionCommitPartitionState(Collection<MigrationInfo> migrationInfos) {
    lock.lock();
    try {
        if (!partitionStateManager.isInitialized()) {
            return null;
        }
        List<MigrationInfo> completedMigrations = migrationManager.getCompletedMigrationsCopy();
        InternalPartition[] partitions = partitionStateManager.getPartitionsCopy(false);
        for (MigrationInfo migrationInfo : migrationInfos) {
            int partitionId = migrationInfo.getPartitionId();
            InternalPartitionImpl partition = (InternalPartitionImpl) partitions[partitionId];
            applyMigration(partition, migrationInfo);
            migrationInfo.setStatus(MigrationStatus.SUCCESS);
        }
        long stamp = calculateStamp(partitions);
        return new PartitionRuntimeState(partitions, completedMigrations, stamp);
    } finally {
        lock.unlock();
    }
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) InternalPartition(com.hazelcast.internal.partition.InternalPartition) ReadonlyInternalPartition(com.hazelcast.internal.partition.ReadonlyInternalPartition)

Example 14 with PartitionRuntimeState

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

the class InternalPartitionServiceImpl method publishPartitionRuntimeState.

/**
 * Called on the master node to publish the current partition state to all cluster nodes. It will not publish the partition
 * state if the partitions have not yet been initialized, there is ongoing repartitioning or a node is joining the cluster.
 */
@SuppressWarnings("checkstyle:npathcomplexity")
void publishPartitionRuntimeState() {
    if (!partitionStateManager.isInitialized()) {
        // do not send partition state until initialized!
        return;
    }
    if (!isLocalMemberMaster()) {
        return;
    }
    if (!areMigrationTasksAllowed()) {
        // migration is disabled because of a member leave, wait till enabled!
        return;
    }
    PartitionRuntimeState partitionState = createPartitionStateInternal();
    if (partitionState == null) {
        return;
    }
    if (logger.isFineEnabled()) {
        logger.fine("Publishing partition state, stamp: " + partitionState.getStamp());
    }
    PartitionStateOperation op = new PartitionStateOperation(partitionState, false);
    OperationService operationService = nodeEngine.getOperationService();
    Collection<Member> members = node.clusterService.getMembers();
    for (Member member : members) {
        if (!member.localMember()) {
            try {
                operationService.send(op, member.getAddress());
            } catch (Exception e) {
                logger.finest(e);
            }
        }
    }
}
Also used : PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) FetchPartitionStateOperation(com.hazelcast.internal.partition.operation.FetchPartitionStateOperation) PartitionStateOperation(com.hazelcast.internal.partition.operation.PartitionStateOperation) Member(com.hazelcast.cluster.Member) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TimeoutException(java.util.concurrent.TimeoutException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) NoDataMemberInClusterException(com.hazelcast.partition.NoDataMemberInClusterException) MemberLeftException(com.hazelcast.core.MemberLeftException)

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