Search in sources :

Example 6 with InternalPartitionImpl

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

the class InternalPartitionImplConstructorTest method testConstructor.

@Test
public void testConstructor() throws Exception {
    PartitionReplica local = new PartitionReplica(new Address("172.16.16.1", 4223), UuidUtil.newUnsecureUUID());
    PartitionReplica[] replicas = new PartitionReplica[] { new PartitionReplica(new Address("127.0.0.1", 2342), UuidUtil.newUnsecureUUID()) };
    InternalPartition partition = new InternalPartitionImpl(42, local, replicas, 1, null);
    InternalPartitionImplConstructor constructor = new InternalPartitionImplConstructor(InternalPartitionImpl.class);
    InternalPartition clonedPartition = (InternalPartition) constructor.createNew(partition);
    assertEquals(partition.getPartitionId(), clonedPartition.getPartitionId());
    assertEquals(partition.version(), clonedPartition.version());
    assertEquals(partition.getOwnerOrNull(), clonedPartition.getOwnerOrNull());
    assertEquals(partition.getReplicaAddress(0), clonedPartition.getReplicaAddress(0));
    assertEquals(partition.getReplica(0), clonedPartition.getReplica(0));
    assertEquals(partition.getReplicaIndex(replicas[0]), clonedPartition.getReplicaIndex(replicas[0]));
}
Also used : Address(com.hazelcast.cluster.Address) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) InternalPartition(com.hazelcast.internal.partition.InternalPartition) InternalPartitionImplConstructor(com.hazelcast.test.starter.constructor.InternalPartitionImplConstructor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with InternalPartitionImpl

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

the class PartitionReplicaConstructorTest method testConstructor.

@Test
public void testConstructor() {
    HazelcastInstance hz = createHazelcastInstance();
    warmUpPartitions(hz);
    InternalPartitionService partitionService = getNode(hz).getPartitionService();
    InternalPartition[] partitions = partitionService.getInternalPartitions();
    InternalPartitionImpl partition = (InternalPartitionImpl) partitions[0];
    PartitionReplica replica = partition.getReplica(0);
    PartitionReplicaConstructor constructor = new PartitionReplicaConstructor(PartitionReplica.class);
    PartitionReplica clonedReplica = (PartitionReplica) constructor.createNew(replica);
    assertEquals(replica.address(), clonedReplica.address());
    assertEquals(replica.uuid(), clonedReplica.uuid());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) PartitionReplicaConstructor(com.hazelcast.test.starter.constructor.PartitionReplicaConstructor) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) InternalPartition(com.hazelcast.internal.partition.InternalPartition) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with InternalPartitionImpl

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

the class StaleReadDuringMigrationTest method invokeOperation.

private InternalCompletableFuture<Boolean> invokeOperation(final Config config) {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    final HazelcastInstance instance = factory.newHazelcastInstance(config);
    warmUpPartitions(instance);
    final int partitionId = 0;
    final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) getPartitionService(instance);
    final InternalPartitionImpl partition = (InternalPartitionImpl) partitionService.getPartition(partitionId);
    partition.setMigrating();
    final OperationServiceImpl operationService = getOperationService(instance);
    final InvocationBuilder invocationBuilder = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new DummyOperation(), partitionId);
    return invocationBuilder.invoke();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) InvocationBuilder(com.hazelcast.spi.impl.operationservice.InvocationBuilder) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 9 with InternalPartitionImpl

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

the class PartitionTableViewTest method test_createUsingInternalPartitions.

@Test
public void test_createUsingInternalPartitions() throws Exception {
    Address[][] addresses = createRandomAddresses();
    InternalPartition[] partitions = new InternalPartition[addresses.length];
    for (int i = 0; i < partitions.length; i++) {
        partitions[i] = new InternalPartitionImpl(i, null, null, addresses[i]);
    }
    PartitionTableView table = new PartitionTableView(partitions, 0);
    assertEquals(partitions.length, table.getLength());
    for (int i = 0; i < addresses.length; i++) {
        for (int j = 0; j < InternalPartition.MAX_REPLICA_COUNT; j++) {
            assertEquals(partitions[i].getReplicaAddress(j), table.getAddress(i, j));
        }
    }
}
Also used : InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with InternalPartitionImpl

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

the class PartitionBackupReplicaAntiEntropyOperation method run.

@Override
public void run() {
    if (!isNodeStartCompleted()) {
        response = false;
        return;
    }
    InternalPartitionServiceImpl partitionService = getService();
    int partitionId = getPartitionId();
    int replicaIndex = getReplicaIndex();
    InternalPartitionImpl partition = partitionService.getPartitionStateManager().getPartitionImpl(partitionId);
    int currentReplicaIndex = partition.getReplicaIndex(PartitionReplica.from(getNodeEngine().getLocalMember()));
    ILogger logger = getLogger();
    if (replicaIndex != currentReplicaIndex) {
        logger.fine("Anti-entropy operation for partitionId=" + getPartitionId() + ", replicaIndex=" + getReplicaIndex() + " is received, but this node is not the expected backup replica!" + " Current replicaIndex=" + currentReplicaIndex);
        response = false;
        return;
    }
    Address ownerAddress = partition.getOwnerOrNull();
    if (!getCallerAddress().equals(ownerAddress)) {
        logger.fine("Anti-entropy operation for partitionId=" + getPartitionId() + ", replicaIndex=" + getReplicaIndex() + " is received from " + getCallerAddress() + ", but it's not the known primary replica owner: " + ownerAddress);
        response = false;
        return;
    }
    PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
    replicaManager.retainNamespaces(partitionId, versions.keySet());
    if (logger.isFinestEnabled()) {
        logger.finest("Retained namespaces for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ". Namespaces=" + replicaManager.getNamespaces(partitionId));
    }
    Iterator<Map.Entry<ServiceNamespace, Long>> iter = versions.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry<ServiceNamespace, Long> entry = iter.next();
        ServiceNamespace ns = entry.getKey();
        long primaryVersion = entry.getValue();
        long[] currentVersions = replicaManager.getPartitionReplicaVersions(partitionId, ns);
        long currentVersion = currentVersions[replicaIndex - 1];
        if (replicaManager.isPartitionReplicaVersionDirty(partitionId, ns) || currentVersion != primaryVersion) {
            logBackupVersionMismatch(ns, currentVersion, primaryVersion);
            continue;
        }
        iter.remove();
    }
    if (!versions.isEmpty()) {
        replicaManager.triggerPartitionReplicaSync(partitionId, versions.keySet(), replicaIndex);
        response = false;
    }
}
Also used : Address(com.hazelcast.cluster.Address) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) PartitionReplicaManager(com.hazelcast.internal.partition.impl.PartitionReplicaManager) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) ILogger(com.hazelcast.logging.ILogger) HashMap(java.util.HashMap) Map(java.util.Map)

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