use of com.hazelcast.query.impl.InternalIndex in project hazelcast by hazelcast.
the class MetadataResolver method resolveFromHd.
@Nullable
@SuppressWarnings("rawtypes")
private Metadata resolveFromHd(MapContainer container) {
if (container.getIndexes() == null) {
return null;
}
InternalIndex[] indexes = container.getIndexes().getIndexes();
if (indexes == null || indexes.length == 0) {
return null;
}
InternalIndex index = indexes[0];
Iterator<QueryableEntry> entryIterator = index.getSqlRecordIterator(false);
if (!entryIterator.hasNext()) {
return null;
}
QueryableEntry entry = entryIterator.next();
return resolveMetadata(entry.getKey(), entry.getValue());
}
use of com.hazelcast.query.impl.InternalIndex in project hazelcast by hazelcast.
the class MapFetchIndexOperation method runInternal.
@Override
protected void runInternal() {
Indexes indexes = mapContainer.getIndexes();
if (indexes == null) {
throw QueryException.error(SqlErrorCode.INDEX_INVALID, "Cannot use the index \"" + indexName + "\" of the IMap \"" + name + "\" because it is not global " + "(make sure the property \"" + ClusterProperty.GLOBAL_HD_INDEX_ENABLED + "\" is set to \"true\")");
}
InternalIndex index = indexes.getIndex(indexName);
if (index == null) {
throw QueryException.error(SqlErrorCode.INDEX_INVALID, "Index \"" + indexName + "\" does not exist");
}
PartitionStamp indexStamp = index.getPartitionStamp();
if (indexStamp == null) {
throw new RetryableHazelcastException("Index is being rebuilt");
}
if (indexStamp.partitions.equals(partitionIdSet)) {
// We clear the requested partitionIdSet, which means that we won't filter out any partitions.
// This is an optimization for the case when there was no concurrent migration.
partitionIdSet = null;
} else {
if (!indexStamp.partitions.containsAll(partitionIdSet)) {
throw new MissingPartitionException("some requested partitions are not indexed");
}
}
switch(index.getConfig().getType()) {
case HASH:
response = runInternalHash(index);
break;
case SORTED:
response = runInternalSorted(index);
break;
case BITMAP:
throw new UnsupportedOperationException("BITMAP index scan is not implemented");
default:
throw new UnsupportedOperationException("Unknown index type: \"" + index.getConfig().getType().name() + "\"");
}
if (!index.validatePartitionStamp(indexStamp.stamp)) {
throw new MissingPartitionException("partition timestamp has changed");
}
}
use of com.hazelcast.query.impl.InternalIndex in project hazelcast by hazelcast.
the class MapTableUtils method getPartitionedMapIndexes.
public static List<MapTableIndex> getPartitionedMapIndexes(MapContainer mapContainer, List<TableField> fields) {
Map<QueryPath, Integer> pathToOrdinalMap = mapPathsToOrdinals(fields);
if (mapContainer.getIndexes() == null) {
return Collections.emptyList();
}
InternalIndex[] indexes = mapContainer.getIndexes().getIndexes();
if (indexes == null || indexes.length == 0) {
return Collections.emptyList();
}
List<MapTableIndex> res = new ArrayList<>(indexes.length);
for (Index index : indexes) {
IndexConfig indexConfig = index.getConfig();
List<QueryDataType> resolvedFieldConverterTypes = indexConverterToSqlTypes(index.getConverter());
List<String> indexAttributes = indexConfig.getAttributes();
List<Integer> indexFieldOrdinals = new ArrayList<>(indexAttributes.size());
List<QueryDataType> indexFieldConverterTypes = new ArrayList<>(indexAttributes.size());
String[] components = index.getComponents();
for (int i = 0; i < indexAttributes.size(); i++) {
String attribute = indexAttributes.get(i);
QueryPath attributePath = QueryPath.create(attribute);
Integer ordinal = pathToOrdinalMap.get(attributePath);
if (ordinal == null) {
// No mapping for the field. Stop.
break;
}
if (i >= resolvedFieldConverterTypes.size()) {
// No more resolved converters. Stop.
break;
}
QueryDataType fieldType = fields.get(ordinal).getType();
QueryDataType converterType = resolvedFieldConverterTypes.get(i);
if (!isCompatibleForIndexRequest(fieldType, converterType)) {
// Field and converter types are not compatible (e.g. INT vs VARCHAR).
break;
}
indexFieldOrdinals.add(ordinal);
indexFieldConverterTypes.add(converterType);
}
MapTableIndex index0 = new MapTableIndex(indexConfig.getName(), indexConfig.getType(), components.length, indexFieldOrdinals, indexFieldConverterTypes);
res.add(index0);
}
return res;
}
use of com.hazelcast.query.impl.InternalIndex in project hazelcast by hazelcast.
the class LocalMapStatsProvider method aggregateFreshIndexStats.
private static Map<String, OnDemandIndexStats> aggregateFreshIndexStats(InternalIndex[] freshIndexes, Map<String, OnDemandIndexStats> freshStats) {
if (freshIndexes.length > 0 && freshStats == null) {
freshStats = new HashMap<>();
}
for (InternalIndex index : freshIndexes) {
String indexName = index.getName();
OnDemandIndexStats freshIndexStats = freshStats.get(indexName);
if (freshIndexStats == null) {
freshIndexStats = new OnDemandIndexStats();
freshIndexStats.setCreationTime(Long.MAX_VALUE);
freshStats.put(indexName, freshIndexStats);
}
PerIndexStats indexStats = index.getPerIndexStats();
freshIndexStats.setCreationTime(Math.min(freshIndexStats.getCreationTime(), indexStats.getCreationTime()));
long hitCount = indexStats.getHitCount();
freshIndexStats.setHitCount(Math.max(freshIndexStats.getHitCount(), hitCount));
freshIndexStats.setQueryCount(Math.max(freshIndexStats.getQueryCount(), indexStats.getQueryCount()));
freshIndexStats.setMemoryCost(freshIndexStats.getMemoryCost() + indexStats.getMemoryCost());
freshIndexStats.setAverageHitSelectivity(freshIndexStats.getAverageHitSelectivity() + indexStats.getTotalNormalizedHitCardinality());
freshIndexStats.setAverageHitLatency(freshIndexStats.getAverageHitLatency() + indexStats.getTotalHitLatency());
freshIndexStats.setTotalHitCount(freshIndexStats.getTotalHitCount() + hitCount);
freshIndexStats.setInsertCount(freshIndexStats.getInsertCount() + indexStats.getInsertCount());
freshIndexStats.setTotalInsertLatency(freshIndexStats.getTotalInsertLatency() + indexStats.getTotalInsertLatency());
freshIndexStats.setUpdateCount(freshIndexStats.getUpdateCount() + indexStats.getUpdateCount());
freshIndexStats.setTotalUpdateLatency(freshIndexStats.getTotalUpdateLatency() + indexStats.getTotalUpdateLatency());
freshIndexStats.setRemoveCount(freshIndexStats.getRemoveCount() + indexStats.getRemoveCount());
freshIndexStats.setTotalRemoveLatency(freshIndexStats.getTotalRemoveLatency() + indexStats.getTotalRemoveLatency());
}
return freshStats;
}
use of com.hazelcast.query.impl.InternalIndex in project hazelcast by hazelcast.
the class MapMigrationAwareService method populateIndexes.
@SuppressWarnings("checkstyle:NPathComplexity")
private void populateIndexes(PartitionMigrationEvent event, TargetIndexes targetIndexes, String stepName) {
assert event.getMigrationEndpoint() == DESTINATION;
assert targetIndexes != null;
if (event.getNewReplicaIndex() != 0) {
// backup partitions have no indexes to populate
return;
}
PartitionContainer container = mapServiceContext.getPartitionContainer(event.getPartitionId());
for (RecordStore<Record> recordStore : container.getMaps().values()) {
MapContainer mapContainer = mapServiceContext.getMapContainer(recordStore.getName());
Indexes indexes = mapContainer.getIndexes(event.getPartitionId());
indexes.createIndexesFromRecordedDefinitions();
if (!indexes.haveAtLeastOneIndex()) {
// no indexes to work with
continue;
}
if (indexes.isGlobal() && targetIndexes == TargetIndexes.NON_GLOBAL) {
continue;
}
if (!indexes.isGlobal() && targetIndexes == TargetIndexes.GLOBAL) {
continue;
}
InternalIndex[] indexesSnapshot = indexes.getIndexes();
Indexes.beginPartitionUpdate(indexesSnapshot);
CacheDeserializedValues cacheDeserializedValues = mapContainer.getMapConfig().getCacheDeserializedValues();
CachedQueryEntry<?, ?> cachedEntry = cacheDeserializedValues == NEVER ? new CachedQueryEntry<>(serializationService, mapContainer.getExtractors()) : null;
recordStore.forEach((key, record) -> {
Object value = Records.getValueOrCachedValue(record, serializationService);
if (value != null) {
QueryableEntry queryEntry = mapContainer.newQueryEntry(key, value);
queryEntry.setRecord(record);
CachedQueryEntry<?, ?> newEntry = cachedEntry == null ? (CachedQueryEntry<?, ?>) queryEntry : cachedEntry.init(key, value);
indexes.putEntry(newEntry, null, queryEntry, Index.OperationSource.SYSTEM);
}
}, false);
Indexes.markPartitionAsIndexed(event.getPartitionId(), indexesSnapshot);
}
if (logger.isFinestEnabled()) {
logger.finest(String.format("Populated indexes at step `%s`:[%s]", stepName, event));
}
}
Aggregations