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());
}
}
});
}
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);
}
}
});
}
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);
}
}
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;
}
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);
}
Aggregations