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);
}
}
}
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);
}
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);
}
}
}
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);
}
}
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;
}
Aggregations