Search in sources :

Example 11 with PartitionReplica

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

the class InternalPartitionServiceImpl method requestMemberListUpdateIfUnknownMembersFound.

private void requestMemberListUpdateIfUnknownMembersFound(Address sender, InternalPartition[] partitions) {
    ClusterServiceImpl clusterService = node.clusterService;
    ClusterState clusterState = clusterService.getClusterState();
    Set<PartitionReplica> unknownReplicas = new HashSet<>();
    for (InternalPartition partition : partitions) {
        for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
            PartitionReplica replica = partition.getReplica(index);
            if (replica == null) {
                continue;
            }
            if (node.clusterService.getMember(replica.address(), replica.uuid()) == null && (clusterState.isJoinAllowed() || !clusterService.isMissingMember(replica.address(), replica.uuid()))) {
                unknownReplicas.add(replica);
            }
        }
    }
    if (!unknownReplicas.isEmpty()) {
        if (logger.isWarningEnabled()) {
            StringBuilder s = new StringBuilder("Following unknown addresses are found in partition table").append(" sent from master[").append(sender).append("].").append(" (Probably they have recently joined or left the cluster.)").append(" {");
            for (PartitionReplica replica : unknownReplicas) {
                s.append("\n\t").append(replica);
            }
            s.append("\n}");
            logger.warning(s.toString());
        }
        Address masterAddress = node.getClusterService().getMasterAddress();
        // If node is shutting down, master can be null.
        if (masterAddress != null && !masterAddress.equals(node.getThisAddress())) {
            // unknown addresses found in partition table, request a new member-list from master
            nodeEngine.getOperationService().send(new TriggerMemberListPublishOp(), masterAddress);
        }
    }
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) Address(com.hazelcast.cluster.Address) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) InternalPartition(com.hazelcast.internal.partition.InternalPartition) ReadonlyInternalPartition(com.hazelcast.internal.partition.ReadonlyInternalPartition) TriggerMemberListPublishOp(com.hazelcast.internal.cluster.impl.operations.TriggerMemberListPublishOp) HashSet(java.util.HashSet)

Example 12 with PartitionReplica

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

the class MigrationManager method finalizeMigration.

/**
 * Finalizes a migration that has finished with {@link MigrationStatus#SUCCESS}
 * or {@link MigrationStatus#FAILED} by invoking {@link FinalizeMigrationOperation}
 * locally if this is the source or destination. The finalization is asynchronous
 * and there might be other ongoing migration finalizations.
 * <p>
 * It will also cleanup the migration state by removing the active migration and
 * clearing the migration flag on the partition owner.
 * <p>
 * This method should not be called on a node which is not the source, destination
 * or partition owner for this migration.
 *
 * @param migrationInfo the migration to be finalized
 */
void finalizeMigration(MigrationInfo migrationInfo) {
    try {
        PartitionReplica localReplica = PartitionReplica.from(node.getLocalMember());
        int partitionId = migrationInfo.getPartitionId();
        boolean source = localReplica.equals(migrationInfo.getSource());
        boolean destination = localReplica.equals(migrationInfo.getDestination());
        assert migrationInfo.getStatus() == MigrationStatus.SUCCESS || migrationInfo.getStatus() == MigrationStatus.FAILED : "Invalid migration: " + migrationInfo;
        if (source || destination) {
            boolean success = migrationInfo.getStatus() == MigrationStatus.SUCCESS;
            MigrationParticipant participant = source ? MigrationParticipant.SOURCE : MigrationParticipant.DESTINATION;
            if (success) {
                migrationInterceptor.onMigrationCommit(participant, migrationInfo);
            } else {
                migrationInterceptor.onMigrationRollback(participant, migrationInfo);
            }
            MigrationEndpoint endpoint = source ? MigrationEndpoint.SOURCE : MigrationEndpoint.DESTINATION;
            FinalizeMigrationOperation op = new FinalizeMigrationOperation(migrationInfo, endpoint, success);
            op.setPartitionId(partitionId).setNodeEngine(nodeEngine).setValidateTarget(false).setService(partitionService);
            registerFinalizingMigration(migrationInfo);
            OperationServiceImpl operationService = nodeEngine.getOperationService();
            if (logger.isFineEnabled()) {
                logger.fine("Finalizing " + migrationInfo);
            }
            if (operationService.isRunAllowed(op)) {
                // When migration finalization is triggered by subsequent migrations
                // on partition thread, finalization may run directly on calling thread.
                // Otherwise, if previously completed migration and newly submitted migration
                // are on the same partition, then finalizing previous migration later will
                // break the order, hence safety.
                operationService.run(op);
            } else {
                operationService.execute(op);
            }
            removeActiveMigration(migrationInfo);
        } else {
            PartitionReplica partitionOwner = partitionStateManager.getPartitionImpl(partitionId).getOwnerReplicaOrNull();
            if (localReplica.equals(partitionOwner)) {
                // This is the primary owner of the partition and the migration was a backup replica migration.
                // In this case, primary owner has nothing to do anymore,
                // just remove the active migration and clear the migrating flag.
                removeActiveMigration(migrationInfo);
                partitionStateManager.clearMigratingFlag(partitionId);
            } else {
                logger.severe("Failed to finalize migration because " + localReplica + " is not a participant of the migration: " + migrationInfo);
            }
        }
    } catch (Exception e) {
        logger.warning(e);
    }
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) FinalizeMigrationOperation(com.hazelcast.internal.partition.operation.FinalizeMigrationOperation) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint) MigrationParticipant(com.hazelcast.internal.partition.impl.MigrationInterceptor.MigrationParticipant) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) PartitionStateVersionMismatchException(com.hazelcast.internal.partition.PartitionStateVersionMismatchException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException)

