Search in sources :

Example 11 with ExpiryMetadata

use of com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata in project hazelcast by hazelcast.

the class RecordReaderWriterTest method written_and_read_data_record_with_stats_are_equal.

@Test
public void written_and_read_data_record_with_stats_are_equal() throws IOException {
    ExpiryMetadata expiryMetadata = newExpiryMetadata();
    Record<Data> writtenRecord = populateAndGetRecord(new DataRecordWithStats(), expiryMetadata);
    Record<Data> readRecord = writeReadAndGet(writtenRecord, writtenRecord.getValue(), expiryMetadata);
    assertEquals(writtenRecord, readRecord);
}
Also used : Data(com.hazelcast.internal.serialization.Data) ExpiryMetadata(com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with ExpiryMetadata

use of com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata in project hazelcast by hazelcast.

the class RecordReaderWriterTest method written_and_read_object_record_with_stats_are_equal.

@Test
public void written_and_read_object_record_with_stats_are_equal() throws IOException {
    ExpiryMetadata expiryMetadata = newExpiryMetadata();
    Record writtenRecord = populateAndGetRecord(new ObjectRecordWithStats(), expiryMetadata);
    Data dataValue = ss.toData(writtenRecord.getValue());
    Record<Data> readRecord = writeReadAndGet(writtenRecord, dataValue, expiryMetadata);
    assertEquals(asDataRecordWithStats(writtenRecord, dataValue), readRecord);
}
Also used : Data(com.hazelcast.internal.serialization.Data) ExpiryMetadata(com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with ExpiryMetadata

use of com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata in project hazelcast by hazelcast.

the class MapReplicationStateHolder method forEachReplicatedRecord.

private void forEachReplicatedRecord(List keyRecordExpiry, MapContainer mapContainer, RecordStore recordStore, boolean populateIndexes, long nowInMillis) {
    long ownedEntryCountOnThisNode = entryCountOnThisNode(mapContainer);
    EvictionConfig evictionConfig = mapContainer.getMapConfig().getEvictionConfig();
    boolean perNodeEvictionConfigured = mapContainer.getEvictor() != Evictor.NULL_EVICTOR && evictionConfig.getMaxSizePolicy() == PER_NODE;
    for (int i = 0; i < keyRecordExpiry.size(); i += 3) {
        Data dataKey = (Data) keyRecordExpiry.get(i);
        Record record = (Record) keyRecordExpiry.get(i + 1);
        ExpiryMetadata expiryMetadata = (ExpiryMetadata) keyRecordExpiry.get(i + 2);
        if (perNodeEvictionConfigured) {
            if (ownedEntryCountOnThisNode >= evictionConfig.getSize()) {
                if (operation.getReplicaIndex() == 0) {
                    recordStore.doPostEvictionOperations(dataKey, record.getValue(), ExpiryReason.NOT_EXPIRED);
                }
            } else {
                recordStore.putOrUpdateReplicatedRecord(dataKey, record, expiryMetadata, populateIndexes, nowInMillis);
                ownedEntryCountOnThisNode++;
            }
        } else {
            recordStore.putOrUpdateReplicatedRecord(dataKey, record, expiryMetadata, populateIndexes, nowInMillis);
            if (recordStore.shouldEvict()) {
                // No need to continue replicating records anymore.
                // We are already over eviction threshold, each put record will cause another eviction.
                recordStore.evictEntries(dataKey);
                break;
            }
        }
        recordStore.disposeDeferredBlocks();
    }
}
Also used : EvictionConfig(com.hazelcast.config.EvictionConfig) Data(com.hazelcast.internal.serialization.Data) Record(com.hazelcast.map.impl.record.Record) ExpiryMetadata(com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata)

Example 14 with ExpiryMetadata

use of com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata in project hazelcast by hazelcast.

the class MapChunk method putOrUpdateReplicatedDataWithPerNodeEviction.

// owned or backup
private void putOrUpdateReplicatedDataWithPerNodeEviction(RecordStore recordStore) {
    MapContainer mapContainer = recordStore.getMapContainer();
    EvictionConfig evictionConfig = mapContainer.getMapConfig().getEvictionConfig();
    long ownedEntryCountOnThisNode = entryCountOnThisNode(mapContainer);
    int count = 0;
    long nowInMillis = Clock.currentTimeMillis();
    do {
        Data dataKey = (Data) keyRecordExpiry.poll();
        Record record = (Record) keyRecordExpiry.poll();
        ExpiryMetadata expiryMetadata = (ExpiryMetadata) keyRecordExpiry.poll();
        if (ownedEntryCountOnThisNode >= evictionConfig.getSize()) {
            if (getReplicaIndex() == 0) {
                recordStore.doPostEvictionOperations(dataKey, record.getValue(), ExpiryReason.NOT_EXPIRED);
            }
        } else {
            Indexes indexes = mapContainer.getIndexes(recordStore.getPartitionId());
            recordStore.putOrUpdateReplicatedRecord(dataKey, record, expiryMetadata, indexesMustBePopulated(indexes), nowInMillis);
            ownedEntryCountOnThisNode++;
        }
        if (++count % DISPOSE_AT_COUNT == 0) {
            recordStore.disposeDeferredBlocks();
        }
    } while (!keyRecordExpiry.isEmpty());
    recordStore.disposeDeferredBlocks();
}
Also used : EvictionConfig(com.hazelcast.config.EvictionConfig) Data(com.hazelcast.internal.serialization.Data) Record(com.hazelcast.map.impl.record.Record) Indexes(com.hazelcast.query.impl.Indexes) MapContainer(com.hazelcast.map.impl.MapContainer) ExpiryMetadata(com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata)

Example 15 with ExpiryMetadata

use of com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata in project hazelcast by hazelcast.

the class Records method readExpiry.

public static ExpiryMetadata readExpiry(ObjectDataInput in) throws IOException {
    ExpiryMetadata expiryMetadata = ExpiryMetadata.NULL;
    boolean hasExpiry = in.readBoolean();
    if (hasExpiry) {
        expiryMetadata = new ExpiryMetadataImpl();
        expiryMetadata.read(in);
    }
    return expiryMetadata;
}
Also used : ExpiryMetadataImpl(com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadataImpl) ExpiryMetadata(com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata)

Aggregations

ExpiryMetadata (com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadata)16 Data (com.hazelcast.internal.serialization.Data)13 Record (com.hazelcast.map.impl.record.Record)11 ArrayList (java.util.ArrayList)3 List (java.util.List)3 EvictionConfig (com.hazelcast.config.EvictionConfig)2 Indexes (com.hazelcast.query.impl.Indexes)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 LocalRecordStoreStatsImpl (com.hazelcast.internal.monitor.impl.LocalRecordStoreStatsImpl)1 ToHeapDataConverter.toHeapData (com.hazelcast.internal.util.ToHeapDataConverter.toHeapData)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)1 ExpiryMetadataImpl (com.hazelcast.map.impl.recordstore.expiry.ExpiryMetadataImpl)1 MapMergeTypes (com.hazelcast.spi.merge.SplitBrainMergeTypes.MapMergeTypes)1 LinkedList (java.util.LinkedList)1