Search in sources :

Example 41 with Record

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

the class SetTtlBackupOperation method afterRunInternal.

@Override
protected void afterRunInternal() {
    Record record = recordStore.getRecord(dataKey);
    if (record != null) {
        publishWanUpdate(dataKey, record.getValue());
    }
    super.afterRunInternal();
}
Also used : Record(com.hazelcast.map.impl.record.Record)

Example 42 with Record

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

the class DefaultRecordStore method putInternal.

/**
 * Core put method for all variants of puts/updates.
 *
 * @return old value if this is an update operation, otherwise returns null
 */
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:parameternumber", "checkstyle:cyclomaticcomplexity" })
private Object putInternal(Data key, Object newValue, long ttl, long maxIdle, long expiryTime, long now, boolean load, boolean store, boolean putIfAbsent, boolean putIfExists, boolean putIfEqual, boolean putFromLoad, Object expectedValue, boolean setTtl, boolean checkIfLoaded, @Nullable UUID transactionId, Address callerAddress, boolean countAsAccess, boolean backup) {
    // If this method has to wait end of map loading.
    if (checkIfLoaded) {
        checkIfLoaded();
    }
    Object oldValue = null;
    // Get record by checking expiry, if expired, evict record.
    Record record = getRecordOrNull(key, now, backup);
    // Variants of loading oldValue
    if (!putIfAbsent && !putIfExists) {
        oldValue = record == null ? (load ? loadValueOf(key) : null) : record.getValue();
    } else if (putIfAbsent) {
        record = getOrLoadRecord(record, key, now, callerAddress, backup);
        // if this is an existing record, return existing value.
        if (record != null) {
            return record.getValue();
        }
    } else if (putIfExists) {
        // For methods like setTtl and replace,
        // when no matching record, just return.
        record = getOrLoadRecord(record, key, now, callerAddress, backup);
        if (record == null) {
            return null;
        }
        oldValue = record.getValue();
        newValue = setTtl ? oldValue : newValue;
    }
    // For method replace, if current value is not expected one, return.
    if (putIfEqual && !valueComparator.isEqual(expectedValue, oldValue, serializationService)) {
        return null;
    }
    // Intercept put on owner partition.
    if (!backup) {
        newValue = mapServiceContext.interceptPut(interceptorRegistry, oldValue, newValue);
    }
    // Put new record or update existing one.
    if (record == null) {
        putNewRecord(key, oldValue, newValue, ttl, maxIdle, expiryTime, now, transactionId, putFromLoad ? LOADED : ADDED, store, backup);
    } else {
        oldValue = updateRecord(record, key, oldValue, newValue, ttl, maxIdle, expiryTime, now, transactionId, store, countAsAccess, backup);
    }
    return oldValue;
}
Also used : Record(com.hazelcast.map.impl.record.Record)

Example 43 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, Address callerAddress) {
    checkIfLoaded();
    long now = getNow();
    MapEntries mapEntries = new MapEntries(keys.size());
    // first search in memory
    Iterator<Data> iterator = keys.iterator();
    while (iterator.hasNext()) {
        Data key = iterator.next();
        Record record = getRecordOrNull(key, now, false);
        if (record != null) {
            addToMapEntrySet(key, record.getValue(), mapEntries);
            accessRecord(key, record, now);
            iterator.remove();
        }
    }
    // then try to load missing keys from map-store
    if (mapDataStore != EMPTY_MAP_DATA_STORE && !keys.isEmpty()) {
        Map loadedEntries = loadEntries(keys, callerAddress);
        addToMapEntrySet(loadedEntries, mapEntries);
    }
    return mapEntries;
}
Also used : MapEntries(com.hazelcast.map.impl.MapEntries) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) Data(com.hazelcast.internal.serialization.Data) Record(com.hazelcast.map.impl.record.Record) Map(java.util.Map) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap)

Example 44 with Record

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

the class DefaultRecordStore method removeBackupInternal.

private void removeBackupInternal(Data key, CallerProvenance provenance, UUID transactionId) {
    long now = getNow();
    Record record = getRecordOrNull(key, now, true);
    if (record == null) {
        return;
    }
    mutationObserver.onRemoveRecord(key, record);
    removeKeyFromExpirySystem(key);
    storage.removeRecord(key, record);
    if (persistenceEnabledFor(provenance)) {
        mapDataStore.removeBackup(key, now, transactionId);
    }
}
Also used : Record(com.hazelcast.map.impl.record.Record)

Example 45 with Record

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

the class DefaultRecordStore method get.

@Override
public Object get(Data key, boolean backup, Address callerAddress, boolean touch) {
    checkIfLoaded();
    long now = getNow();
    Record record = getRecordOrNull(key, now, backup);
    if (record != null && touch) {
        accessRecord(key, record, now);
    } else if (record == null && mapDataStore != EMPTY_MAP_DATA_STORE) {
        record = loadRecordOrNull(key, backup, callerAddress);
        record = evictIfExpired(key, now, backup) ? null : record;
    }
    Object value = record == null ? null : record.getValue();
    value = mapServiceContext.interceptGet(interceptorRegistry, value);
    return value;
}
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