Search in sources :

Example 16 with Record

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

the class DefaultRecordStore method putIfAbsent.

@Override
public Object putIfAbsent(Data key, Object value, long ttl) {
    checkIfLoaded();
    final long now = getNow();
    markRecordStoreExpirable(ttl);
    Record record = getRecordOrNull(key, now, false);
    Object oldValue;
    if (record == null) {
        oldValue = mapDataStore.load(key);
        if (oldValue != null) {
            record = createRecord(oldValue, DEFAULT_TTL, now);
            storage.put(key, record);
        }
    } else {
        accessRecord(record, now);
        oldValue = record.getValue();
    }
    if (oldValue == null) {
        value = mapServiceContext.interceptPut(name, null, value);
        value = mapDataStore.add(key, value, now);
        onStore(record);
        record = createRecord(value, ttl, now);
        storage.put(key, record);
        updateExpiryTime(record, ttl, mapContainer.getMapConfig());
    }
    saveIndex(record, oldValue);
    return oldValue;
}
Also used : Record(com.hazelcast.map.impl.record.Record)

Example 17 with Record

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

the class DefaultRecordStore method containsKey.

@Override
public boolean containsKey(Data key) {
    checkIfLoaded();
    final long now = getNow();
    Record record = getRecordOrNull(key, now, false);
    if (record == null) {
        record = loadRecordOrNull(key, false);
    }
    boolean contains = record != null;
    if (contains) {
        accessRecord(record, now);
    }
    return contains;
}
Also used : Record(com.hazelcast.map.impl.record.Record)

Example 18 with Record

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

the class DefaultRecordStore method loadEntries.

protected Map<Data, Object> loadEntries(Set<Data> keys) {
    Map loadedEntries = mapDataStore.loadAll(keys);
    if (loadedEntries == null || loadedEntries.isEmpty()) {
        return Collections.emptyMap();
    }
    // holds serialized keys and if values are serialized, also holds them in serialized format.
    Map<Data, Object> resultMap = createHashMap(loadedEntries.size());
    // add loaded key-value pairs to this record-store.
    Set entrySet = loadedEntries.entrySet();
    for (Object object : entrySet) {
        Map.Entry entry = (Map.Entry) object;
        Data key = toData(entry.getKey());
        Object value = entry.getValue();
        resultMap.put(key, value);
        putFromLoad(key, value);
    }
    if (hasQueryCache()) {
        for (Data key : resultMap.keySet()) {
            Record record = storage.get(key);
            // here we are only publishing events for loaded entries. This is required for notifying query-caches
            // otherwise query-caches cannot see loaded entries
            addEventToQueryCache(record);
        }
    }
    return resultMap;
}
Also used : DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry) Set(java.util.Set) HashSet(java.util.HashSet) 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 19 with Record

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

the class DefaultRecordStore method putFromLoadInternal.

private Object putFromLoadInternal(Data key, Object value, long ttl, boolean backup) {
    if (!isKeyAndValueLoadable(key, value)) {
        return null;
    }
    final long now = getNow();
    if (shouldEvict()) {
        return null;
    }
    markRecordStoreExpirable(ttl);
    Record record = getRecordOrNull(key, now, false);
    Object oldValue = null;
    if (record == null) {
        value = mapServiceContext.interceptPut(name, null, value);
        record = createRecord(value, ttl, now);
        storage.put(key, record);
    } else {
        oldValue = record.getValue();
        value = mapServiceContext.interceptPut(name, oldValue, value);
        updateRecord(key, record, value, now);
        updateExpiryTime(record, ttl, mapContainer.getMapConfig());
    }
    if (!backup) {
        saveIndex(record, oldValue);
    }
    return oldValue;
}
Also used : Record(com.hazelcast.map.impl.record.Record)

Example 20 with Record

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

the class TxnLockAndGetOperation method run.

@Override
public void run() throws Exception {
    if (!recordStore.txnLock(getKey(), ownerUuid, getThreadId(), getCallId(), ttl, blockReads)) {
        throw new TransactionException("Transaction couldn't obtain lock.");
    }
    Record record = recordStore.getRecordOrNull(dataKey);
    if (record == null && shouldLoad) {
        record = recordStore.loadRecordOrNull(dataKey, false);
    }
    Data value = record == null ? null : mapServiceContext.toData(record.getValue());
    response = new VersionedValue(value, record == null ? 0 : record.getVersion());
}
Also used : TransactionException(com.hazelcast.transaction.TransactionException) Record(com.hazelcast.map.impl.record.Record) Data(com.hazelcast.nio.serialization.Data)

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