Example 13 with PartitionReplica

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

the class MigrationManager method logMigrationCommitFailure.

private void logMigrationCommitFailure(MigrationInfo migration, Throwable t) {
    boolean memberLeft = t instanceof MemberLeftException || t.getCause() instanceof TargetNotMemberException || t.getCause() instanceof HazelcastInstanceNotActiveException;
    PartitionReplica destination = migration.getDestination();
    if (memberLeft) {
        if (destination.isIdentical(node.getLocalMember())) {
            logger.fine("Migration commit failed for " + migration + " since this node is shutting down.");
            return;
        }
        logger.warning("Migration commit failed for " + migration + " since destination " + destination + " left the cluster");
    } else {
        logger.severe("Migration commit to " + destination + " failed for " + migration, t);
    }
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 14 with PartitionReplica

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

the class OperationBackupHandler method sendSingleBackup.

private int sendSingleBackup(BackupAwareOperation backupAwareOp, InternalPartition partition, long[] replicaVersions, int syncBackups, int replica) {
    Operation backupOp = getBackupOperation(backupAwareOp);
    PartitionReplica target = partition.getReplica(replica);
    if (target != null) {
        if (skipSendingBackupToTarget(partition, target)) {
            return 0;
        }
        // without any unnecessary memory allocation and copy when it is used as object inside `Backup`.
        if (backupOp instanceof TargetAware) {
            ((TargetAware) backupOp).setTarget(target.address());
        }
        boolean isSyncBackup = syncBackups == 1;
        Backup backup = newBackup(backupAwareOp, backupOp, replicaVersions, 1, isSyncBackup);
        outboundOperationHandler.send(backup, target.address());
        if (isSyncBackup) {
            return 1;
        }
    }
    return 0;
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) TargetAware(com.hazelcast.spi.impl.operationservice.TargetAware) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 15 with PartitionReplica

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

the class OperationRunnerImpl method ensureNoPartitionProblems.

private void ensureNoPartitionProblems(Operation op) {
    int partitionId = op.getPartitionId();
    if (partitionId < 0) {
        return;
    }
    if (partitionId != getPartitionId()) {
        throw new IllegalStateException("wrong partition, expected: " + getPartitionId() + " but found:" + partitionId);
    }
    if (internalPartition == null) {
        internalPartition = nodeEngine.getPartitionService().getPartition(partitionId);
    }
    if (!isAllowedToRetryDuringMigration(op) && internalPartition.isMigrating()) {
        throw new PartitionMigratingException(thisAddress, partitionId, op.getClass().getName(), op.getServiceName());
    }
    PartitionReplica owner = internalPartition.getReplica(op.getReplicaIndex());
    if (op.validatesTarget() && (owner == null || !owner.isIdentical(node.getLocalMember()))) {
        Member target = owner != null ? node.getClusterService().getMember(owner.address(), owner.uuid()) : null;
        throw new WrongTargetException(node.getLocalMember(), target, partitionId, op.getReplicaIndex(), op.getClass().getName(), op.getServiceName());
    }
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) Member(com.hazelcast.cluster.Member) WrongTargetException(com.hazelcast.spi.exception.WrongTargetException) PartitionMigratingException(com.hazelcast.spi.exception.PartitionMigratingException)

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