use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class AbstractRecordStore method removeIndex.
protected void removeIndex(Record record) {
Indexes indexes = mapContainer.getIndexes();
if (indexes.hasIndex()) {
Data key = record.getKey();
Object value = Records.getValueOrCachedValue(record, serializationService);
if (NATIVE == inMemoryFormat) {
key = (Data) copyToHeap(key);
value = copyToHeap(value);
}
indexes.removeEntryIndex(key, value);
}
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class PartitionWideEntryWithPredicateOperationFactory method getKeysFromIndex.
private Set<Data> getKeysFromIndex(NodeEngine nodeEngine) {
// Do not use index in this case, because it requires full-table-scan.
if (predicate == TruePredicate.INSTANCE) {
return emptySet();
}
// get indexes
MapService mapService = nodeEngine.getService(SERVICE_NAME);
MapServiceContext mapServiceContext = mapService.getMapServiceContext();
Indexes indexes = mapServiceContext.getMapContainer(name).getIndexes();
// optimize predicate
QueryOptimizer queryOptimizer = mapServiceContext.getQueryOptimizer();
predicate = queryOptimizer.optimize(predicate, indexes);
Set<QueryableEntry> querySet = indexes.query(predicate);
if (querySet == null) {
return emptySet();
}
List<Data> keys = null;
for (QueryableEntry e : querySet) {
if (keys == null) {
keys = new ArrayList<Data>(querySet.size());
}
keys.add(e.getKeyData());
}
return keys == null ? Collections.<Data>emptySet() : newBuilder(keys).build();
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class AddIndexOperation method run.
@Override
public void run() throws Exception {
Indexes indexes = mapContainer.getIndexes();
Index index = indexes.addOrGetIndex(attributeName, ordered);
final long now = getNow();
final Iterator<Record> iterator = recordStore.iterator(now, false);
SerializationService serializationService = getNodeEngine().getSerializationService();
while (iterator.hasNext()) {
final Record record = iterator.next();
Data key = record.getKey();
Object value = Records.getValueOrCachedValue(record, serializationService);
QueryableEntry queryEntry = mapContainer.newQueryEntry(key, value);
index.saveEntryIndex(queryEntry, null);
}
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class MapMigrationAwareService method migrateIndex.
private void migrateIndex(PartitionMigrationEvent event) {
final long now = getNow();
final PartitionContainer container = mapServiceContext.getPartitionContainer(event.getPartitionId());
for (RecordStore recordStore : container.getMaps().values()) {
final MapContainer mapContainer = mapServiceContext.getMapContainer(recordStore.getName());
final Indexes indexes = mapContainer.getIndexes();
if (!indexes.hasIndex()) {
continue;
}
final Iterator<Record> iterator = recordStore.iterator(now, false);
while (iterator.hasNext()) {
Record record = iterator.next();
Data key = record.getKey();
if (event.getMigrationEndpoint() == SOURCE) {
assert event.getNewReplicaIndex() != 0 : "Invalid migration event: " + event;
Object value = Records.getValueOrCachedValue(record, serializationService);
indexes.removeEntryIndex(key, value);
} else if (event.getNewReplicaIndex() == 0) {
Object value = Records.getValueOrCachedValue(record, serializationService);
if (value != null) {
QueryableEntry queryEntry = mapContainer.newQueryEntry(record.getKey(), value);
indexes.saveEntryIndex(queryEntry, null);
}
}
}
}
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class PartitionContainer method createRecordStore.
private RecordStore createRecordStore(String name) {
MapServiceContext serviceContext = mapService.getMapServiceContext();
MapContainer mapContainer = serviceContext.getMapContainer(name);
MapConfig mapConfig = mapContainer.getMapConfig();
NodeEngine nodeEngine = serviceContext.getNodeEngine();
IPartitionService ps = nodeEngine.getPartitionService();
OperationService opService = nodeEngine.getOperationService();
ExecutionService execService = nodeEngine.getExecutionService();
HazelcastProperties hazelcastProperties = nodeEngine.getProperties();
MapKeyLoader keyLoader = new MapKeyLoader(name, opService, ps, nodeEngine.getClusterService(), execService, mapContainer.toData(), serviceContext.getNodeWideLoadedKeyLimiter());
keyLoader.setMaxBatch(hazelcastProperties.getInteger(ClusterProperty.MAP_LOAD_CHUNK_SIZE));
keyLoader.setMaxSize(getMaxSizePerNode(mapConfig.getEvictionConfig()));
keyLoader.setHasBackup(mapConfig.getTotalBackupCount() > 0);
keyLoader.setMapOperationProvider(serviceContext.getMapOperationProvider(name));
if (!mapContainer.isGlobalIndexEnabled()) {
Indexes indexesForMap = mapContainer.createIndexes(false);
indexes.putIfAbsent(name, indexesForMap);
}
RecordStore recordStore = serviceContext.createRecordStore(mapContainer, partitionId, keyLoader);
recordStore.init();
return recordStore;
}
Aggregations