Search in sources :

Example 21 with Indexes

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

the class MapIndexJsonTest method getIndexOfAttributeForMap.

protected static List<Index> getIndexOfAttributeForMap(HazelcastInstance instance, String mapName, String attribute) {
    Node node = getNode(instance);
    MapService service = node.nodeEngine.getService(MapService.SERVICE_NAME);
    MapServiceContext mapServiceContext = service.getMapServiceContext();
    MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
    List<Index> result = new ArrayList<>();
    for (int partitionId : mapServiceContext.getOrInitCachedMemberPartitions()) {
        Indexes indexes = mapContainer.getIndexes(partitionId);
        result.add(indexes.getIndex(attribute));
    }
    return result;
}
Also used : Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) ArrayList(java.util.ArrayList) Index(com.hazelcast.query.impl.Index) MapService(com.hazelcast.map.impl.MapService) Indexes(com.hazelcast.query.impl.Indexes) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 22 with Indexes

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

the class IndexStatsChangingNumberOfMembersTest method calculateOverallSelectivity.

protected double calculateOverallSelectivity(long initialHits, double initialTotalSelectivityCount, IMap<?, ?>... maps) {
    List<Indexes> allIndexes = new ArrayList<>();
    for (IMap<?, ?> map : maps) {
        allIndexes.addAll(getAllIndexes(map));
    }
    long totalHitCount = 0;
    double totalNormalizedHitCardinality = 0.0;
    for (Indexes indexes : allIndexes) {
        PerIndexStats perIndexStats = indexes.getIndex("this").getPerIndexStats();
        totalHitCount += perIndexStats.getHitCount();
        totalNormalizedHitCardinality += perIndexStats.getTotalNormalizedHitCardinality();
    }
    double averageHitSelectivity = totalHitCount == 0 ? 0.0 : 1.0 - totalNormalizedHitCardinality / totalHitCount;
    if (totalHitCount + initialHits == 0) {
        return 0.0;
    } else {
        return (averageHitSelectivity * totalHitCount + initialTotalSelectivityCount) / (totalHitCount + initialHits);
    }
}
Also used : ArrayList(java.util.ArrayList) PerIndexStats(com.hazelcast.internal.monitor.impl.PerIndexStats) Indexes(com.hazelcast.query.impl.Indexes) Accessors.getAllIndexes(com.hazelcast.test.Accessors.getAllIndexes)

Example 23 with Indexes

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

the class ClientBitmapIndexTest method before.

@Before
public void before() {
    HazelcastInstance member = factory.newHazelcastInstance(getConfig());
    personsOnMember = member.getMap("persons");
    HazelcastInstance client = factory.newHazelcastClient();
    persons = client.getMap("persons");
    // add the index dynamically to verify client protocol support
    persons.addIndex(indexConfig);
    List<Indexes> allIndexes = getAllIndexes(personsOnMember);
    assertEquals(1, allIndexes.size());
    InternalIndex[] indexes = allIndexes.get(0).getIndexes();
    assertEquals(1, indexes.length);
    assertEquals(IndexUtils.validateAndNormalize("persons", indexConfig), indexes[0].getConfig());
}
Also used : InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Indexes(com.hazelcast.query.impl.Indexes) Accessors.getAllIndexes(com.hazelcast.test.Accessors.getAllIndexes) Before(org.junit.Before)

Example 24 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 25 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)

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