Search in sources :

Example 1 with InternalPartition

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

the class InternalPartitionServiceImpl method createPartitionStateInternal.

public PartitionRuntimeState createPartitionStateInternal() {
    lock.lock();
    try {
        if (!partitionStateManager.isInitialized()) {
            return null;
        }
        List<MigrationInfo> completedMigrations = migrationManager.getCompletedMigrationsCopy();
        InternalPartition[] partitions = partitionStateManager.getPartitions();
        PartitionRuntimeState state = new PartitionRuntimeState(partitions, completedMigrations, getPartitionStateVersion());
        state.setActiveMigration(migrationManager.getActiveMigration());
        return state;
    } finally {
        lock.unlock();
    }
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Example 2 with InternalPartition

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

the class PartitionReplicaStateChecker method invokeReplicaSyncOperations.

@SuppressWarnings("checkstyle:npathcomplexity")
private int invokeReplicaSyncOperations(int maxBackupCount, Semaphore semaphore, AtomicBoolean result) {
    Address thisAddress = node.getThisAddress();
    ExecutionCallback<Object> callback = new ReplicaSyncResponseCallback(result, semaphore);
    ClusterServiceImpl clusterService = node.getClusterService();
    ClusterState clusterState = clusterService.getClusterState();
    boolean isClusterActive = clusterState == ClusterState.ACTIVE || clusterState == ClusterState.IN_TRANSITION;
    int ownedCount = 0;
    for (InternalPartition partition : partitionStateManager.getPartitions()) {
        Address owner = partition.getOwnerOrNull();
        if (owner == null) {
            result.set(false);
            continue;
        }
        if (!thisAddress.equals(owner)) {
            continue;
        }
        ownedCount++;
        if (maxBackupCount == 0) {
            if (partition.isMigrating()) {
                result.set(false);
            }
            continue;
        }
        for (int index = 1; index <= maxBackupCount; index++) {
            Address replicaAddress = partition.getReplicaAddress(index);
            if (replicaAddress == null) {
                result.set(false);
                semaphore.release();
                continue;
            }
            if (!isClusterActive && clusterService.isMemberRemovedWhileClusterIsNotActive(replicaAddress)) {
                semaphore.release();
                continue;
            }
            CheckReplicaVersionTask task = new CheckReplicaVersionTask(nodeEngine, partitionService, partition.getPartitionId(), index, callback);
            nodeEngine.getOperationService().execute(task);
        }
    }
    return ownedCount;
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) Address(com.hazelcast.nio.Address) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Example 3 with InternalPartition

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

the class PartitionStateGeneratorImpl method initialize.

private void initialize(InternalPartition[] currentState, Address[][] state) {
    int partitionCount = currentState.length;
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        InternalPartition p = currentState[partitionId];
        Address[] replicas = state[partitionId];
        boolean empty = true;
        for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
            replicas[index] = p.getReplicaAddress(index);
            empty &= replicas[index] == null;
        }
        if (empty) {
            continue;
        }
        // auto shift-up colder replicas to hotter replicas to fill the empty gaps
        int maxReplicaIndex = InternalPartition.MAX_REPLICA_COUNT - 1;
        for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
            if (replicas[index] == null) {
                for (int k = maxReplicaIndex; k > index; k--) {
                    if (replicas[k] != null) {
                        replicas[index] = replicas[k];
                        replicas[k] = null;
                        maxReplicaIndex = k - 1;
                        break;
                    }
                }
            }
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Example 4 with InternalPartition

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

the class MigrationRequestOperation method run.

@Override
public void run() {
    NodeEngine nodeEngine = getNodeEngine();
    verifyGoodMaster(nodeEngine);
    Address source = migrationInfo.getSource();
    Address destination = migrationInfo.getDestination();
    verifyExistingTarget(nodeEngine, destination);
    if (destination.equals(source)) {
        getLogger().warning("Source and destination addresses are the same! => " + toString());
        setFailed();
        return;
    }
    InternalPartition partition = getPartition();
    verifySource(nodeEngine.getThisAddress(), partition);
    setActiveMigration();
    if (!migrationInfo.startProcessing()) {
        getLogger().warning("Migration is cancelled -> " + migrationInfo);
        setFailed();
        return;
    }
    try {
        executeBeforeMigrations();
        Collection<Operation> tasks = prepareMigrationOperations();
        InternalPartitionServiceImpl partitionService = getService();
        long[] replicaVersions = partitionService.getPartitionReplicaVersions(migrationInfo.getPartitionId());
        invokeMigrationOperation(destination, replicaVersions, tasks);
        returnResponse = false;
    } catch (Throwable e) {
        logThrowable(e);
        setFailed();
    } finally {
        migrationInfo.doneProcessing();
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartition(com.hazelcast.internal.partition.InternalPartition) Operation(com.hazelcast.spi.Operation)

Example 5 with InternalPartition

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

the class ReplicatedMapService method triggerAntiEntropy.

/** Send an operation to all replicas to check their replica versions for all partitions for which this node is the owner */
public void triggerAntiEntropy() {
    if (clusterService.getSize(DATA_MEMBER_SELECTOR) == 1) {
        return;
    }
    Collection<Address> addresses = new ArrayList<Address>(getMemberAddresses(DATA_MEMBER_SELECTOR));
    addresses.remove(nodeEngine.getThisAddress());
    for (int i = 0; i < partitionContainers.length; i++) {
        Address thisAddress = nodeEngine.getThisAddress();
        InternalPartition partition = partitionService.getPartition(i, false);
        Address ownerAddress = partition.getOwnerOrNull();
        if (!thisAddress.equals(ownerAddress)) {
            continue;
        }
        PartitionContainer partitionContainer = partitionContainers[i];
        if (partitionContainer.isEmpty()) {
            continue;
        }
        for (Address address : addresses) {
            CheckReplicaVersionOperation checkReplicaVersionOperation = new CheckReplicaVersionOperation(partitionContainer);
            checkReplicaVersionOperation.setPartitionId(i);
            checkReplicaVersionOperation.setValidateTarget(false);
            operationService.createInvocationBuilder(SERVICE_NAME, checkReplicaVersionOperation, address).setTryCount(INVOCATION_TRY_COUNT).invoke();
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) CheckReplicaVersionOperation(com.hazelcast.replicatedmap.impl.operation.CheckReplicaVersionOperation) ArrayList(java.util.ArrayList) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Aggregations

InternalPartition (com.hazelcast.internal.partition.InternalPartition)26 ParallelTest (com.hazelcast.test.annotation.ParallelTest)13 QuickTest (com.hazelcast.test.annotation.QuickTest)13 Test (org.junit.Test)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 Address (com.hazelcast.nio.Address)12 Config (com.hazelcast.config.Config)8 ListenerConfig (com.hazelcast.config.ListenerConfig)6 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AssertTask (com.hazelcast.test.AssertTask)4 ClusterState (com.hazelcast.cluster.ClusterState)3 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 Node (com.hazelcast.instance.Node)2 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)2 PartitionRuntimeState (com.hazelcast.internal.partition.PartitionRuntimeState)2 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 TransactionException (com.hazelcast.transaction.TransactionException)2