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));
}
}
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));
}
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));
}
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();
}
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);
}
});
}
Aggregations