Search in sources :

Example 1 with PartitionReplica

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

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

the class PartitionReplicaStateChecker method invokeReplicaSyncOperations.

@SuppressWarnings("checkstyle:npathcomplexity")
private int invokeReplicaSyncOperations(int maxBackupCount, Semaphore semaphore, AtomicBoolean result) {
    MemberImpl localMember = node.getLocalMember();
    BiConsumer<Object, Throwable> callback = new ReplicaSyncResponseCallback(result, semaphore);
    ClusterServiceImpl clusterService = node.getClusterService();
    ClusterState clusterState = clusterService.getClusterState();
    int ownedCount = 0;
    for (InternalPartition partition : partitionStateManager.getPartitions()) {
        PartitionReplica owner = partition.getOwnerReplicaOrNull();
        if (owner == null) {
            result.set(false);
            continue;
        }
        if (!owner.isIdentical(localMember)) {
            continue;
        }
        ownedCount++;
        if (maxBackupCount == 0) {
            if (partition.isMigrating()) {
                result.set(false);
            }
            continue;
        }
        for (int index = 1; index <= maxBackupCount; index++) {
            PartitionReplica replicaOwner = partition.getReplica(index);
            if (replicaOwner == null) {
                result.set(false);
                semaphore.release();
                continue;
            }
            // because to be able to change cluster state, we ensure that there are no ongoing/pending migrations
            if (!clusterState.isJoinAllowed() && clusterService.isMissingMember(replicaOwner.address(), replicaOwner.uuid())) {
                semaphore.release();
                continue;
            }
            int partitionId = partition.getPartitionId();
            PartitionSpecificRunnable task = new CheckPartitionReplicaVersionTask(nodeEngine, partitionId, index, callback);
            nodeEngine.getOperationService().execute(task);
        }
    }
    return ownedCount;
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) InternalPartition(com.hazelcast.internal.partition.InternalPartition) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable)

Example 3 with PartitionReplica

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

the class PartitionStateManager method reset.

void reset() {
    initialized = false;
    stateStamp = INITIAL_STAMP;
    // local member uuid changes during ClusterService reset
    PartitionReplica localReplica = PartitionReplica.from(node.getLocalMember());
    for (InternalPartitionImpl partition : partitions) {
        partition.reset(localReplica);
    }
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 4 with PartitionReplica

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

the class BaseMigrationOperation method verifyPartitionOwner.

/**
 * Verifies that this node is the owner of the partition.
 */
private void verifyPartitionOwner() {
    InternalPartition partition = getPartition();
    PartitionReplica owner = partition.getOwnerReplicaOrNull();
    if (owner == null) {
        throw new RetryableHazelcastException("Cannot migrate at the moment! Owner of the partition is null => " + migrationInfo);
    }
    if (!owner.isIdentical(getNodeEngine().getLocalMember())) {
        throw new RetryableHazelcastException("Owner of partition is not this node! => " + toString());
    }
}
Also used : RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Example 5 with PartitionReplica

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

the class BaseMigrationOperation method verifyExistingDestination.

/**
 * Verifies that the destination is a cluster member.
 */
final void verifyExistingDestination() {
    PartitionReplica destination = migrationInfo.getDestination();
    Member target = getNodeEngine().getClusterService().getMember(destination.address(), destination.uuid());
    if (target == null) {
        throw new TargetNotMemberException("Destination of migration could not be found! => " + toString());
    }
}
Also used : TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) Member(com.hazelcast.cluster.Member)

Aggregations

PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)103 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)51 QuickTest (com.hazelcast.test.annotation.QuickTest)51 Test (org.junit.Test)51 Address (com.hazelcast.cluster.Address)44 InternalPartition (com.hazelcast.internal.partition.InternalPartition)17 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)17 ArrayList (java.util.ArrayList)10 Member (com.hazelcast.cluster.Member)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)7 PartitionTableView (com.hazelcast.internal.partition.PartitionTableView)6 ReadonlyInternalPartition (com.hazelcast.internal.partition.ReadonlyInternalPartition)6 ClusterState (com.hazelcast.cluster.ClusterState)5 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 NodeEngine (com.hazelcast.spi.impl.NodeEngine)4 Operation (com.hazelcast.spi.impl.operationservice.Operation)4 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)3 MemberLeftException (com.hazelcast.core.MemberLeftException)3 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)3