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());
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class DefaultRecordStore method clearPartition.
@Override
public void clearPartition(boolean onShutdown) {
NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
LockService lockService = nodeEngine.getSharedService(LockService.SERVICE_NAME);
if (lockService != null) {
final DefaultObjectNamespace namespace = new DefaultObjectNamespace(MapService.SERVICE_NAME, name);
lockService.clearLockStore(partitionId, namespace);
}
Indexes indexes = mapContainer.getIndexes();
if (indexes.hasIndex()) {
for (Record record : storage.values()) {
Data key = record.getKey();
Object value = Records.getValueOrCachedValue(record, serializationService);
indexes.removeEntryIndex(key, value);
}
}
mapDataStore.reset();
if (onShutdown) {
NativeMemoryConfig nativeMemoryConfig = nodeEngine.getConfig().getNativeMemoryConfig();
boolean shouldClear = (nativeMemoryConfig != null && nativeMemoryConfig.getAllocatorType() != POOLED);
if (shouldClear) {
storage.clear(true);
}
storage.destroy(true);
} else {
storage.clear(false);
}
}
use of com.hazelcast.query.impl.Indexes in project hazelcast by hazelcast.
the class AbstractRecordStore method saveIndex.
protected void saveIndex(Record record, Object oldValue) {
Data dataKey = record.getKey();
final Indexes indexes = mapContainer.getIndexes();
if (indexes.hasIndex()) {
Object value = Records.getValueOrCachedValue(record, serializationService);
// When using format InMemoryFormat.NATIVE, just copy key & value to heap.
if (NATIVE == inMemoryFormat) {
dataKey = (Data) copyToHeap(dataKey);
value = copyToHeap(value);
oldValue = copyToHeap(oldValue);
}
QueryableEntry queryableEntry = mapContainer.newQueryEntry(dataKey, value);
indexes.saveEntryIndex(queryableEntry, oldValue);
}
}
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();
}
Aggregations