public VectorClockWrapper(VectorClock vc) { this.versions = vc.getEntries(); this.setTimestamp(vc.getTimestamp()); }
/** * 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; }
|| this.parsedVectorClock.getEntries().size() == 0) { if(logger.isDebugEnabled()) { debugLog("PUT", System.currentTimeMillis());
if(vc != null && vc.getEntries().size() != 0) { String serializedVC = null; if(!vc.getEntries().isEmpty()) { serializedVC = RestUtils.getSerializedVectorClock(vc);
/** * A test for comparing vector clocks that nodes of clock entries are not * sorted In case people insert clock entries without using increment we * need to test although it has been deprecated */ @Test public void testNodeClockEntryDeprecate() { VectorClock vc1 = new VectorClock(); try { vc1.getEntries().add(new ClockEntry((short) 2, 2)); fail("Did not throw UnsupportedOperationException"); } catch(UnsupportedOperationException e) { } }
if(!vc.getEntries().isEmpty()) { serializedVC = RestUtils.getSerializedVectorClock(vc);
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; }
@Override @Test public void testPutVersioned() { VectorClock vc = new VectorClock(); vc.incrementVersion(this.nodeId, System.currentTimeMillis()); VectorClock initialVC = vc.clone(); client.put("k", new Versioned<String>("v", vc)); Versioned<String> v = client.get("k"); assertEquals("GET should return the version set by PUT.", "v", v.getValue()); VectorClock expected = initialVC.clone(); expected.incrementVersion(this.nodeId, System.currentTimeMillis()); assertEquals("The version should be incremented after a put.", expected.getEntries(), ((VectorClock) v.getVersion()).getEntries()); try { client.put("k", new Versioned<String>("v", initialVC)); fail("Put of obsolete version should throw exception."); } catch(ObsoleteVersionException e) { // this is good } // PUT of a concurrent version should succeed client.put("k", new Versioned<String>("v2", new VectorClock().incremented(nodeId + 1, time.getMilliseconds()))); assertEquals("GET should return the new value set by PUT.", "v2", client.getValue("k")); assertEquals("GET should return the new version set by PUT.", expected.incremented(nodeId + 1, time.getMilliseconds()), client.get("k").getVersion()); }