Search in sources :

Example 66 with Record

use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.

the class DefaultRecordStore method loadRecordOrNull.

@Override
public Record loadRecordOrNull(Data key, boolean backup) {
    Record record = null;
    final Object value = mapDataStore.load(key);
    if (value != null) {
        record = createRecord(value, DEFAULT_TTL, getNow());
        storage.put(key, record);
        if (!backup) {
            saveIndex(record, null);
        }
        evictEntries(key);
    }
    // otherwise query-caches cannot see loaded entries
    if (!backup && record != null && hasQueryCache()) {
        addEventToQueryCache(record);
    }
    return record;
}
Also used : Record(com.hazelcast.map.impl.record.Record)

Example 67 with Record

use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.

the class DefaultRecordStore method getAll.

@Override
public MapEntries getAll(Set<Data> keys) {
    checkIfLoaded();
    final long now = getNow();
    final MapEntries mapEntries = new MapEntries(keys.size());
    final Iterator<Data> iterator = keys.iterator();
    while (iterator.hasNext()) {
        final Data key = iterator.next();
        final Record record = getRecordOrNull(key, now, false);
        if (record != null) {
            addMapEntrySet(key, record.getValue(), mapEntries);
            accessRecord(record, now);
            iterator.remove();
        }
    }
    Map loadedEntries = loadEntries(keys);
    addMapEntrySet(loadedEntries, mapEntries);
    return mapEntries;
}
Also used : MapEntries(com.hazelcast.map.impl.MapEntries) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) Data(com.hazelcast.nio.serialization.Data) Record(com.hazelcast.map.impl.record.Record) MapUtil.createHashMap(com.hazelcast.util.MapUtil.createHashMap) Map(java.util.Map)

Example 68 with Record

use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.

the class DefaultRecordStore method putInternal.

protected Object putInternal(Data key, Object value, long ttl, boolean loadFromStore) {
    checkIfLoaded();
    long now = getNow();
    markRecordStoreExpirable(ttl);
    Record record = getRecordOrNull(key, now, false);
    Object oldValue = record == null ? (loadFromStore ? mapDataStore.load(key) : null) : record.getValue();
    value = mapServiceContext.interceptPut(name, oldValue, value);
    value = mapDataStore.add(key, value, now);
    onStore(record);
    if (record == null) {
        record = createRecord(value, ttl, now);
        storage.put(key, record);
    } else {
        updateRecord(key, record, value, now);
        updateExpiryTime(record, ttl, mapContainer.getMapConfig());
    }
    saveIndex(record, oldValue);
    return oldValue;
}
Also used : Record(com.hazelcast.map.impl.record.Record)

Example 69 with Record

use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.

the class DefaultRecordStore method merge.

@Override
public boolean merge(Data key, EntryView mergingEntry, MapMergePolicy mergePolicy) {
    checkIfLoaded();
    final long now = getNow();
    Record record = getRecordOrNull(key, now, false);
    mergingEntry = EntryViews.convertToLazyEntryView(mergingEntry, serializationService, mergePolicy);
    Object newValue;
    Object oldValue = null;
    if (record == null) {
        final Object notExistingKey = mapServiceContext.toObject(key);
        final EntryView nullEntryView = EntryViews.createNullEntryView(notExistingKey);
        newValue = mergePolicy.merge(name, mergingEntry, nullEntryView);
        if (newValue == null) {
            return false;
        }
        newValue = mapDataStore.add(key, newValue, now);
        record = createRecord(newValue, DEFAULT_TTL, now);
        mergeRecordExpiration(record, mergingEntry);
        storage.put(key, record);
    } else {
        oldValue = record.getValue();
        EntryView existingEntry = EntryViews.createLazyEntryView(record.getKey(), record.getValue(), record, serializationService, mergePolicy);
        newValue = mergePolicy.merge(name, mergingEntry, existingEntry);
        // existing entry will be removed
        if (newValue == null) {
            removeIndex(record);
            mapDataStore.remove(key, now);
            onStore(record);
            storage.removeRecord(record);
            updateStatsOnRemove(record.getHits());
            return true;
        }
        if (newValue == mergingEntry.getValue()) {
            mergeRecordExpiration(record, mergingEntry);
        }
        // same with the existing entry so no need to map-store etc operations.
        if (recordFactory.isEquals(newValue, oldValue)) {
            return true;
        }
        newValue = mapDataStore.add(key, newValue, now);
        onStore(record);
        storage.updateRecordValue(key, record, newValue);
    }
    saveIndex(record, oldValue);
    return newValue != null;
}
Also used : EntryView(com.hazelcast.core.EntryView) Record(com.hazelcast.map.impl.record.Record)

Example 70 with Record

use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.

the class DefaultRecordStore method remove.

@Override
public Object remove(Data key) {
    checkIfLoaded();
    final long now = getNow();
    final Record record = getRecordOrNull(key, now, false);
    Object oldValue;
    if (record == null) {
        oldValue = mapDataStore.load(key);
        if (oldValue != null) {
            mapDataStore.remove(key, now);
        }
    } else {
        oldValue = removeRecord(key, record, now);
    }
    return oldValue;
}
Also used : Record(com.hazelcast.map.impl.record.Record)

Aggregations

Record (com.hazelcast.map.impl.record.Record)109 Data (com.hazelcast.internal.serialization.Data)27 Data (com.hazelcast.nio.serialization.Data)22 Map (java.util.Map)13 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)11 ExpiryMetadata (com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata)11 EntryView (com.hazelcast.core.EntryView)8 Indexes (com.hazelcast.query.impl.Indexes)8 ArrayList (java.util.ArrayList)7 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)6 MapContainer (com.hazelcast.map.impl.MapContainer)6 DelayedEntry (com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)6 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)6 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)6 EntryViews.createSimpleEntryView (com.hazelcast.map.impl.EntryViews.createSimpleEntryView)5 MapService (com.hazelcast.map.impl.MapService)5 List (java.util.List)5 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)4 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)3 MapEntries (com.hazelcast.map.impl.MapEntries)3