use of com.hazelcast.replicatedmap.impl.record.ReplicatedRecord in project hazelcast by hazelcast.
the class ReplicatedMapService method createReplicatedMapStats.
public LocalReplicatedMapStatsImpl createReplicatedMapStats(String name) {
LocalReplicatedMapStatsImpl stats = getLocalMapStatsImpl(name);
long hits = 0;
long count = 0;
long memoryUsage = 0;
boolean isBinary = (getReplicatedMapConfig(name).getInMemoryFormat() == InMemoryFormat.BINARY);
for (PartitionContainer container : partitionContainers) {
ReplicatedRecordStore store = container.getRecordStore(name);
if (store == null) {
continue;
}
Iterator<ReplicatedRecord> iterator = store.recordIterator();
while (iterator.hasNext()) {
ReplicatedRecord record = iterator.next();
stats.setLastAccessTime(Math.max(stats.getLastAccessTime(), record.getLastAccessTime()));
stats.setLastUpdateTime(Math.max(stats.getLastUpdateTime(), record.getUpdateTime()));
hits += record.getHits();
if (isBinary) {
memoryUsage += ((HeapData) record.getValueInternal()).getHeapCost();
}
count++;
}
}
stats.setOwnedEntryCount(count);
stats.setHits(hits);
stats.setOwnedEntryMemoryCost(memoryUsage);
return stats;
}
use of com.hazelcast.replicatedmap.impl.record.ReplicatedRecord in project hazelcast by hazelcast.
the class ReplicatedMapSplitBrainHandlerService method prepareMergeRunnable.
@Override
public Runnable prepareMergeRunnable() {
HashMap<String, Collection<ReplicatedRecord>> recordMap = new HashMap<String, Collection<ReplicatedRecord>>();
Address thisAddress = service.getNodeEngine().getThisAddress();
List<Integer> partitions = nodeEngine.getPartitionService().getMemberPartitions(thisAddress);
for (Integer partition : partitions) {
PartitionContainer partitionContainer = service.getPartitionContainer(partition);
ConcurrentMap<String, ReplicatedRecordStore> stores = partitionContainer.getStores();
for (ReplicatedRecordStore store : stores.values()) {
String name = store.getName();
Collection<ReplicatedRecord> records = recordMap.get(name);
if (records == null) {
records = new ArrayList<ReplicatedRecord>();
}
Iterator<ReplicatedRecord> iterator = store.recordIterator();
while (iterator.hasNext()) {
ReplicatedRecord record = iterator.next();
records.add(record);
}
recordMap.put(name, records);
store.reset();
}
}
return new Merger(recordMap);
}
use of com.hazelcast.replicatedmap.impl.record.ReplicatedRecord in project hazelcast by hazelcast.
the class LocalReplicatedMapStatsProvider method getLocalReplicatedMapStats.
LocalReplicatedMapStats getLocalReplicatedMapStats(String name) {
ReplicatedMapConfig replicatedMapConfig = getReplicatedMapConfig(name);
final LocalReplicatedMapStats result;
if (!replicatedMapConfig.isStatisticsEnabled()) {
result = EMPTY_LOCAL_MAP_STATS;
} else {
LocalReplicatedMapStatsImpl stats = getLocalReplicatedMapStatsImpl(name);
long hits = 0;
long count = 0;
long memoryUsage = 0;
boolean isBinary = (replicatedMapConfig.getInMemoryFormat() == InMemoryFormat.BINARY);
for (PartitionContainer container : partitionContainers) {
ReplicatedRecordStore store = container.getRecordStore(name);
if (store == null) {
continue;
}
Iterator<ReplicatedRecord> iterator = store.recordIterator();
while (iterator.hasNext()) {
ReplicatedRecord record = iterator.next();
stats.setLastAccessTime(max(stats.getLastAccessTime(), record.getLastAccessTime()));
stats.setLastUpdateTime(max(stats.getLastUpdateTime(), record.getUpdateTime()));
hits += record.getHits();
if (isBinary) {
memoryUsage += ((HeapData) record.getValueInternal()).getHeapCost();
}
count++;
}
}
stats.setOwnedEntryCount(count);
stats.setHits(hits);
stats.setOwnedEntryMemoryCost(memoryUsage);
result = stats;
}
return result;
}
use of com.hazelcast.replicatedmap.impl.record.ReplicatedRecord in project hazelcast by hazelcast.
the class ReplicatedMapTest method testAddTtl.
private void testAddTtl(Config config) {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap("default");
final ReplicatedMap<String, String> map2 = instance2.getReplicatedMap("default");
final int partitionCount = getPartitionService(instance1).getPartitionCount();
final Set<String> keys = generateRandomKeys(instance1, partitionCount);
for (String key : keys) {
map1.put(key, "bar", 10, TimeUnit.MINUTES);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
for (String key : keys) {
assertEquals("bar", map1.get(key));
ReplicatedRecord<String, String> record = getReplicatedRecord(map1, key);
assertNotNull(record);
assertNotEquals(0, record.getTtlMillis());
}
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
for (String key : keys) {
assertEquals("bar", map2.get(key));
ReplicatedRecord<String, String> record = getReplicatedRecord(map2, key);
assertNotNull(record);
assertNotEquals(0, record.getTtlMillis());
}
}
});
}
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);
}
}
Aggregations