/** * This function is not safe because it may break the pre-condition that * clock entries should be sorted by nodeId * */ @Deprecated public VectorClock(List<ClockEntry> versions, long timestamp) { this.versionMap = new TreeMap<Short, Long>(); this.timestamp = timestamp; for(ClockEntry clockEntry: versions) { this.versionMap.put(clockEntry.getNodeId(), clockEntry.getVersion()); } }
/** * Function to copy values from another VectorClock. This is used for * in-place updates during a Voldemort put operation. * * @param vc The VectorClock object from which the inner values are to be * copied. */ public void copyFromVectorClock(VectorClock vc) { this.versionMap.clear(); this.timestamp = vc.getTimestamp(); for(ClockEntry clockEntry: vc.getEntries()) { this.versionMap.put(clockEntry.getNodeId(), clockEntry.getVersion()); } } }
private boolean clockContainsNonReplicas(VectorClock clock, List<Integer> replicas) { for(ClockEntry cEntry: clock.getEntries()) { if(!replicas.contains((int) cEntry.getNodeId())) { return true; } } return false; }
/** * Remove all non replica clock entries from the list of versioned values * provided * * @param vals list of versioned values to prune replicas from * @param keyReplicas list of current replicas for the given key * @param didPrune flag to mark if we did actually prune something * @return pruned list */ public static List<Versioned<byte[]>> pruneNonReplicaEntries(List<Versioned<byte[]>> vals, List<Integer> keyReplicas, MutableBoolean didPrune) { List<Versioned<byte[]>> prunedVals = new ArrayList<Versioned<byte[]>>(vals.size()); for(Versioned<byte[]> val: vals) { VectorClock clock = (VectorClock) val.getVersion(); List<ClockEntry> clockEntries = new ArrayList<ClockEntry>(); for(ClockEntry clockEntry: clock.getEntries()) { if(keyReplicas.contains((int) clockEntry.getNodeId())) { clockEntries.add(clockEntry); } else { didPrune.setValue(true); } } prunedVals.add(new Versioned<byte[]>(val.getValue(), new VectorClock(clockEntries, clock.getTimestamp()))); } return prunedVals; }
public static VProto.VectorClock.Builder encodeClock(Version version) { VectorClock clock = (VectorClock) version; VProto.VectorClock.Builder encoded = VProto.VectorClock.newBuilder(); encoded.setTimestamp(clock.getTimestamp()); for(ClockEntry entry: clock.getEntries()) encoded.addEntries(VProto.ClockEntry.newBuilder() .setNodeId(entry.getNodeId()) .setVersion(entry.getVersion())); return encoded; }
public void testIncrement() { ClockEntry v = new ClockEntry((short) 0, 1); assertEquals(v.getNodeId(), 0); assertEquals(v.getVersion(), 1); ClockEntry v2 = v.incremented(); assertEquals(v.getVersion(), 1); assertEquals(v2.getVersion(), 2); }