Search in sources :

Example 6 with InternalIndex

use of com.hazelcast.query.impl.InternalIndex in project hazelcast by hazelcast.

the class MapMigrationAwareService method depopulateIndexes.

private void depopulateIndexes(PartitionMigrationEvent event, String stepName) {
    assert event.getMigrationEndpoint() == SOURCE;
    assert event.getNewReplicaIndex() != 0 : "Invalid migration event: " + event;
    if (event.getCurrentReplicaIndex() != 0) {
        // backup partitions have no indexes to depopulate
        return;
    }
    PartitionContainer container = mapServiceContext.getPartitionContainer(event.getPartitionId());
    for (RecordStore<Record> recordStore : container.getMaps().values()) {
        MapContainer mapContainer = mapServiceContext.getMapContainer(recordStore.getName());
        Indexes indexes = mapContainer.getIndexes(event.getPartitionId());
        if (!indexes.haveAtLeastOneIndex()) {
            // no indexes to work with
            continue;
        }
        InternalIndex[] indexesSnapshot = indexes.getIndexes();
        Indexes.beginPartitionUpdate(indexesSnapshot);
        CachedQueryEntry<?, ?> entry = new CachedQueryEntry<>(serializationService, mapContainer.getExtractors());
        recordStore.forEach((key, record) -> {
            Object value = Records.getValueOrCachedValue(record, serializationService);
            entry.init(key, value);
            indexes.removeEntry(entry, Index.OperationSource.SYSTEM);
        }, false);
        Indexes.markPartitionAsUnindexed(event.getPartitionId(), indexesSnapshot);
    }
    if (logger.isFinestEnabled()) {
        logger.finest(String.format("Depopulated indexes at step `%s`:[%s]", stepName, event));
    }
}
Also used : InternalIndex(com.hazelcast.query.impl.InternalIndex) Record(com.hazelcast.map.impl.record.Record) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) Indexes(com.hazelcast.query.impl.Indexes)

Example 7 with InternalIndex

use of com.hazelcast.query.impl.InternalIndex in project hazelcast by hazelcast.

the class IndexInFilterIterationTest method check.

private void check(IndexType indexType) {
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap(MAP_NAME);
    map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(indexType).addAttribute("value1"));
    InternalIndex index = getIndex(instance);
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    map.put(1, new Value(null));
    map.put(2, new Value(0));
    map.put(3, new Value(1));
    // No values from both filters
    checkIterator(indexType, descendingDirection, in(equals(2), equals(3)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, in(equals(3), equals(2)).getEntries(index, descendingDirection, evalContext));
    // No values from one filter
    checkIterator(indexType, descendingDirection, in(equals(1), equals(2)).getEntries(index, descendingDirection, evalContext), 3);
    checkIterator(indexType, descendingDirection, in(equals(2), equals(1)).getEntries(index, descendingDirection, evalContext), 3);
    checkIterator(indexType, descendingDirection, in(equals(null, true), equals(2)).getEntries(index, descendingDirection, evalContext), 1);
    checkIterator(indexType, descendingDirection, in(equals(2), equals(null, true)).getEntries(index, descendingDirection, evalContext), 1);
    // Values from both filters
    checkIterator(indexType, descendingDirection, in(equals(0), equals(1)).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(indexType, descendingDirection, in(equals(1), equals(0)).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(indexType, descendingDirection, in(equals(null, true), equals(0)).getEntries(index, descendingDirection, evalContext), 1, 2);
    checkIterator(indexType, descendingDirection, in(equals(0), equals(null, true)).getEntries(index, descendingDirection, evalContext), 1, 2);
    // One distinct value
    checkIterator(indexType, descendingDirection, in(equals(0), equals(0)).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(indexType, descendingDirection, in(equals(null, true), equals(null, true)).getEntries(index, descendingDirection, evalContext), 1);
    // One null value
    checkIterator(indexType, descendingDirection, in(equals(0), equals(null, false)).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(indexType, descendingDirection, in(equals(null, false), equals(0)).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(indexType, descendingDirection, in(equals(null, false), equals(null, true)).getEntries(index, descendingDirection, evalContext), 1);
    checkIterator(indexType, descendingDirection, in(equals(null, true), equals(null, false)).getEntries(index, descendingDirection, evalContext), 1);
    // Two null values
    checkIterator(indexType, descendingDirection, in(equals(null, false), equals(null, false)).getEntries(index, descendingDirection, evalContext));
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig)

Example 8 with InternalIndex

use of com.hazelcast.query.impl.InternalIndex in project hazelcast by hazelcast.

the class IndexRangeFilterIteratorTest method testIterator_simple_between.

@Test
public void testIterator_simple_between() {
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap(MAP_NAME);
    map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(SORTED).addAttribute("value1"));
    InternalIndex index = getIndex(instance);
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    // Check missing value.
    map.put(0, new Value(0));
    map.put(1, new Value(10));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext));
    // Check left bound
    map.put(2, new Value(1));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
    map.put(3, new Value(1));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
    map.remove(2);
    map.remove(3);
    // Check right bound
    map.put(2, new Value(5));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
    map.put(3, new Value(5));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
    map.remove(2);
    map.remove(3);
    // Check middle
    map.put(2, new Value(3));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
    map.put(3, new Value(3));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
    map.remove(2);
    map.remove(3);
    // Check combined
    map.put(2, new Value(1));
    map.put(3, new Value(1));
    map.put(4, new Value(3));
    map.put(5, new Value(3));
    map.put(6, new Value(5));
    map.put(7, new Value(5));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext), 4, 5);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2, 3, 4, 5);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 4, 5, 6, 7);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3, 4, 5, 6, 7);
    // Check null value.
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(null, false), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(null, false), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(null, false), false, intValue(null, false), false).getEntries(index, descendingDirection, evalContext));
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with InternalIndex

