Search in sources :

Example 11 with IndexIterationPointer

use of com.hazelcast.internal.iteration.IndexIterationPointer in project hazelcast by hazelcast.

the class MapIndexScanP method splitOnMigration.

/**
 * Perform splitting of a {@link Split} after receiving {@link MissingPartitionException}
 * or various cluster state exceptions like {@link MemberLeftException}.
 * <p>
 * Method gets current partition table and proceeds with following procedure:
 * <p>
 * It splits the partitions assigned to the split according to the new
 * partition owner into disjoint sets, one for each owner.
 *
 * @param split the split to split
 * @return collection of new split units
 */
private List<Split> splitOnMigration(Split split) {
    IndexIterationPointer[] lastPointers = split.pointers;
    InternalPartitionService partitionService = getNodeEngine(hazelcastInstance).getPartitionService();
    Map<Address, Split> newSplits = new HashMap<>();
    PrimitiveIterator.OfInt partitionIterator = split.partitions.intIterator();
    while (partitionIterator.hasNext()) {
        int partitionId = partitionIterator.nextInt();
        // If at least one partition owner is not assigned -- assign current member.
        // Later, a WrongTargetException will be thrown
        // and it causes this method to be called again.
        // Occasionally prediction with current member would be correct.
        Address potentialOwner = partitionService.getPartition(partitionId).getOwnerOrNull();
        Address owner = potentialOwner == null ? split.owner : partitionService.getPartition(partitionId).getOwnerOrNull();
        newSplits.computeIfAbsent(owner, x -> new Split(new PartitionIdSet(partitionService.getPartitionCount()), owner, lastPointers)).partitions.add(partitionId);
    }
    return new ArrayList<>(newSplits.values());
}
Also used : Address(com.hazelcast.cluster.Address) PrimitiveIterator(java.util.PrimitiveIterator) IndexIterationPointer(com.hazelcast.internal.iteration.IndexIterationPointer) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) HashMap(java.util.HashMap) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) ArrayList(java.util.ArrayList)

Example 12 with IndexIterationPointer

use of com.hazelcast.internal.iteration.IndexIterationPointer in project hazelcast by hazelcast.

the class MapFetchIndexOperationTest method whenSizeLimitIsSmall_thenFetchInMultipleCalls.

