Search in sources :

Example 1 with CacheDeserializedValues

use of com.hazelcast.config.CacheDeserializedValues 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));
    }
}
Also used : InternalIndex(com.hazelcast.query.impl.InternalIndex) CacheDeserializedValues(com.hazelcast.config.CacheDeserializedValues) Record(com.hazelcast.map.impl.record.Record) Indexes(com.hazelcast.query.impl.Indexes) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 2 with CacheDeserializedValues

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

the class AddIndexOperation method runInternal.

@Override
public void runInternal() {
    int partitionId = getPartitionId();
    Indexes indexes = mapContainer.getIndexes(partitionId);
    InternalIndex index = indexes.addOrGetIndex(config);
    if (index.hasPartitionIndexed(partitionId)) {
        return;
    }
    SerializationService serializationService = getNodeEngine().getSerializationService();
    index.beginPartitionUpdate();
    CacheDeserializedValues cacheDeserializedValues = mapContainer.getMapConfig().getCacheDeserializedValues();
    CachedQueryEntry<?, ?> cachedEntry = cacheDeserializedValues == NEVER ? new CachedQueryEntry<>(serializationService, mapContainer.getExtractors()) : null;
    recordStore.forEach((dataKey, record) -> {
        Object value = Records.getValueOrCachedValue(record, serializationService);
        QueryableEntry<?, ?> queryEntry = mapContainer.newQueryEntry(dataKey, value);
        queryEntry.setRecord(record);
        CachedQueryEntry<?, ?> newEntry = cachedEntry == null ? (CachedQueryEntry<?, ?>) queryEntry : cachedEntry.init(dataKey, value);
        index.putEntry(newEntry, null, queryEntry, Index.OperationSource.USER);
    }, false);
    index.markPartitionAsIndexed(partitionId);
}
Also used : InternalIndex(com.hazelcast.query.impl.InternalIndex) CacheDeserializedValues(com.hazelcast.config.CacheDeserializedValues) SerializationService(com.hazelcast.internal.serialization.SerializationService) Indexes(com.hazelcast.query.impl.Indexes)

Example 3 with CacheDeserializedValues

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

the class DataRecordFactory method newRecord.

@Override
public Record<Data> newRecord(Data key, Object value) {
    MapConfig mapConfig = mapContainer.getMapConfig();
    boolean perEntryStatsEnabled = mapConfig.isPerEntryStatsEnabled();
    CacheDeserializedValues cacheDeserializedValues = mapConfig.getCacheDeserializedValues();
    boolean hasEviction = mapContainer.getEvictor() != NULL_EVICTOR;
    Data valueData = ss.toData(value);
    switch(cacheDeserializedValues) {
        case NEVER:
            return newSimpleRecord(valueData, mapConfig, perEntryStatsEnabled, hasEviction);
        default:
            return newCachedSimpleRecord(valueData, mapConfig, perEntryStatsEnabled, hasEviction);
    }
}
Also used : CacheDeserializedValues(com.hazelcast.config.CacheDeserializedValues) Data(com.hazelcast.internal.serialization.Data) MapConfig(com.hazelcast.config.MapConfig)

Aggregations

CacheDeserializedValues (com.hazelcast.config.CacheDeserializedValues)3 Indexes (com.hazelcast.query.impl.Indexes)2 InternalIndex (com.hazelcast.query.impl.InternalIndex)2 MapConfig (com.hazelcast.config.MapConfig)1 Data (com.hazelcast.internal.serialization.Data)1 SerializationService (com.hazelcast.internal.serialization.SerializationService)1 Record (com.hazelcast.map.impl.record.Record)1 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)1