Search in sources :

Example 1 with IndexIterationPointer

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

the class MapFetchIndexOperation method writeInternal.

@Override
protected void writeInternal(ObjectDataOutput out) throws IOException {
    super.writeInternal(out);
    out.writeString(indexName);
    out.writeObject(partitionIdSet);
    out.writeInt(pointers.length);
    for (IndexIterationPointer pointer : pointers) {
        out.writeObject(pointer);
    }
    out.writeInt(sizeLimit);
}
Also used : IndexIterationPointer(com.hazelcast.internal.iteration.IndexIterationPointer)

Example 2 with IndexIterationPointer

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

the class MapFetchIndexOperation method runInternalSorted.

@SuppressWarnings({ "checkstyle:CyclomaticComplexity", "checkstyle:NPathComplexity", "checkstyle:MethodLength" })
private MapFetchIndexOperationResult runInternalSorted(InternalIndex index) {
    List<QueryableEntry<?, ?>> entries = new ArrayList<>(sizeLimit);
    int partitionCount = getNodeEngine().getPartitionService().getPartitionCount();
    for (int i = 0; i < pointers.length; i++) {
        IndexIterationPointer pointer = pointers[i];
        Data lastEntryKeyData = pointer.getLastEntryKeyData();
        Comparator<Data> comparator = OrderedIndexStore.DATA_COMPARATOR;
        if (isDescendingEntryKey(pointer)) {
            comparator = comparator.reversed();
        }
        Iterator<IndexKeyEntries> entryIterator = getEntryIterator(index, pointer);
        while (entryIterator.hasNext()) {
            IndexKeyEntries indexKeyEntries = entryIterator.next();
            @SuppressWarnings({ "rawtypes" }) Iterator<QueryableEntry> keyEntries = indexKeyEntries.getEntries();
            // Skip until the entry last read
            if (lastEntryKeyData != null) {
                while (keyEntries.hasNext()) {
                    QueryableEntry<?, ?> entry = keyEntries.next();
                    int comparison = comparator.compare(entry.getKeyData(), lastEntryKeyData);
                    if (comparison >= 0) {
                        if (comparison > 0 && isInPartitionSet(entry, partitionIdSet, partitionCount)) {
                            entries.add(entry);
                            lastEntryKeyData = entry.getKeyData();
                        }
                        break;
                    }
                }
            }
            // Read and add until size limit is reached or iterator ends
            while (keyEntries.hasNext() && entries.size() < sizeLimit) {
                QueryableEntry<?, ?> entry = keyEntries.next();
                if (isInPartitionSet(entry, partitionIdSet, partitionCount)) {
                    entries.add(entry);
                    lastEntryKeyData = entry.getKeyData();
                }
            }
            if (!keyEntries.hasNext()) {
                lastEntryKeyData = null;
            }
            if (entries.size() >= sizeLimit) {
                IndexIterationPointer[] newPointers;
                if (entryIterator.hasNext() || lastEntryKeyData != null) {
                    Comparable<?> currentIndexKey = indexKeyEntries.getIndexKey();
                    newPointers = new IndexIterationPointer[pointers.length - i];
                    if (lastEntryKeyData != null) {
                        newPointers[0] = IndexIterationPointer.create(pointer.isDescending() ? pointer.getFrom() : currentIndexKey, !pointer.isDescending() || pointer.isFromInclusive(), pointer.isDescending() ? currentIndexKey : pointer.getTo(), pointer.isDescending() || pointer.isToInclusive(), pointer.isDescending(), lastEntryKeyData);
                    } else {
                        newPointers[0] = IndexIterationPointer.create(pointer.isDescending() ? pointer.getFrom() : currentIndexKey, pointer.isDescending() && pointer.isFromInclusive(), pointer.isDescending() ? currentIndexKey : pointer.getTo(), !pointer.isDescending() && pointer.isToInclusive(), pointer.isDescending(), null);
                    }
                    System.arraycopy(pointers, i + 1, newPointers, 1, newPointers.length - 1);
                } else {
                    newPointers = new IndexIterationPointer[pointers.length - i - 1];
                    System.arraycopy(pointers, i + 1, newPointers, 0, newPointers.length);
                }
                return new MapFetchIndexOperationResult(entries, newPointers);
            }
        }
    }
    return new MapFetchIndexOperationResult(entries, new IndexIterationPointer[0]);
}
Also used : IndexKeyEntries(com.hazelcast.query.impl.IndexKeyEntries) IndexIterationPointer(com.hazelcast.internal.iteration.IndexIterationPointer) ArrayList(java.util.ArrayList) Data(com.hazelcast.internal.serialization.Data) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 3 with IndexIterationPointer

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

