Search in sources :

Example 1 with Indexes

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

the class MapSplitBrainHandlerService method prepareMergeRunnable.

@Override
public Runnable prepareMergeRunnable() {
    final long now = getNow();
    final Map<String, MapContainer> mapContainers = getMapContainers();
    final Map<MapContainer, Collection<Record>> recordMap = new HashMap<MapContainer, Collection<Record>>(mapContainers.size());
    final IPartitionService partitionService = nodeEngine.getPartitionService();
    final int partitionCount = partitionService.getPartitionCount();
    final Address thisAddress = nodeEngine.getClusterService().getThisAddress();
    for (MapContainer mapContainer : mapContainers.values()) {
        for (int i = 0; i < partitionCount; i++) {
            RecordStore recordStore = mapServiceContext.getPartitionContainer(i).getRecordStore(mapContainer.getName());
            // add your owned entries to the map so they will be merged
            if (thisAddress.equals(partitionService.getPartitionOwner(i))) {
                Collection<Record> records = recordMap.get(mapContainer);
                if (records == null) {
                    records = new ArrayList<Record>();
                    recordMap.put(mapContainer, records);
                }
                final Iterator<Record> iterator = recordStore.iterator(now, false);
                while (iterator.hasNext()) {
                    final Record record = iterator.next();
                    records.add(record);
                }
            }
            // clear all records either owned or backup
            recordStore.reset();
        }
        Indexes indexes = mapContainer.getIndexes();
        indexes.clearIndexes();
    }
    return new Merger(recordMap);
}
Also used : Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) IPartitionService(com.hazelcast.spi.partition.IPartitionService) Indexes(com.hazelcast.query.impl.Indexes) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) Collection(java.util.Collection) Record(com.hazelcast.map.impl.record.Record)

Example 2 with Indexes

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

the class PostJoinMapOperation method addMapIndex.

public void addMapIndex(MapContainer mapContainer) {
    final Indexes indexes = mapContainer.getIndexes();
    if (indexes.hasIndex()) {
        MapIndexInfo mapIndexInfo = new MapIndexInfo(mapContainer.getName());
        for (Index index : indexes.getIndexes()) {
            mapIndexInfo.addIndexInfo(index.getAttributeName(), index.isOrdered());
        }
        indexInfoList.add(mapIndexInfo);
    }
}
Also used : Index(com.hazelcast.query.impl.Index) Indexes(com.hazelcast.query.impl.Indexes)

Example 3 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 4 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 5 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)

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