Search in sources :

Example 6 with PartitionRuntimeState

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

the class PartitionDataSerializerHook method createFactory.

@Override
public DataSerializableFactory createFactory() {
    ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[LEN];
    constructors[PARTITION_RUNTIME_STATE] = arg -> new PartitionRuntimeState();
    constructors[ASSIGN_PARTITIONS] = arg -> new AssignPartitions();
    constructors[PARTITION_BACKUP_REPLICA_ANTI_ENTROPY] = arg -> new PartitionBackupReplicaAntiEntropyOperation();
    constructors[FETCH_PARTITION_STATE] = arg -> new FetchPartitionStateOperation();
    constructors[HAS_ONGOING_MIGRATION] = arg -> new HasOngoingMigration();
    constructors[MIGRATION_COMMIT] = arg -> new MigrationCommitOperation();
    constructors[PARTITION_STATE_OP] = arg -> new PartitionStateOperation();
    constructors[PROMOTION_COMMIT] = arg -> new PromotionCommitOperation();
    constructors[REPLICA_SYNC_REQUEST] = arg -> new PartitionReplicaSyncRequest();
    constructors[REPLICA_SYNC_RESPONSE] = arg -> new PartitionReplicaSyncResponse();
    constructors[REPLICA_SYNC_RETRY_RESPONSE] = arg -> new PartitionReplicaSyncRetryResponse();
    constructors[SAFE_STATE_CHECK] = arg -> new SafeStateCheckOperation();
    constructors[SHUTDOWN_REQUEST] = arg -> new ShutdownRequestOperation();
    constructors[SHUTDOWN_RESPONSE] = arg -> new ShutdownResponseOperation();
    constructors[REPLICA_FRAGMENT_MIGRATION_STATE] = arg -> new ReplicaFragmentMigrationState();
    constructors[MIGRATION] = arg -> new MigrationOperation();
    constructors[MIGRATION_REQUEST] = arg -> new MigrationRequestOperation();
    constructors[NON_FRAGMENTED_SERVICE_NAMESPACE] = arg -> NonFragmentedServiceNamespace.INSTANCE;
    constructors[PARTITION_REPLICA] = arg -> new PartitionReplica();
    constructors[PUBLISH_COMPLETED_MIGRATIONS] = arg -> new PublishCompletedMigrationsOperation();
    constructors[PARTITION_STATE_CHECK_OP] = arg -> new PartitionStateCheckOperation();
    constructors[REPLICA_MIGRATION_EVENT] = arg -> new ReplicaMigrationEventImpl();
    constructors[MIGRATION_EVENT] = arg -> new MigrationStateImpl();
    constructors[PARTITION_LOST_EVENT] = arg -> new PartitionLostEventImpl();
    constructors[REPLICA_SYNC_REQUEST_OFFLOADABLE] = arg -> new PartitionReplicaSyncRequestOffloadable();
    return new ArrayDataSerializableFactory(constructors);
}
Also used : HasOngoingMigration(com.hazelcast.internal.partition.operation.HasOngoingMigration) ShutdownResponseOperation(com.hazelcast.internal.partition.operation.ShutdownResponseOperation) PartitionBackupReplicaAntiEntropyOperation(com.hazelcast.internal.partition.operation.PartitionBackupReplicaAntiEntropyOperation) AssignPartitions(com.hazelcast.internal.partition.operation.AssignPartitions) MigrationStateImpl(com.hazelcast.internal.partition.MigrationStateImpl) PartitionStateOperation(com.hazelcast.internal.partition.operation.PartitionStateOperation) FetchPartitionStateOperation(com.hazelcast.internal.partition.operation.FetchPartitionStateOperation) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) PartitionReplicaSyncRetryResponse(com.hazelcast.internal.partition.operation.PartitionReplicaSyncRetryResponse) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) ShutdownRequestOperation(com.hazelcast.internal.partition.operation.ShutdownRequestOperation) PartitionReplicaSyncResponse(com.hazelcast.internal.partition.operation.PartitionReplicaSyncResponse) FetchPartitionStateOperation(com.hazelcast.internal.partition.operation.FetchPartitionStateOperation) PartitionReplicaSyncRequest(com.hazelcast.internal.partition.operation.PartitionReplicaSyncRequest) MigrationOperation(com.hazelcast.internal.partition.operation.MigrationOperation) MigrationRequestOperation(com.hazelcast.internal.partition.operation.MigrationRequestOperation) PartitionReplicaSyncRequestOffloadable(com.hazelcast.internal.partition.operation.PartitionReplicaSyncRequestOffloadable) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction) MigrationCommitOperation(com.hazelcast.internal.partition.operation.MigrationCommitOperation) ReplicaFragmentMigrationState(com.hazelcast.internal.partition.ReplicaFragmentMigrationState) PromotionCommitOperation(com.hazelcast.internal.partition.operation.PromotionCommitOperation) SafeStateCheckOperation(com.hazelcast.internal.partition.operation.SafeStateCheckOperation) PublishCompletedMigrationsOperation(com.hazelcast.internal.partition.operation.PublishCompletedMigrationsOperation) PartitionStateCheckOperation(com.hazelcast.internal.partition.operation.PartitionStateCheckOperation) ReplicaMigrationEventImpl(com.hazelcast.internal.partition.ReplicaMigrationEventImpl) ArrayDataSerializableFactory(com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory) PartitionLostEventImpl(com.hazelcast.internal.partition.PartitionLostEventImpl)