the class MapFetchIndexOperationTest method testRangeReverse.

@Test
public void testRangeReverse() throws ExecutionException, InterruptedException {
    PartitionIdSet partitions = getLocalPartitions(instance);
    IndexIterationPointer[] pointers = new IndexIterationPointer[1];
    pointers[0] = IndexIterationPointer.create(30, true, 60, false, true, null);
    MapOperationProvider operationProvider = getOperationProvider(map);
    MapOperation operation = operationProvider.createFetchIndexOperation(mapName, orderedIndexName, 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();
    assertResultSorted(result, Arrays.asList(new Person("person11", 45, "Dep5"), new Person("person10", 45, "Dep4"), new Person("person9", 45, "Dep3"), new Person("person4", 45, "Dep2"), new Person("person1", 45, "Dep1"), new Person("person5", 43, "Dep2"), new Person("person2", 39, "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)

Example 4 with IndexIterationPointer

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

the class MapFetchIndexOperationTest method whenSizeLimitIsSmall_thenFetchInMultipleCalls_reverse.

@Test
public void whenSizeLimitIsSmall_thenFetchInMultipleCalls_reverse() throws ExecutionException, InterruptedException {
    PartitionIdSet partitions = getLocalPartitions(instance);
    IndexIterationPointer[] pointers = new IndexIterationPointer[2];
    pointers[0] = IndexIterationPointer.create(50, true, 60, true, true, null);
    pointers[1] = IndexIterationPointer.create(30, true, 50, false, true, 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("person3", 60, "Dep1"), new Person("person11", 45, "Dep5"), new Person("person10", 45, "Dep4"), new Person("person9", 45, "Dep3"), new Person("person4", 45, "Dep2")));
    // First pointer is done in reverse case
    assertEquals(1, 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("person1", 45, "Dep1"), new Person("person5", 43, "Dep2"), new Person("person2", 39, "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 5 with IndexIterationPointer

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

the class MapFetchIndexOperationTest method testMigration.

// This test has different requirements, therefore depends on local variables.
// Before and After actions are dismissed.
@Test
public void testMigration() {
    HazelcastInstance instance = new CustomTestInstanceFactory().newHazelcastInstance(config);
    PartitionIdSet partitions = getLocalPartitions(instance);
    List<Person> people = new ArrayList<>(Arrays.asList(new Person("person1", 45, null), new Person("person2", 39, null), new Person("person3", 60, null), new Person("person4", 45, null), new Person("person5", 43, null)));
    IMap<String, Person> map = instance.getMap(mapName);
    map.addIndex(new IndexConfig(IndexType.SORTED, "age").setName(orderedIndexName));
    insertIntoMap(map, people);
    IndexIterationPointer[] pointers = new IndexIterationPointer[1];
    pointers[0] = IndexIterationPointer.create(10, true, 100, true, false, null);
    MapOperationProvider operationProvider = getOperationProvider(map);
    MapOperation operation = operationProvider.createFetchIndexOperation(mapName, orderedIndexName, pointers, partitions, 10);
    Address address = instance.getCluster().getLocalMember().getAddress();
    OperationServiceImpl operationService = getOperationService(instance);
    try {
        InvocationFuture<MapFetchIndexOperationResult> future = operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, address).invoke();
        future.get();
    } catch (Exception e) {
        assertInstanceOf(MissingPartitionException.class, e.getCause());
    } finally {
        instance.shutdown();
    }
}
Also used : Address(com.hazelcast.cluster.Address) IndexIterationPointer(com.hazelcast.internal.iteration.IndexIterationPointer) ArrayList(java.util.ArrayList) MapFetchIndexOperationResult(com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult) MissingPartitionException(com.hazelcast.map.impl.operation.MapFetchIndexOperation.MissingPartitionException) ExecutionException(java.util.concurrent.ExecutionException) MissingPartitionException(com.hazelcast.map.impl.operation.MapFetchIndexOperation.MissingPartitionException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) 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