Search in sources :

Example 26 with Indexes

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

the class AbstractRecordStore method removeIndex.

protected void removeIndex(Record record) {
    Indexes indexes = mapContainer.getIndexes();
    if (indexes.hasIndex()) {
        Data key = record.getKey();
        Object value = Records.getValueOrCachedValue(record, serializationService);
        if (NATIVE == inMemoryFormat) {
            key = (Data) copyToHeap(key);
            value = copyToHeap(value);
        }
        indexes.removeEntryIndex(key, value);
    }
}
Also used : Data(com.hazelcast.nio.serialization.Data) Indexes(com.hazelcast.query.impl.Indexes)

Example 27 with Indexes

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

the class PartitionWideEntryWithPredicateOperationFactory method getKeysFromIndex.

private Set<Data> getKeysFromIndex(NodeEngine nodeEngine) {
    // Do not use index in this case, because it requires full-table-scan.
    if (predicate == TruePredicate.INSTANCE) {
        return emptySet();
    }
    // get indexes
    MapService mapService = nodeEngine.getService(SERVICE_NAME);
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    Indexes indexes = mapServiceContext.getMapContainer(name).getIndexes();
    // optimize predicate
    QueryOptimizer queryOptimizer = mapServiceContext.getQueryOptimizer();
    predicate = queryOptimizer.optimize(predicate, indexes);
    Set<QueryableEntry> querySet = indexes.query(predicate);
    if (querySet == null) {
        return emptySet();
    }
    List<Data> keys = null;
    for (QueryableEntry e : querySet) {
        if (keys == null) {
            keys = new ArrayList<Data>(querySet.size());
        }
        keys.add(e.getKeyData());
    }
    return keys == null ? Collections.<Data>emptySet() : newBuilder(keys).build();
}
Also used : Data(com.hazelcast.nio.serialization.Data) QueryOptimizer(com.hazelcast.query.impl.predicates.QueryOptimizer) MapService(com.hazelcast.map.impl.MapService) Indexes(com.hazelcast.query.impl.Indexes) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 28 with Indexes

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

the class AddIndexOperation method run.

@Override
public void run() throws Exception {
    Indexes indexes = mapContainer.getIndexes();
    Index index = indexes.addOrGetIndex(attributeName, ordered);
    final long now = getNow();
    final Iterator<Record> iterator = recordStore.iterator(now, false);
    SerializationService serializationService = getNodeEngine().getSerializationService();
    while (iterator.hasNext()) {
        final Record record = iterator.next();
        Data key = record.getKey();
        Object value = Records.getValueOrCachedValue(record, serializationService);
        QueryableEntry queryEntry = mapContainer.newQueryEntry(key, value);
        index.saveEntryIndex(queryEntry, null);
    }
}
Also used : SerializationService(com.hazelcast.spi.serialization.SerializationService) Index(com.hazelcast.query.impl.Index) Record(com.hazelcast.map.impl.record.Record) Data(com.hazelcast.nio.serialization.Data) Indexes(com.hazelcast.query.impl.Indexes) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 29 with Indexes

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

the class MapMigrationAwareService method migrateIndex.

private void migrateIndex(PartitionMigrationEvent event) {
    final long now = getNow();
    final PartitionContainer container = mapServiceContext.getPartitionContainer(event.getPartitionId());
    for (RecordStore recordStore : container.getMaps().values()) {
        final MapContainer mapContainer = mapServiceContext.getMapContainer(recordStore.getName());
        final Indexes indexes = mapContainer.getIndexes();
        if (!indexes.hasIndex()) {
            continue;
        }
        final Iterator<Record> iterator = recordStore.iterator(now, false);
        while (iterator.hasNext()) {
            Record record = iterator.next();
            Data key = record.getKey();
            if (event.getMigrationEndpoint() == SOURCE) {
                assert event.getNewReplicaIndex() != 0 : "Invalid migration event: " + event;
                Object value = Records.getValueOrCachedValue(record, serializationService);
                indexes.removeEntryIndex(key, value);
            } else if (event.getNewReplicaIndex() == 0) {
                Object value = Records.getValueOrCachedValue(record, serializationService);
                if (value != null) {
                    QueryableEntry queryEntry = mapContainer.newQueryEntry(record.getKey(), value);
                    indexes.saveEntryIndex(queryEntry, null);
                }
            }
        }
    }
}
Also used : RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) Record(com.hazelcast.map.impl.record.Record) Data(com.hazelcast.nio.serialization.Data) Indexes(com.hazelcast.query.impl.Indexes) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 30 with Indexes

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

the class PartitionContainer method createRecordStore.

private RecordStore createRecordStore(String name) {
    MapServiceContext serviceContext = mapService.getMapServiceContext();
    MapContainer mapContainer = serviceContext.getMapContainer(name);
    MapConfig mapConfig = mapContainer.getMapConfig();
    NodeEngine nodeEngine = serviceContext.getNodeEngine();
    IPartitionService ps = nodeEngine.getPartitionService();
    OperationService opService = nodeEngine.getOperationService();
    ExecutionService execService = nodeEngine.getExecutionService();
    HazelcastProperties hazelcastProperties = nodeEngine.getProperties();
    MapKeyLoader keyLoader = new MapKeyLoader(name, opService, ps, nodeEngine.getClusterService(), execService, mapContainer.toData(), serviceContext.getNodeWideLoadedKeyLimiter());
    keyLoader.setMaxBatch(hazelcastProperties.getInteger(ClusterProperty.MAP_LOAD_CHUNK_SIZE));
    keyLoader.setMaxSize(getMaxSizePerNode(mapConfig.getEvictionConfig()));
    keyLoader.setHasBackup(mapConfig.getTotalBackupCount() > 0);
    keyLoader.setMapOperationProvider(serviceContext.getMapOperationProvider(name));
    if (!mapContainer.isGlobalIndexEnabled()) {
        Indexes indexesForMap = mapContainer.createIndexes(false);
        indexes.putIfAbsent(name, indexesForMap);
    }
    RecordStore recordStore = serviceContext.createRecordStore(mapContainer, partitionId, keyLoader);
    recordStore.init();
    return recordStore;
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) IPartitionService(com.hazelcast.internal.partition.IPartitionService) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapConfig(com.hazelcast.config.MapConfig) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) Indexes(com.hazelcast.query.impl.Indexes)

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