use of com.hazelcast.query.impl.InternalIndex in project hazelcast by hazelcast.

the class EvaluateVisitorTest method before.

@SuppressWarnings("SuspiciousMethodCalls")
@Before
public void before() {
    indexes = mock(Indexes.class);
    InternalIndex bitmapA = mock(InternalIndex.class);
    when(bitmapA.getConverter()).thenReturn(TypeConverters.INTEGER_CONVERTER);
    when(bitmapA.getName()).thenReturn("a");
    when(indexes.matchIndex(eq("a"), any(), eq(IndexMatchHint.EXACT_NAME), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> EVALUABLE_PREDICATES.contains(invocation.getArgument(1)) ? bitmapA : null);
    when(indexes.matchIndex(eq("a"), any(), eq(IndexMatchHint.PREFER_UNORDERED), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> EVALUABLE_PREDICATES.contains(invocation.getArgument(1)) ? bitmapA : null);
    InternalIndex bitmapB = mock(InternalIndex.class);
    when(bitmapB.getConverter()).thenReturn(TypeConverters.STRING_CONVERTER);
    when(bitmapB.getName()).thenReturn("b");
    when(indexes.matchIndex(eq("b"), any(), eq(IndexMatchHint.EXACT_NAME), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> EVALUABLE_PREDICATES.contains(invocation.getArgument(1)) ? bitmapB : null);
    when(indexes.matchIndex(eq("b"), any(), eq(IndexMatchHint.PREFER_UNORDERED), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> EVALUABLE_PREDICATES.contains(invocation.getArgument(1)) ? bitmapB : null);
    InternalIndex bitmapNoConverter = mock(InternalIndex.class);
    when(bitmapNoConverter.getName()).thenReturn("nc");
    when(bitmapNoConverter.getConverter()).thenReturn(null);
    when(indexes.matchIndex(eq("nc"), any(), eq(IndexMatchHint.EXACT_NAME), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> EVALUABLE_PREDICATES.contains(invocation.getArgument(1)) ? bitmapNoConverter : null);
    when(indexes.matchIndex(eq("nc"), any(), eq(IndexMatchHint.PREFER_UNORDERED), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> EVALUABLE_PREDICATES.contains(invocation.getArgument(1)) ? bitmapNoConverter : null);
    InternalIndex bitmapNoSubPredicates = mock(InternalIndex.class);
    when(bitmapNoSubPredicates.getName()).thenReturn("ns");
    when(bitmapNoSubPredicates.getConverter()).thenReturn(TypeConverters.INTEGER_CONVERTER);
    when(indexes.matchIndex(eq("ns"), any(), eq(IndexMatchHint.EXACT_NAME), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> {
        Object clazz = invocation.getArgument(1);
        if (clazz == AndPredicate.class || clazz == OrPredicate.class || clazz == NotPredicate.class) {
            return null;
        } else {
            return bitmapNoSubPredicates;
        }
    });
    when(indexes.matchIndex(eq("ns"), any(), eq(IndexMatchHint.PREFER_UNORDERED), eq(SKIP_PARTITIONS_COUNT_CHECK))).then((Answer<InternalIndex>) invocation -> {
        Object clazz = invocation.getArgument(1);
        if (clazz == AndPredicate.class || clazz == OrPredicate.class || clazz == NotPredicate.class) {
            return null;
        } else {
            return bitmapNoSubPredicates;
        }
    });
    visitor = new EvaluateVisitor();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Indexes(com.hazelcast.query.impl.Indexes) QuickTest(com.hazelcast.test.annotation.QuickTest) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) Predicates.notEqual(com.hazelcast.query.Predicates.notEqual) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Assert.assertSame(org.junit.Assert.assertSame) Answer(org.mockito.stubbing.Answer) TypeConverters(com.hazelcast.query.impl.TypeConverters) SKIP_PARTITIONS_COUNT_CHECK(com.hazelcast.query.impl.Indexes.SKIP_PARTITIONS_COUNT_CHECK) Arrays.asList(java.util.Arrays.asList) Predicate(com.hazelcast.query.Predicate) Before(org.junit.Before) Predicates.in(com.hazelcast.query.Predicates.in) Predicates.not(com.hazelcast.query.Predicates.not) Predicates.and(com.hazelcast.query.Predicates.and) IndexMatchHint(com.hazelcast.query.impl.QueryContext.IndexMatchHint) Predicates.or(com.hazelcast.query.Predicates.or) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Predicates.alwaysFalse(com.hazelcast.query.Predicates.alwaysFalse) Mockito.when(org.mockito.Mockito.when) Category(org.junit.experimental.categories.Category) Predicates.equal(com.hazelcast.query.Predicates.equal) List(java.util.List) InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Predicates.like(com.hazelcast.query.Predicates.like) CustomPredicate(com.hazelcast.query.impl.predicates.VisitorTestSupport.CustomPredicate) Mockito.mock(org.mockito.Mockito.mock) InternalIndex(com.hazelcast.query.impl.InternalIndex) Indexes(com.hazelcast.query.impl.Indexes) Before(org.junit.Before)

Example 10 with InternalIndex

use of com.hazelcast.query.impl.InternalIndex in project hazelcast by hazelcast.

the class IndexStatsChangingNumberOfMembersTest method awaitStable.

protected void awaitStable(String mapName, HazelcastInstance... instances) {
    // Await for migrations to complete.
    waitAllForSafeState(instances);
    // Make sure that all indexes contain expected partitions.
    final Map<UUID, PartitionIdSet> memberToPartitions = toMemberToPartitionsMap(instances[0]);
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            InternalIndex index = ((MapProxyImpl<?, ?>) instance.getMap(mapName)).getService().getMapServiceContext().getMapContainer(mapName).getIndexes().getIndex(INDEX_NAME);
            assertNotNull(index);
            PartitionIdSet expectedPartitions = memberToPartitions.get(instance.getCluster().getLocalMember().getUuid());
            // Double check: if we still see same partition distribution
            assertEquals(memberToPartitions, toMemberToPartitionsMap(instances[0]));
            assertEquals("MemberPartitions={size=" + expectedPartitions.size() + ", partitions=" + expectedPartitions + "}, " + index, expectedPartitions, index.getPartitionStamp().partitions);
        }
    });
}
Also used : InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) UUID(java.util.UUID)

Aggregations

InternalIndex (com.hazelcast.query.impl.InternalIndex)22 IndexConfig (com.hazelcast.config.IndexConfig)11 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 Indexes (com.hazelcast.query.impl.Indexes)9 ExpressionEvalContext (com.hazelcast.sql.impl.expression.ExpressionEvalContext)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 IndexRangeFilter (com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter)4 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 CacheDeserializedValues (com.hazelcast.config.CacheDeserializedValues)2 MapContainer (com.hazelcast.map.impl.MapContainer)2 Record (com.hazelcast.map.impl.record.Record)2 Predicate (com.hazelcast.query.Predicate)2 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)2 IndexEqualsFilter (com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter)2 HazelcastInstanceProxy (com.hazelcast.instance.impl.HazelcastInstanceProxy)1 LocalRecordStoreStats (com.hazelcast.internal.monitor.LocalRecordStoreStats)1 OnDemandIndexStats (com.hazelcast.internal.monitor.impl.OnDemandIndexStats)1