Search in sources :

Example 1 with ReplicatedRecord

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;
}
Also used : LocalReplicatedMapStatsImpl(com.hazelcast.monitor.impl.LocalReplicatedMapStatsImpl) ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore)

Example 2 with ReplicatedRecord

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);
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) Collection(java.util.Collection)

Example 3 with ReplicatedRecord

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;
}
Also used : LocalReplicatedMapStatsImpl(com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl) ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) EmptyLocalReplicatedMapStats(com.hazelcast.internal.monitor.impl.EmptyLocalReplicatedMapStats) LocalReplicatedMapStats(com.hazelcast.replicatedmap.LocalReplicatedMapStats)

Example 4 with ReplicatedRecord

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

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