@Test
public void whenSizeLimitIsSmall_thenFetchInMultipleCalls() throws ExecutionException, InterruptedException {
    PartitionIdSet partitions = getLocalPartitions(instance);
    IndexIterationPointer[] pointers = new IndexIterationPointer[2];
    pointers[0] = IndexIterationPointer.create(30, true, 50, false, false, null);
    pointers[1] = IndexIterationPointer.create(50, true, 60, true, false, null);
    MapOperationProvider operationProvider = getOperationProvider(map);
    MapOperation operation = operationProvider.createFetchIndexOperation(mapName, orderedIndexName, pointers, partitions, 5);
    Address address = instance.getCluster().getLocalMember().getAddress();
    OperationServiceImpl operationService = getOperationService(instance);
    MapFetchIndexOperationResult result = operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, address).<MapFetchIndexOperationResult>invoke().get();
    assertResultSorted(result, Arrays.asList(new Person("person2", 39, "Dep1"), new Person("person5", 43, "Dep2"), new Person("person1", 45, "Dep1"), new Person("person4", 45, "Dep2"), new Person("person9", 45, "Dep3")));
    // First pointer is not done yet
    assertEquals(2, result.getPointers().length);
    operation = operationProvider.createFetchIndexOperation(mapName, orderedIndexName, result.getPointers(), partitions, 5);
    result = operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, address).<MapFetchIndexOperationResult>invoke().get();
    assertResultSorted(result, Arrays.asList(new Person("person10", 45, "Dep4"), new Person("person11", 45, "Dep5"), new Person("person3", 60, "Dep1")));
    assertEquals(0, result.getPointers().length);
}
Also used : Address(com.hazelcast.cluster.Address) IndexIterationPointer(com.hazelcast.internal.iteration.IndexIterationPointer) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapFetchIndexOperationResult(com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with IndexIterationPointer

use of com.hazelcast.internal.iteration.IndexIterationPointer in project hazelcast by hazelcast.

the class MapFetchIndexOperationTest method testRange.

@Test
public void testRange() throws ExecutionException, InterruptedException {
    PartitionIdSet partitions = getLocalPartitions(instance);
    IndexIterationPointer[] pointers = new IndexIterationPointer[1];
    pointers[0] = IndexIterationPointer.create(30, true, 60, false, false, null);
    MapOperationProvider operationProvider = getOperationProvider(map);
    MapOperation operation = operationProvider.createFetchIndexOperation(mapName, orderedIndexName, pointers, partitions, 7);
    Address address = instance.getCluster().getLocalMember().getAddress();
    OperationServiceImpl operationService = getOperationService(instance);
    MapFetchIndexOperationResult result = operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, address).<MapFetchIndexOperationResult>invoke().get();
    assertResultSorted(result, Arrays.asList(new Person("person2", 39, "Dep1"), new Person("person5", 43, "Dep2"), new Person("person1", 45, "Dep1"), new Person("person4", 45, "Dep2"), new Person("person9", 45, "Dep3"), new Person("person10", 45, "Dep4"), new Person("person11", 45, "Dep5")));
}
Also used : Address(com.hazelcast.cluster.Address) IndexIterationPointer(com.hazelcast.internal.iteration.IndexIterationPointer) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapFetchIndexOperationResult(com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with IndexIterationPointer

use of com.hazelcast.internal.iteration.IndexIterationPointer in project hazelcast by hazelcast.

the class MapFetchIndexOperationTest method testMultipleLookups.

@Test
public void testMultipleLookups() throws ExecutionException, InterruptedException {
    PartitionIdSet partitions = getLocalPartitions(instance);
    IndexIterationPointer[] pointers = new IndexIterationPointer[3];
    pointers[0] = IndexIterationPointer.create(30, true, 30, true, false, null);
    pointers[1] = IndexIterationPointer.create(39, true, 39, true, false, null);
    pointers[2] = IndexIterationPointer.create(45, true, 45, true, false, null);
    MapOperationProvider operationProvider = getOperationProvider(map);
    MapOperation operation = operationProvider.createFetchIndexOperation(mapName, hashIndexName, pointers, partitions, 10);
    Address address = instance.getCluster().getLocalMember().getAddress();
    OperationServiceImpl operationService = getOperationService(instance);
    MapFetchIndexOperationResult result = operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, address).<MapFetchIndexOperationResult>invoke().get();
    assertResult(result, Arrays.asList(new Person("person2", 39, "Dep1"), new Person("person1", 45, "Dep1"), new Person("person4", 45, "Dep2"), new Person("person9", 45, "Dep3"), new Person("person10", 45, "Dep4"), new Person("person11", 45, "Dep5")));
}
Also used : Address(com.hazelcast.cluster.Address) IndexIterationPointer(com.hazelcast.internal.iteration.IndexIterationPointer) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapFetchIndexOperationResult(com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with IndexIterationPointer

use of com.hazelcast.internal.iteration.IndexIterationPointer in project hazelcast by hazelcast.

the class MapFetchIndexOperationTest method testMultipleRanges.

@Test
public void testMultipleRanges() throws ExecutionException, InterruptedException {
    PartitionIdSet partitions = getLocalPartitions(instance);
    IndexIterationPointer[] pointers = new IndexIterationPointer[2];
    pointers[0] = IndexIterationPointer.create(30, true, 40, true, false, null);
    pointers[1] = IndexIterationPointer.create(50, true, 60, true, false, null);
    MapOperationProvider operationProvider = getOperationProvider(map);
    MapOperation operation = operationProvider.createFetchIndexOperation(mapName, orderedIndexName, pointers, partitions, 5);
    Address address = instance.getCluster().getLocalMember().getAddress();
    OperationServiceImpl operationService = getOperationService(instance);
    MapFetchIndexOperationResult result = operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, address).<MapFetchIndexOperationResult>invoke().get();
    assertResultSorted(result, Arrays.asList(new Person("person2", 39, "Dep1"), new Person("person3", 60, "Dep1")));
}
Also used : Address(com.hazelcast.cluster.Address) IndexIterationPointer(com.hazelcast.internal.iteration.IndexIterationPointer) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapFetchIndexOperationResult(com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IndexIterationPointer (com.hazelcast.internal.iteration.IndexIterationPointer)15 Address (com.hazelcast.cluster.Address)11 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)11 MapFetchIndexOperationResult (com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult)11 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)4 MapAssignAndGetUuidsOperation (com.hazelcast.client.impl.protocol.task.map.MapAssignAndGetUuidsOperation)1 MapAssignAndGetUuidsOperationFactory (com.hazelcast.client.impl.protocol.task.map.MapAssignAndGetUuidsOperationFactory)1 IndexConfig (com.hazelcast.config.IndexConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 LocalRecordStoreStatsImpl (com.hazelcast.internal.monitor.impl.LocalRecordStoreStatsImpl)1 BatchNearCacheInvalidation (com.hazelcast.internal.nearcache.impl.invalidation.BatchNearCacheInvalidation)1 SingleNearCacheInvalidation (com.hazelcast.internal.nearcache.impl.invalidation.SingleNearCacheInvalidation)1 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)1 Data (com.hazelcast.internal.serialization.Data)1 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1 ConstructorFunction (com.hazelcast.internal.util.ConstructorFunction)1