Search in sources :

Example 6 with Indexes

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

the class RecordStoreTest method testRecordStoreResetWithClearingIndexes.

@Test
public void testRecordStoreResetWithClearingIndexes() {
    IMap<Object, Object> map = testRecordStoreReset();
    Indexes indexes = getIndexService(map);
    indexes.clearIndexes();
    Collection<Object> values = map.values(Predicates.equal("name", "tom"));
    assertTrue(values.isEmpty());
}
Also used : Indexes(com.hazelcast.query.impl.Indexes) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with Indexes

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

the class DefaultRecordStore method clearPartition.

@Override
public void clearPartition(boolean onShutdown) {
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    LockService lockService = nodeEngine.getSharedService(LockService.SERVICE_NAME);
    if (lockService != null) {
        final DefaultObjectNamespace namespace = new DefaultObjectNamespace(MapService.SERVICE_NAME, name);
        lockService.clearLockStore(partitionId, namespace);
    }
    Indexes indexes = mapContainer.getIndexes();
    if (indexes.hasIndex()) {
        for (Record record : storage.values()) {
            Data key = record.getKey();
            Object value = Records.getValueOrCachedValue(record, serializationService);
            indexes.removeEntryIndex(key, value);
        }
    }
    mapDataStore.reset();
    if (onShutdown) {
        NativeMemoryConfig nativeMemoryConfig = nodeEngine.getConfig().getNativeMemoryConfig();
        boolean shouldClear = (nativeMemoryConfig != null && nativeMemoryConfig.getAllocatorType() != POOLED);
        if (shouldClear) {
            storage.clear(true);
        }
        storage.destroy(true);
    } else {
        storage.clear(false);
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) NativeMemoryConfig(com.hazelcast.config.NativeMemoryConfig) DefaultObjectNamespace(com.hazelcast.spi.DefaultObjectNamespace) LockService(com.hazelcast.concurrent.lock.LockService) Record(com.hazelcast.map.impl.record.Record) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) Data(com.hazelcast.nio.serialization.Data) Indexes(com.hazelcast.query.impl.Indexes)

Example 8 with Indexes

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

the class AbstractRecordStore method saveIndex.

protected void saveIndex(Record record, Object oldValue) {
    Data dataKey = record.getKey();
    final Indexes indexes = mapContainer.getIndexes();
    if (indexes.hasIndex()) {
        Object value = Records.getValueOrCachedValue(record, serializationService);
        // When using format InMemoryFormat.NATIVE, just copy key & value to heap.
        if (NATIVE == inMemoryFormat) {
            dataKey = (Data) copyToHeap(dataKey);
            value = copyToHeap(value);
            oldValue = copyToHeap(oldValue);
        }
        QueryableEntry queryableEntry = mapContainer.newQueryEntry(dataKey, value);
        indexes.saveEntryIndex(queryableEntry, oldValue);
    }
}
Also used : Data(com.hazelcast.nio.serialization.Data) Indexes(com.hazelcast.query.impl.Indexes) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 9 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 10 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)

Aggregations

Indexes (com.hazelcast.query.impl.Indexes)17 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 Data (com.hazelcast.nio.serialization.Data)6 Predicate (com.hazelcast.query.Predicate)5 PredicateTestUtils.createPassthroughVisitor (com.hazelcast.query.impl.predicates.PredicateTestUtils.createPassthroughVisitor)5 Record (com.hazelcast.map.impl.record.Record)4 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)4 PredicateTestUtils.createDelegatingVisitor (com.hazelcast.query.impl.predicates.PredicateTestUtils.createDelegatingVisitor)3 PredicateTestUtils.createMockVisitablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate)3 MapService (com.hazelcast.map.impl.MapService)2 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)2 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)2 Index (com.hazelcast.query.impl.Index)2 PredicateTestUtils.createMockNegatablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockNegatablePredicate)2 HashMap (java.util.HashMap)2 LockService (com.hazelcast.concurrent.lock.LockService)1 NativeMemoryConfig (com.hazelcast.config.NativeMemoryConfig)1 MapInterceptor (com.hazelcast.map.MapInterceptor)1