Search in sources :

Example 6 with VectorClock

use of com.hazelcast.cluster.impl.VectorClock in project hazelcast by hazelcast.

the class PNCounterService method clearCRDTState.

@Override
public boolean clearCRDTState(Map<String, VectorClock> vectorClocks) {
    boolean allCleared = true;
    for (Entry<String, VectorClock> vectorClockEntry : vectorClocks.entrySet()) {
        final String counterName = vectorClockEntry.getKey();
        final VectorClock vectorClock = vectorClockEntry.getValue();
        final PNCounterImpl counter = counters.get(counterName);
        if (counter == null) {
            continue;
        }
        if (counter.markMigrated(vectorClock)) {
            counters.remove(counterName);
            statsMap.remove(counterName);
        } else {
            allCleared = false;
        }
    }
    return allCleared;
}
Also used : VectorClock(com.hazelcast.cluster.impl.VectorClock)

Example 7 with VectorClock

use of com.hazelcast.cluster.impl.VectorClock in project hazelcast by hazelcast.

the class ReplicatedVectorClocks method getLatestReplicatedVectorClock.

/**
 * Returns the vector clock map for the given {@code serviceName}.
 * For each CRDT belonging to that service, the map contains the latest
 * successfully replicated vector clocks to any replica.
 *
 * @param serviceName the CRDT service name
 * @return the last successfully replicated vector clock for all CRDTs for
 * the given {@code serviceName}
 * @see CRDTReplicationAwareService
 */
public Map<String, VectorClock> getLatestReplicatedVectorClock(String serviceName) {
    final HashMap<String, VectorClock> latestVectorClocks = new HashMap<>();
    for (Entry<ReplicatedVectorClockId, Map<String, VectorClock>> clockEntry : replicatedVectorClocks.entrySet()) {
        final ReplicatedVectorClockId id = clockEntry.getKey();
        final Map<String, VectorClock> clock = clockEntry.getValue();
        if (id.serviceName.equals(serviceName)) {
            for (Entry<String, VectorClock> crdtReplicatedClocks : clock.entrySet()) {
                final String crdtName = crdtReplicatedClocks.getKey();
                final VectorClock vectorClock = crdtReplicatedClocks.getValue();
                final VectorClock latestVectorClock = latestVectorClocks.get(crdtName);
                if (latestVectorClock == null || vectorClock.isAfter(latestVectorClock)) {
                    latestVectorClocks.put(crdtName, vectorClock);
                }
            }
        }
    }
    return latestVectorClocks;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) VectorClock(com.hazelcast.cluster.impl.VectorClock) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

VectorClock (com.hazelcast.cluster.impl.VectorClock)7 HashMap (java.util.HashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Config (com.hazelcast.config.Config)2 PNCounterConfig (com.hazelcast.config.PNCounterConfig)2 CRDTReplicationContainer (com.hazelcast.internal.crdt.CRDTReplicationContainer)2 Address (com.hazelcast.cluster.Address)1 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)1 EndpointQualifier (com.hazelcast.instance.EndpointQualifier)1 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)1 AuthenticationFailureOp (com.hazelcast.internal.cluster.impl.operations.AuthenticationFailureOp)1 BeforeJoinCheckFailureOp (com.hazelcast.internal.cluster.impl.operations.BeforeJoinCheckFailureOp)1 ClusterMismatchOp (com.hazelcast.internal.cluster.impl.operations.ClusterMismatchOp)1 CommitClusterStateOp (com.hazelcast.internal.cluster.impl.operations.CommitClusterStateOp)1 ConfigMismatchOp (com.hazelcast.internal.cluster.impl.operations.ConfigMismatchOp)1 ExplicitSuspicionOp (com.hazelcast.internal.cluster.impl.operations.ExplicitSuspicionOp)1 FetchMembersViewOp (com.hazelcast.internal.cluster.impl.operations.FetchMembersViewOp)1 FinalizeJoinOp (com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOp)1 HeartbeatComplaintOp (com.hazelcast.internal.cluster.impl.operations.HeartbeatComplaintOp)1 HeartbeatOp (com.hazelcast.internal.cluster.impl.operations.HeartbeatOp)1