Search in sources :

Example 6 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class MapReplicationStateHolder method addIndexes.

private void addIndexes(String mapName, Collection<IndexConfig> indexConfigs) {
    if (indexConfigs == null) {
        return;
    }
    RecordStore recordStore = operation.getRecordStore(mapName);
    MapContainer mapContainer = recordStore.getMapContainer();
    if (mapContainer.isGlobalIndexEnabled()) {
        // creating global indexes on partition thread in case they do not exist
        for (IndexConfig indexConfig : indexConfigs) {
            Indexes indexes = mapContainer.getIndexes();
            // optimisation not to synchronize each partition thread on the addOrGetIndex method
            if (indexes.getIndex(indexConfig.getName()) == null) {
                indexes.addOrGetIndex(indexConfig);
            }
        }
    } else {
        Indexes indexes = mapContainer.getIndexes(operation.getPartitionId());
        indexes.createIndexesFromRecordedDefinitions();
        for (IndexConfig indexConfig : indexConfigs) {
            indexes.addOrGetIndex(indexConfig);
        }
    }
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) Indexes(com.hazelcast.query.impl.Indexes) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 7 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class MapChunkContext method createMapIndexInfo.

public final MapIndexInfo createMapIndexInfo() {
    MapContainer mapContainer = recordStore.getMapContainer();
    Set<IndexConfig> indexConfigs = new HashSet<>();
    if (mapContainer.isGlobalIndexEnabled()) {
        // global-index
        final Indexes indexes = mapContainer.getIndexes();
        for (Index index : indexes.getIndexes()) {
            indexConfigs.add(index.getConfig());
        }
        indexConfigs.addAll(indexes.getIndexDefinitions());
    } else {
        // partitioned-index
        final Indexes indexes = mapContainer.getIndexes(partitionId);
        if (indexes != null && indexes.haveAtLeastOneIndexOrDefinition()) {
            for (Index index : indexes.getIndexes()) {
                indexConfigs.add(index.getConfig());
            }
            indexConfigs.addAll(indexes.getIndexDefinitions());
        }
    }
    return new MapIndexInfo(mapName).addIndexCofigs(indexConfigs);
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) MapIndexInfo(com.hazelcast.query.impl.MapIndexInfo) Index(com.hazelcast.query.impl.Index) Indexes(com.hazelcast.query.impl.Indexes) MapContainer(com.hazelcast.map.impl.MapContainer) HashSet(java.util.HashSet)

Example 8 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class MapChunk method addIndexes.

private void addIndexes(RecordStore recordStore, Collection<IndexConfig> indexConfigs) {
    if (indexConfigs == null) {
        return;
    }
    MapContainer mapContainer = recordStore.getMapContainer();
    if (mapContainer.isGlobalIndexEnabled()) {
        // creating global indexes on partition thread in case they do not exist
        for (IndexConfig indexConfig : indexConfigs) {
            Indexes indexes = mapContainer.getIndexes();
            // optimisation not to synchronize each partition thread on the addOrGetIndex method
            if (indexes.getIndex(indexConfig.getName()) == null) {
                indexes.addOrGetIndex(indexConfig);
            }
        }
    } else {
        Indexes indexes = mapContainer.getIndexes(getPartitionId());
        indexes.createIndexesFromRecordedDefinitions();
        for (IndexConfig indexConfig : indexConfigs) {
            indexes.addOrGetIndex(indexConfig);
        }
    }
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) Indexes(com.hazelcast.query.impl.Indexes) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 9 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class DefaultQueryCache method addIndex.

@Override
public void addIndex(IndexConfig config) {
    checkNotNull(config, "Index config cannot be null.");
    assert indexes.isGlobal();
    IndexConfig config0 = getNormalizedIndexConfig(config);
    indexes.addOrGetIndex(config0);
    InternalSerializationService serializationService = context.getSerializationService();
    CachedQueryEntry<?, ?> newEntry = new CachedQueryEntry<>(serializationService, extractors);
    Set<Map.Entry<Object, QueryCacheRecord>> entries = recordStore.entrySet();
    for (Map.Entry<Object, QueryCacheRecord> entry : entries) {
        Object queryCacheKey = entry.getKey();
        QueryCacheRecord record = entry.getValue();
        Object value = record.getValue();
        Data keyData = toData(queryCacheKey);
        QueryEntry queryable = new QueryEntry(serializationService, keyData, value, extractors);
        newEntry.init(keyData, value);
        indexes.putEntry(newEntry, null, queryable, Index.OperationSource.USER);
    }
}
Also used : CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryEntry(com.hazelcast.query.impl.QueryEntry) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryEntry(com.hazelcast.query.impl.QueryEntry) IndexConfig(com.hazelcast.config.IndexConfig) QueryCacheRecord(com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap)

