use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class AddIndexOperation method runInternal.
@Override
public void runInternal() {
int partitionId = getPartitionId();
Indexes indexes = mapContainer.getIndexes(partitionId);
InternalIndex index = indexes.addOrGetIndex(config);
if (index.hasPartitionIndexed(partitionId)) {
return;
}
SerializationService serializationService = getNodeEngine().getSerializationService();
index.beginPartitionUpdate();
CacheDeserializedValues cacheDeserializedValues = mapContainer.getMapConfig().getCacheDeserializedValues();
CachedQueryEntry<?, ?> cachedEntry = cacheDeserializedValues == NEVER ? new CachedQueryEntry<>(serializationService, mapContainer.getExtractors()) : null;
recordStore.forEach((dataKey, record) -> {
Object value = Records.getValueOrCachedValue(record, serializationService);
QueryableEntry<?, ?> queryEntry = mapContainer.newQueryEntry(dataKey, value);
queryEntry.setRecord(record);
CachedQueryEntry<?, ?> newEntry = cachedEntry == null ? (CachedQueryEntry<?, ?>) queryEntry : cachedEntry.init(dataKey, value);
index.putEntry(newEntry, null, queryEntry, Index.OperationSource.USER);
}, false);
index.markPartitionAsIndexed(partitionId);
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class AddIndexBackupOperation method runInternal.
@Override
public void runInternal() {
int partitionId = getPartitionId();
Indexes indexes = mapContainer.getIndexes(partitionId);
indexes.recordIndexDefinition(config);
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class MapIndexLifecycleTest method assertAllPartitionContainersAreEmpty.
private void assertAllPartitionContainersAreEmpty(HazelcastInstance instance) {
MapServiceContext context = getMapServiceContext(instance);
int partitionCount = getPartitionCount(instance);
for (int i = 0; i < partitionCount; i++) {
PartitionContainer container = context.getPartitionContainer(i);
Map<String, ?> maps = container.getMaps().entrySet().stream().filter(e -> !e.getKey().startsWith(JobRepository.INTERNAL_JET_OBJECTS_PREFIX)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
assertTrue("record stores not empty", maps.isEmpty());
Map<String, Indexes> indexes = container.getIndexes().entrySet().stream().filter(e -> !e.getKey().startsWith(JobRepository.INTERNAL_JET_OBJECTS_PREFIX)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
assertTrue("indexes not empty", indexes.isEmpty());
}
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class MapIndexLifecycleTest method assertAllPartitionContainersAreInitialized.
private void assertAllPartitionContainersAreInitialized(HazelcastInstance instance) {
MapServiceContext context = getMapServiceContext(instance);
int partitionCount = getPartitionCount(instance);
final AtomicInteger authorRecordsCounter = new AtomicInteger();
final AtomicInteger yearRecordsCounter = new AtomicInteger();
String authorOwned = findAuthorOwnedBy(instance);
Integer yearOwned = findYearOwnedBy(instance);
for (int i = 0; i < partitionCount; i++) {
if (!getNode(instance).getPartitionService().isPartitionOwner(i)) {
continue;
}
PartitionContainer container = context.getPartitionContainer(i);
ConcurrentMap<String, RecordStore> maps = container.getMaps();
RecordStore recordStore = maps.get(mapName);
assertNotNull("record store is null: ", recordStore);
if (!globalIndex()) {
// also assert contents of partition indexes when NATIVE memory format
ConcurrentMap<String, Indexes> indexes = container.getIndexes();
final Indexes index = indexes.get(mapName);
assertNotNull("indexes is null", indexes);
assertEquals(2, index.getIndexes().length);
assertNotNull("There should be a partition index for attribute 'author'", index.getIndex("author"));
assertNotNull("There should be a partition index for attribute 'year'", index.getIndex("year"));
authorRecordsCounter.getAndAdd(numberOfPartitionQueryResults(instance, i, "author", authorOwned));
yearRecordsCounter.getAndAdd(numberOfPartitionQueryResults(instance, i, "year", yearOwned));
}
}
if (!globalIndex()) {
assertTrue("Author index should contain records", authorRecordsCounter.get() > 0);
assertTrue("Year index should contain records", yearRecordsCounter.get() > 0);
}
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class PagingPredicateOptimizationTest method testInnerPredicateOptimization.
@Test
public void testInnerPredicateOptimization() {
RuleBasedQueryOptimizer optimizer = new RuleBasedQueryOptimizer();
Indexes indexes = mock(Indexes.class);
Predicate[] orPredicates = new Predicate[10];
for (int i = 0; i < orPredicates.length; ++i) {
orPredicates[i] = Predicates.equal("a", i);
}
Predicate innerPredicate = Predicates.or(orPredicates);
PagingPredicate<Object, Object> pagingPredicate = Predicates.pagingPredicate(innerPredicate, 10);
Predicate optimized = optimizer.optimize(pagingPredicate, indexes);
assertInstanceOf(PagingPredicateImpl.class, optimized);
Predicate innerOptimized = ((PagingPredicateImpl) optimized).getPredicate();
assertInstanceOf(InPredicate.class, innerOptimized);
}
Aggregations