Search in sources :

Example 6 with ReplicatedRecord

use of com.hazelcast.replicatedmap.impl.record.ReplicatedRecord in project hazelcast by hazelcast.

the class ReplicatedMapHitsAndLastAccessTimeTest method testHitsAreIncrementedOnPutsFor1Of2Nodes.

private void testHitsAreIncrementedOnPutsFor1Of2Nodes(final Config config) {
    final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    final HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    final HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    warmUpPartitions(instance1, instance2);
    final String mapName = randomMapName();
    final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap(mapName);
    final ReplicatedMap<String, String> map2 = instance2.getReplicatedMap(mapName);
    final int partitionCount = getPartitionService(instance1).getPartitionCount();
    final Set<String> keys = generateRandomKeys(instance1, partitionCount);
    for (String key : keys) {
        map1.put(key, "bar");
    }
    for (String key : keys) {
        map1.put(key, "bar");
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (String key : keys) {
                final ReplicatedRecord<String, String> record1 = getReplicatedRecord(map1, key);
                assertNotNull(record1);
                assertEquals(1, record1.getHits());
                final ReplicatedRecord<String, String> record2 = getReplicatedRecord(map2, key);
                assertNotNull(record2);
                assertEquals(0, record2.getHits());
            }
        }
    });
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 7 with ReplicatedRecord

use of com.hazelcast.replicatedmap.impl.record.ReplicatedRecord in project hazelcast by hazelcast.

the class ReplicatedMapHitsAndLastAccessTimeTest method testHitsAndLastAccessTimeAreSetFor1Of2Nodes.

private void testHitsAndLastAccessTimeAreSetFor1Of2Nodes(Config config) throws Exception {
    final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    final HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    final HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    warmUpPartitions(instance1, instance2);
    final String mapName = randomMapName();
    final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap(mapName);
    final ReplicatedMap<String, String> map2 = instance2.getReplicatedMap(mapName);
    final int partitionCount = getPartitionService(instance1).getPartitionCount();
    final Set<String> keys = generateRandomKeys(instance1, partitionCount);
    for (String key : keys) {
        map1.put(key, "bar");
        map1.containsKey(key);
    }
    for (String key : keys) {
        final ReplicatedRecord<String, String> replicatedRecord = getReplicatedRecord(map1, key);
        assertNotNull(replicatedRecord);
        assertEquals(1, replicatedRecord.getHits());
        assertTrue("Last access time should be set for " + key, replicatedRecord.getLastAccessTime() > 0);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (String key : keys) {
                final ReplicatedRecord<String, String> replicatedRecord = getReplicatedRecord(map2, key);
                assertNotNull(replicatedRecord);
                assertEquals(0, replicatedRecord.getHits());
                assertTrue("Last access time should be set for " + key, replicatedRecord.getLastAccessTime() > 0);
            }
        }
    });
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 8 with ReplicatedRecord

use of com.hazelcast.replicatedmap.impl.record.ReplicatedRecord in project hazelcast by hazelcast.

the class ReplicatedMapMergeRunnable method mergeStore.

@Override
protected void mergeStore(ReplicatedRecordStore store, BiConsumer<Integer, ReplicatedMapMergeTypes<Object, Object>> consumer) {
    int partitionId = store.getPartitionId();
    Iterator<ReplicatedRecord> iterator = store.recordIterator();
    while (iterator.hasNext()) {
        ReplicatedRecord record = iterator.next();
        ReplicatedMapMergeTypes<Object, Object> mergingEntry = createMergingEntry(getSerializationService(), record);
        consumer.accept(partitionId, mergingEntry);
    }
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord)

Example 9 with ReplicatedRecord

use of com.hazelcast.replicatedmap.impl.record.ReplicatedRecord in project hazelcast by hazelcast.

the class RequestMapDataOperation method getRecordSet.

private Set<RecordMigrationInfo> getRecordSet(ReplicatedRecordStore store) {
    SerializationService serializationService = getNodeEngine().getSerializationService();
    Set<RecordMigrationInfo> recordSet = createHashSet(store.size());
    Iterator<ReplicatedRecord> iterator = store.recordIterator();
    while (iterator.hasNext()) {
        ReplicatedRecord record = iterator.next();
        Data dataKey = serializationService.toData(record.getKeyInternal());
        Data dataValue = serializationService.toData(record.getValueInternal());
        recordSet.add(new RecordMigrationInfo(dataKey, dataValue, record.getTtlMillis()));
    }
    return recordSet;
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) RecordMigrationInfo(com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo)

Example 10 with ReplicatedRecord

use of com.hazelcast.replicatedmap.impl.record.ReplicatedRecord in project hazelcast by hazelcast.

the class SyncReplicatedMapDataOperation method run.

@Override
@SuppressWarnings("unchecked")
public void run() throws Exception {
    ILogger logger = getLogger();
    if (logger.isFineEnabled()) {
        logger.fine("Syncing " + recordSet.size() + " records (version " + version + ") for replicated map '" + name + "' (partitionId " + getPartitionId() + ") from " + getCallerAddress() + " to " + getNodeEngine().getThisAddress());
    }
    ReplicatedMapService service = getService();
    AbstractReplicatedRecordStore store = (AbstractReplicatedRecordStore) service.getReplicatedRecordStore(name, true, getPartitionId());
    InternalReplicatedMapStorage<K, V> newStorage = new InternalReplicatedMapStorage<>();
    for (RecordMigrationInfo record : recordSet) {
        K key = (K) store.marshall(record.getKey());
        V value = (V) store.marshall(record.getValue());
        ReplicatedRecord<K, V> replicatedRecord = buildReplicatedRecord(key, value, record.getTtl());
        ReplicatedRecord oldRecord = store.getReplicatedRecord(key);
        if (oldRecord != null) {
            replicatedRecord.setHits(oldRecord.getHits());
        }
        newStorage.put(key, replicatedRecord);
        if (record.getTtl() > 0) {
            store.scheduleTtlEntry(record.getTtl(), key, value);
        }
    }
    newStorage.syncVersion(version);
    AtomicReference<InternalReplicatedMapStorage<K, V>> storageRef = store.getStorageRef();
    storageRef.set(newStorage);
    store.setLoaded(true);
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) ILogger(com.hazelcast.logging.ILogger) InternalReplicatedMapStorage(com.hazelcast.replicatedmap.impl.record.InternalReplicatedMapStorage) RecordMigrationInfo(com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo)

Aggregations

ReplicatedRecord (com.hazelcast.replicatedmap.impl.record.ReplicatedRecord)14 ReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 Data (com.hazelcast.internal.serialization.Data)4 ReplicatedMapService (com.hazelcast.replicatedmap.impl.ReplicatedMapService)4 AssertTask (com.hazelcast.test.AssertTask)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)4 SerializationService (com.hazelcast.internal.serialization.SerializationService)3 RecordMigrationInfo (com.hazelcast.replicatedmap.impl.record.RecordMigrationInfo)3 AbstractReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)1 EmptyLocalReplicatedMapStats (com.hazelcast.internal.monitor.impl.EmptyLocalReplicatedMapStats)1 LocalReplicatedMapStatsImpl (com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl)1 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)1 ILogger (com.hazelcast.logging.ILogger)1 DataCollection (com.hazelcast.map.impl.DataCollection)1 MapEntries (com.hazelcast.map.impl.MapEntries)1 LocalReplicatedMapStatsImpl (com.hazelcast.monitor.impl.LocalReplicatedMapStatsImpl)1