Search in sources :

Example 11 with InternalPartitionImpl

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

the class PartitionReplicaSyncResponse 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);
    int currentReplicaIndex = partition.getReplicaIndex(PartitionReplica.from(nodeEngine.getLocalMember()));
    try {
        if (replicaIndex == currentReplicaIndex) {
            executeOperations();
        } else {
            nodeNotOwnsBackup(partition);
        }
        if (operations != null) {
            operations.clear();
        }
    } finally {
        postProcessReplicaSync(partitionService, currentReplicaIndex);
    }
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) PartitionStateManager(com.hazelcast.internal.partition.impl.PartitionStateManager)

Example 12 with InternalPartitionImpl

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

the class PartitionReplicaSyncRequest method checkPartitionOwner.

/**
 * Checks if we are the primary owner of the partition.
 */
protected boolean checkPartitionOwner() {
    InternalPartitionServiceImpl partitionService = getService();
    PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
    InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId());
    PartitionReplica owner = partition.getOwnerReplicaOrNull();
    NodeEngine nodeEngine = getNodeEngine();
    if (owner == null || !owner.isIdentical(nodeEngine.getLocalMember())) {
        ILogger logger = getLogger();
        if (logger.isFinestEnabled()) {
            logger.finest("This node is not owner partition. Cannot process request. partitionId=" + partitionId() + ", replicaIndex=" + getReplicaIndex() + ", namespaces=" + namespaces);
        }
        return false;
    }
    return true;
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) 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 13 with InternalPartitionImpl

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

the class InvocationUtilTest method executeLocallyRetriesWhenPartitionIsMigrating.

@Test
public void executeLocallyRetriesWhenPartitionIsMigrating() throws InterruptedException {
    final HazelcastInstance instance = createHazelcastInstance(smallInstanceConfig());
    final NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(instance);
    final InternalPartitionService partitionService = nodeEngineImpl.getPartitionService();
    final int randomPartitionId = (int) (Math.random() * partitionService.getPartitionCount());
    final InternalPartitionImpl partition = (InternalPartitionImpl) partitionService.getPartition(randomPartitionId);
    partition.setMigrating();
    final String operationResponse = "operationResponse";
    final Operation operation = new LocalOperation(operationResponse).setPartitionId(randomPartitionId);
    final LocalRetryableExecution execution = executeLocallyWithRetry(nodeEngineImpl, operation);
    spawn(new Runnable() {

        @Override
        public void run() {
            try {
                TimeUnit.SECONDS.sleep(10);
            } catch (InterruptedException e) {
            }
            partition.resetMigrating();
        }
    });
    assertTrue(execution.awaitCompletion(1, TimeUnit.MINUTES));
    assertEquals(operationResponse, execution.getResponse());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) AbstractLocalOperation(com.hazelcast.spi.impl.operationservice.AbstractLocalOperation) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) AbstractLocalOperation(com.hazelcast.spi.impl.operationservice.AbstractLocalOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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