Search in sources :

Example 1 with InternalPartitionImpl

use of com.hazelcast.internal.partition.impl.InternalPartitionImpl in project hazelcast by hazelcast.

the class ReplicaSyncResponse method run.

@Override
public void run() throws Exception {
    NodeEngine nodeEngine = getNodeEngine();
    InternalPartitionServiceImpl partitionService = getService();
    int partitionId = getPartitionId();
    int replicaIndex = getReplicaIndex();
    PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
    InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
    Address thisAddress = nodeEngine.getThisAddress();
    int currentReplicaIndex = partition.getReplicaIndex(thisAddress);
    try {
        if (replicaIndex == currentReplicaIndex) {
            executeTasks();
        } else {
            nodeNotOwnsBackup(partition);
        }
        if (tasks != null) {
            tasks.clear();
        }
    } finally {
        postProcessReplicaSync(partitionService, currentReplicaIndex);
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) PartitionStateManager(com.hazelcast.internal.partition.impl.PartitionStateManager)

Example 2 with InternalPartitionImpl

use of com.hazelcast.internal.partition.impl.InternalPartitionImpl in project hazelcast by hazelcast.

the class ReplicaSyncRetryResponse method run.

@Override
public void run() throws Exception {
    final InternalPartitionServiceImpl partitionService = getService();
    final int partitionId = getPartitionId();
    final int replicaIndex = getReplicaIndex();
    partitionService.getReplicaManager().clearReplicaSyncRequest(partitionId, replicaIndex);
    PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
    InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
    Address thisAddress = getNodeEngine().getThisAddress();
    ILogger logger = getLogger();
    int currentReplicaIndex = partition.getReplicaIndex(thisAddress);
    if (currentReplicaIndex > 0) {
        if (logger.isFinestEnabled()) {
            logger.finest("Retrying replica sync request for partitionId=" + partitionId + ", initial-replicaIndex=" + replicaIndex + ", current-replicaIndex=" + currentReplicaIndex);
        }
        partitionService.getReplicaManager().triggerPartitionReplicaSync(partitionId, currentReplicaIndex, InternalPartitionService.REPLICA_SYNC_RETRY_DELAY);
    } else if (logger.isFinestEnabled()) {
        logger.finest("No need to retry replica sync request for partitionId=" + partitionId + ", initial-replicaIndex=" + replicaIndex + ", current-replicaIndex=" + currentReplicaIndex);
    }
}
Also used : Address(com.hazelcast.nio.Address) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) ILogger(com.hazelcast.logging.ILogger) PartitionStateManager(com.hazelcast.internal.partition.impl.PartitionStateManager)

Example 3 with InternalPartitionImpl

use of com.hazelcast.internal.partition.impl.InternalPartitionImpl in project hazelcast by hazelcast.

the class ReplicaSyncRequest method preCheckReplicaSync.

/** Checks if we can continue with the replication or not. Can send a retry or empty response to the replica in some cases */
private boolean preCheckReplicaSync(NodeEngineImpl nodeEngine, int partitionId, int replicaIndex) throws IOException {
    InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) nodeEngine.getPartitionService();
    PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
    InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
    Address owner = partition.getOwnerOrNull();
    long[] replicaVersions = partitionService.getPartitionReplicaVersions(partitionId);
    long currentVersion = replicaVersions[replicaIndex - 1];
    ILogger logger = getLogger();
    if (!nodeEngine.getThisAddress().equals(owner)) {
        if (logger.isFinestEnabled()) {
            logger.finest("Wrong target! " + toString() + " cannot be processed! Target should be: " + owner);
        }
        sendRetryResponse();
        return false;
    }
    if (currentVersion == 0) {
        if (logger.isFinestEnabled()) {
            logger.finest("Current replicaVersion=0, sending empty response for partitionId=" + getPartitionId() + ", replicaIndex=" + getReplicaIndex() + ", replicaVersions=" + Arrays.toString(replicaVersions));
        }
        sendEmptyResponse();
        return false;
    }
    if (!partitionService.getReplicaManager().tryToAcquireReplicaSyncPermit()) {
        if (logger.isFinestEnabled()) {
            logger.finest("Max parallel replication process limit exceeded! Could not run replica sync -> " + toString());
        }
        sendRetryResponse();
        return false;
    }
    return true;
}
Also used : Address(com.hazelcast.nio.Address) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) ILogger(com.hazelcast.logging.ILogger) PartitionStateManager(com.hazelcast.internal.partition.impl.PartitionStateManager)

Example 4 with InternalPartitionImpl

use of com.hazelcast.internal.partition.impl.InternalPartitionImpl in project hazelcast by hazelcast.

the class PromotionCommitOperation method filterAlreadyAppliedPromotions.

private void filterAlreadyAppliedPromotions() {
    if (getNodeEngine().getClusterService().getClusterVersion().isUnknownOrLessOrEqual(Versions.V4_0)) {
        return;
    }
    ILogger logger = getLogger();
    InternalPartitionServiceImpl partitionService = getService();
    PartitionStateManager stateManager = partitionService.getPartitionStateManager();
    Iterator<MigrationInfo> iter = promotions.iterator();
    while (iter.hasNext()) {
        MigrationInfo promotion = iter.next();
        InternalPartitionImpl partition = stateManager.getPartitionImpl(promotion.getPartitionId());
        if (partition.version() >= promotion.getFinalPartitionVersion()) {
            logger.fine("Already applied promotion commit. -> " + promotion);
            iter.remove();
        }
    }
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) ILogger(com.hazelcast.logging.ILogger) PartitionStateManager(com.hazelcast.internal.partition.impl.PartitionStateManager)

Example 5 with InternalPartitionImpl

use of com.hazelcast.internal.partition.impl.InternalPartitionImpl in project hazelcast by hazelcast.

the class PartitionRuntimeState method getPartitions.

public InternalPartition[] getPartitions() {
    int length = encodedPartitionTable.length;
    InternalPartition[] result = new InternalPartition[length];
    for (int partitionId = 0; partitionId < length; partitionId++) {
        int[] addressIndexes = encodedPartitionTable[partitionId];
        PartitionReplica[] replicas = new PartitionReplica[MAX_REPLICA_COUNT];
        for (int replicaIndex = 0; replicaIndex < addressIndexes.length; replicaIndex++) {
            int index = addressIndexes[replicaIndex];
            if (index != -1) {
                PartitionReplica replica = allReplicas[index];
                assert replica != null;
                replicas[replicaIndex] = replica;
            }
        }
        result[partitionId] = new InternalPartitionImpl(partitionId, null, replicas, versions[partitionId], null);
    }
    return result;
}
Also used : InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl)

Aggregations

InternalPartitionImpl (com.hazelcast.internal.partition.impl.InternalPartitionImpl)13 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)8 PartitionStateManager (com.hazelcast.internal.partition.impl.PartitionStateManager)6 ILogger (com.hazelcast.logging.ILogger)5 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)3 Address (com.hazelcast.nio.Address)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 Address (com.hazelcast.cluster.Address)2 InternalPartition (com.hazelcast.internal.partition.InternalPartition)2 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)2 NodeEngine (com.hazelcast.spi.impl.NodeEngine)2 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)1 PartitionReplicaManager (com.hazelcast.internal.partition.impl.PartitionReplicaManager)1 ServiceNamespace (com.hazelcast.internal.services.ServiceNamespace)1 NodeEngine (com.hazelcast.spi.NodeEngine)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 AbstractLocalOperation (com.hazelcast.spi.impl.operationservice.AbstractLocalOperation)1