Search in sources :

Example 41 with Indexes

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);
}
Also used : InternalIndex(com.hazelcast.query.impl.InternalIndex) CacheDeserializedValues(com.hazelcast.config.CacheDeserializedValues) SerializationService(com.hazelcast.internal.serialization.SerializationService) Indexes(com.hazelcast.query.impl.Indexes)

Example 42 with Indexes

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);
}
Also used : Indexes(com.hazelcast.query.impl.Indexes)

Example 43 with Indexes

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());
    }
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Query(com.hazelcast.map.impl.query.Query) Indexes(com.hazelcast.query.impl.Indexes) Accessors.getOperationService(com.hazelcast.test.Accessors.getOperationService) Member(com.hazelcast.cluster.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) ConcurrentMap(java.util.concurrent.ConcurrentMap) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) IndexType(com.hazelcast.config.IndexType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Operation(com.hazelcast.spi.impl.operationservice.Operation) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) Map(java.util.Map) Accessors.getNode(com.hazelcast.test.Accessors.getNode) ConfigAccessor(com.hazelcast.config.ConfigAccessor) JobRepository(com.hazelcast.jet.impl.JobRepository) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) QueryResult(com.hazelcast.map.impl.query.QueryResult) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) MapContainer(com.hazelcast.map.impl.MapContainer) Assert.assertNotNull(org.junit.Assert.assertNotNull) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ServiceConfig(com.hazelcast.config.ServiceConfig) MapService(com.hazelcast.map.impl.MapService) Category(org.junit.experimental.categories.Category) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) Collectors(java.util.stream.Collectors) Node(com.hazelcast.instance.impl.Node) IndexConfig(com.hazelcast.config.IndexConfig) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) Serializable(java.io.Serializable) PostJoinAwareService(com.hazelcast.internal.services.PostJoinAwareService) Predicates(com.hazelcast.query.Predicates) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) CoreService(com.hazelcast.internal.services.CoreService) IterationType(com.hazelcast.internal.util.IterationType) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Arrays.copyOfRange(java.util.Arrays.copyOfRange) Assert.assertEquals(org.junit.Assert.assertEquals) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) Indexes(com.hazelcast.query.impl.Indexes) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 44 with Indexes

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);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) Indexes(com.hazelcast.query.impl.Indexes) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 45 with Indexes

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);
}
Also used : RuleBasedQueryOptimizer(com.hazelcast.query.impl.predicates.RuleBasedQueryOptimizer) Indexes(com.hazelcast.query.impl.Indexes) InPredicate(com.hazelcast.query.impl.predicates.InPredicate) PagingPredicate(com.hazelcast.query.PagingPredicate) Predicate(com.hazelcast.query.Predicate) PagingPredicateImpl(com.hazelcast.query.impl.predicates.PagingPredicateImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Indexes (com.hazelcast.query.impl.Indexes)56 MapContainer (com.hazelcast.map.impl.MapContainer)15 QuickTest (com.hazelcast.test.annotation.QuickTest)14 Test (org.junit.Test)14 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)13 Predicate (com.hazelcast.query.Predicate)11 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)11 InternalIndex (com.hazelcast.query.impl.InternalIndex)10 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)9 IndexConfig (com.hazelcast.config.IndexConfig)8 Record (com.hazelcast.map.impl.record.Record)8 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)7 MapService (com.hazelcast.map.impl.MapService)6 Data (com.hazelcast.nio.serialization.Data)6 ArrayList (java.util.ArrayList)6 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)5 PredicateTestUtils.createPassthroughVisitor (com.hazelcast.query.impl.predicates.PredicateTestUtils.createPassthroughVisitor)5 Index (com.hazelcast.query.impl.Index)4 Map (java.util.Map)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3