Example 7 with PartitionRuntimeState

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

the class InternalPartitionServiceImpl method sendPartitionRuntimeState.

void sendPartitionRuntimeState(Address target) {
    if (!isLocalMemberMaster()) {
        return;
    }
    assert partitionStateManager.isInitialized();
    PartitionRuntimeState partitionState = createPartitionStateInternal();
    assert partitionState != null;
    if (logger.isFineEnabled()) {
        logger.fine("Sending partition state, stamp: " + partitionState.getStamp() + ", to " + target);
    }
    OperationService operationService = nodeEngine.getOperationService();
    PartitionStateOperation op = new PartitionStateOperation(partitionState, true);
    operationService.invokeOnTarget(SERVICE_NAME, op, target);
}
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)

Example 8 with PartitionRuntimeState

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

the class InternalPartitionServiceImpl method triggerMasterToAssignPartitions.

/**
 * Sends a {@link AssignPartitions} to the master to assign partitions.
 */
private void triggerMasterToAssignPartitions() {
    if (!shouldTriggerMasterToAssignPartitions()) {
        return;
    }
    ClusterServiceImpl clusterService = node.getClusterService();
    ClusterState clusterState = clusterService.getClusterState();
    if (!clusterState.isMigrationAllowed()) {
        logger.warning("Partitions can't be assigned since cluster-state=" + clusterState);
        return;
    }
    final Address masterAddress = latestMaster;
    if (masterAddress == null || masterAddress.equals(node.getThisAddress())) {
        return;
    }
    if (masterTriggered.compareAndSet(false, true)) {
        OperationServiceImpl operationService = nodeEngine.getOperationService();
        InvocationFuture<PartitionRuntimeState> future = operationService.invokeOnTarget(SERVICE_NAME, new AssignPartitions(), masterAddress);
        future.whenCompleteAsync((partitionState, throwable) -> {
            if (throwable == null) {
                resetMasterTriggeredFlag();
                if (partitionState != null) {
                    partitionState.setMaster(masterAddress);
                    processPartitionRuntimeState(partitionState);
                }
            } else {
                resetMasterTriggeredFlag();
                logger.severe(throwable);
            }
        });
        masterTrigger.executeWithDelay();
    }
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) Address(com.hazelcast.cluster.Address) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) AssignPartitions(com.hazelcast.internal.partition.operation.AssignPartitions) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 9 with PartitionRuntimeState

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

the class InternalPartitionServiceImpl method createPartitionStateInternal.

/**
 * Returns a copy of the partition table or {@code null} if not initialized. This method will acquire the partition service
 * lock.
 */
public PartitionRuntimeState createPartitionStateInternal() {
    lock.lock();
    try {
        if (!partitionStateManager.isInitialized()) {
            return null;
        }
        List<MigrationInfo> completedMigrations = migrationManager.getCompletedMigrationsCopy();
        InternalPartition[] partitions = partitionStateManager.getPartitions();
        PartitionRuntimeState state;
        long stamp = partitionStateManager.getStamp();
        assert calculateStamp(partitions) == stamp : "Invalid partition stamp! Expected: " + calculateStamp(partitions) + ", Actual: " + stamp;
        state = new PartitionRuntimeState(partitions, completedMigrations, stamp);
        // Create copy of active migrations set.
        // Because original set can be updated concurrently behind the scenes.
        Collection<MigrationInfo> activeMigrations = new ArrayList<>(migrationManager.getActiveMigrations());
        state.setActiveMigrations(activeMigrations);
        return state;
    } finally {
        lock.unlock();
    }
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) ArrayList(java.util.ArrayList) InternalPartition(com.hazelcast.internal.partition.InternalPartition) ReadonlyInternalPartition(com.hazelcast.internal.partition.ReadonlyInternalPartition)

Example 10 with PartitionRuntimeState

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

the class InternalPartitionServiceImpl method syncPartitionRuntimeState.

@SuppressWarnings("checkstyle:npathcomplexity")
boolean syncPartitionRuntimeState() {
    if (!partitionStateManager.isInitialized()) {
        // do not send partition state until initialized!
        return false;
    }
    if (!node.isMaster()) {
        return false;
    }
    PartitionRuntimeState partitionState = createPartitionStateInternal();
    if (partitionState == null) {
        return false;
    }
    if (logger.isFineEnabled()) {
        logger.fine("Sync'ing partition state, version: " + partitionState.getVersion());
    }
    OperationService operationService = nodeEngine.getOperationService();
    Collection<MemberImpl> members = node.clusterService.getMemberImpls();
    List<Future<Boolean>> calls = firePartitionStateOperation(members, partitionState, operationService);
    Collection<Boolean> results = returnWithDeadline(calls, PTABLE_SYNC_TIMEOUT_SECONDS, TimeUnit.SECONDS, partitionStateSyncTimeoutHandler);
    if (calls.size() != results.size()) {
        return false;
    }
    for (Boolean result : results) {
        if (!result) {
            if (logger.isFineEnabled()) {
                logger.fine("Partition state, version: " + partitionState.getVersion() + " sync failed to one of the members!");
            }
            return false;
        }
    }
    return true;
}
Also used : MemberImpl(com.hazelcast.instance.MemberImpl) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.OperationService) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

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