Example 10 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class IndexUtils method validateAndNormalize.

/**
 * Validate provided index config and normalize it's name and attribute names.
 *
 * @param mapName Name of the map
 * @param config Index config.
 * @return Normalized index config.
 * @throws IllegalArgumentException If index configuration is invalid.
 */
@SuppressWarnings("checkstyle:npathcomplexity")
public static IndexConfig validateAndNormalize(String mapName, IndexConfig config) {
    assert config != null;
    // Validate attributes.
    List<String> originalAttributeNames = config.getAttributes();
    if (originalAttributeNames.isEmpty()) {
        throw new IllegalArgumentException("Index must have at least one attribute: " + config);
    }
    if (originalAttributeNames.size() > MAX_ATTRIBUTES) {
        throw new IllegalArgumentException("Index cannot have more than " + MAX_ATTRIBUTES + " attributes: " + config);
    }
    if (config.getType() == IndexType.BITMAP && originalAttributeNames.size() > 1) {
        throw new IllegalArgumentException("Composite bitmap indexes are not supported: " + config);
    }
    List<String> normalizedAttributeNames = new ArrayList<>(originalAttributeNames.size());
    for (String originalAttributeName : originalAttributeNames) {
        validateAttribute(config, originalAttributeName);
        originalAttributeName = originalAttributeName.trim();
        String normalizedAttributeName = canonicalizeAttribute(originalAttributeName);
        assert !normalizedAttributeName.isEmpty();
        int existingIdx = normalizedAttributeNames.indexOf(normalizedAttributeName);
        if (existingIdx != -1) {
            String duplicateOriginalAttributeName = originalAttributeNames.get(existingIdx);
            if (duplicateOriginalAttributeName.equals(originalAttributeName)) {
                throw new IllegalArgumentException("Duplicate attribute name [attributeName=" + originalAttributeName + ", indexConfig=" + config + ']');
            } else {
                throw new IllegalArgumentException("Duplicate attribute names [" + "attributeName1=" + duplicateOriginalAttributeName + ", attributeName2=" + originalAttributeName + ", indexConfig=" + config + ']');
            }
        }
        normalizedAttributeNames.add(normalizedAttributeName);
    }
    // Construct final index.
    String name = config.getName();
    if (name != null && name.trim().isEmpty()) {
        name = null;
    }
    IndexConfig normalizedConfig = buildNormalizedConfig(mapName, config.getType(), name, normalizedAttributeNames);
    if (config.getType() == IndexType.BITMAP) {
        String uniqueKey = config.getBitmapIndexOptions().getUniqueKey();
        UniqueKeyTransformation uniqueKeyTransformation = config.getBitmapIndexOptions().getUniqueKeyTransformation();
        validateAttribute(uniqueKey);
        uniqueKey = canonicalizeAttribute(uniqueKey);
        normalizedConfig.getBitmapIndexOptions().setUniqueKey(uniqueKey).setUniqueKeyTransformation(uniqueKeyTransformation);
    }
    return normalizedConfig;
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) ArrayList(java.util.ArrayList) UniqueKeyTransformation(com.hazelcast.config.BitmapIndexOptions.UniqueKeyTransformation)

Aggregations

IndexConfig (com.hazelcast.config.IndexConfig)130 Test (org.junit.Test)49 QuickTest (com.hazelcast.test.annotation.QuickTest)45 Config (com.hazelcast.config.Config)42 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)38 MapConfig (com.hazelcast.config.MapConfig)34 HazelcastInstance (com.hazelcast.core.HazelcastInstance)29 ArrayList (java.util.ArrayList)16 Before (org.junit.Before)13 MapStoreConfig (com.hazelcast.config.MapStoreConfig)12 InternalIndex (com.hazelcast.query.impl.InternalIndex)12 AttributeConfig (com.hazelcast.config.AttributeConfig)9 MapContainer (com.hazelcast.map.impl.MapContainer)9 IndexRangeFilter (com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter)9 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)8 Node (org.w3c.dom.Node)8 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)7 IMap (com.hazelcast.map.IMap)7 Indexes (com.hazelcast.query.impl.Indexes)7 ExpressionEvalContext (com.hazelcast.sql.impl.expression.ExpressionEvalContext)7