Search in sources :

Example 1 with CRDTReplicationContainer

use of com.hazelcast.internal.crdt.CRDTReplicationContainer in project hazelcast by hazelcast.

the class PNCounterService method prepareMigrationOperation.

@Override
public CRDTReplicationContainer prepareMigrationOperation(int maxConfiguredReplicaCount) {
    final HashMap<String, VectorClock> currentVectorClocks = new HashMap<>();
    final HashMap<String, PNCounterImpl> counters = new HashMap<>();
    final Config config = nodeEngine.getConfig();
    for (Entry<String, PNCounterImpl> counterEntry : this.counters.entrySet()) {
        final String counterName = counterEntry.getKey();
        final PNCounterImpl counter = counterEntry.getValue();
        if (config.findPNCounterConfig(counterName).getReplicaCount() >= maxConfiguredReplicaCount) {
            continue;
        }
        counters.put(counterName, counter);
        currentVectorClocks.put(counterName, counter.getCurrentVectorClock());
    }
    return counters.isEmpty() ? null : new CRDTReplicationContainer(new PNCounterReplicationOperation(counters), currentVectorClocks);
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PNCounterConfig(com.hazelcast.config.PNCounterConfig) Config(com.hazelcast.config.Config) VectorClock(com.hazelcast.cluster.impl.VectorClock) CRDTReplicationContainer(com.hazelcast.internal.crdt.CRDTReplicationContainer)

Example 2 with CRDTReplicationContainer

use of com.hazelcast.internal.crdt.CRDTReplicationContainer in project hazelcast by hazelcast.

the class PNCounterService method prepareReplicationOperation.

@Override
public CRDTReplicationContainer prepareReplicationOperation(Map<String, VectorClock> previouslyReplicatedVectorClocks, int targetIndex) {
    final HashMap<String, VectorClock> currentVectorClocks = new HashMap<String, VectorClock>();
    final HashMap<String, PNCounterImpl> counters = new HashMap<String, PNCounterImpl>();
    final Config config = nodeEngine.getConfig();
    for (Entry<String, PNCounterImpl> counterEntry : this.counters.entrySet()) {
        final String counterName = counterEntry.getKey();
        final PNCounterImpl counter = counterEntry.getValue();
        if (targetIndex >= config.findPNCounterConfig(counterName).getReplicaCount()) {
            continue;
        }
        final VectorClock counterCurrentVectorClock = counter.getCurrentVectorClock();
        final VectorClock counterPreviousVectorClock = previouslyReplicatedVectorClocks.get(counterName);
        if (counterPreviousVectorClock == null || counterCurrentVectorClock.isAfter(counterPreviousVectorClock)) {
            counters.put(counterName, counter);
        }
        currentVectorClocks.put(counterName, counterCurrentVectorClock);
    }
    return counters.isEmpty() ? null : new CRDTReplicationContainer(new PNCounterReplicationOperation(counters), currentVectorClocks);
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PNCounterConfig(com.hazelcast.config.PNCounterConfig) Config(com.hazelcast.config.Config) VectorClock(com.hazelcast.cluster.impl.VectorClock) CRDTReplicationContainer(com.hazelcast.internal.crdt.CRDTReplicationContainer)

Aggregations

VectorClock (com.hazelcast.cluster.impl.VectorClock)2 Config (com.hazelcast.config.Config)2 PNCounterConfig (com.hazelcast.config.PNCounterConfig)2 CRDTReplicationContainer (com.hazelcast.internal.crdt.CRDTReplicationContainer)2 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2