public Occurred compare(Value v) { if (!(v instanceof VersionValue)) { throw new VoldemortException(" Expected type VersionValue found type " + v.getClass().getCanonicalName()); } VersionValue other = (VersionValue) v; return version.compare(other.version); }
public int compare(Versioned<S> v1, Versioned<S> v2) { Occurred occurred = v1.getVersion().compare(v2.getVersion()); if(occurred == Occurred.BEFORE) return -1; else if(occurred == Occurred.AFTER) return 1; else return 0; } }
public List<Versioned<T>> resolveConflicts(List<Versioned<T>> items) { int size = items.size(); if(size <= 1) return items; List<Versioned<T>> newItems = Lists.newArrayList(); for(Versioned<T> v1: items) { boolean found = false; for(ListIterator<Versioned<T>> it2 = newItems.listIterator(); it2.hasNext();) { Versioned<T> v2 = it2.next(); Occurred compare = v1.getVersion().compare(v2.getVersion()); if(compare == Occurred.AFTER) { if(found) it2.remove(); else it2.set(v1); } if(compare != Occurred.CONCURRENTLY) found = true; } if(!found) newItems.add(v1); } return newItems; }
Occurred occurred = value.getVersion().compare(curr.getVersion()); if(occurred == Occurred.BEFORE) { obsolete = true;
@Override public synchronized boolean delete(K key, Version version) { StoreUtils.assertValidKey(key); List<Versioned<V>> values = map.get(key); if(values == null) { return false; } if(version == null) { map.remove(key); return true; } boolean deletedSomething = false; Iterator<Versioned<V>> iterator = values.iterator(); while(iterator.hasNext()) { Versioned<V> item = iterator.next(); if(item.getVersion().compare(version) == Occurred.BEFORE) { iterator.remove(); deletedSomething = true; } } if(values.size() == 0) { // if there are no more versions left, also remove the key from the // map map.remove(key); } return deletedSomething; }
Occurred occurred = value.getVersion().compare(curr.getVersion()); if(occurred == Occurred.BEFORE) { obsolete = true;
@Override public synchronized void put(K key, Versioned<V> value, T transforms) throws VoldemortException { StoreUtils.assertValidKey(key); List<Versioned<V>> items = map.get(key); // If we have no value, add the current value if(items == null) { items = new ArrayList<Versioned<V>>(); } // Check for existing versions - remember which items to // remove in case of success List<Versioned<V>> itemsToRemove = new ArrayList<Versioned<V>>(items.size()); for(Versioned<V> versioned: items) { Occurred occurred = value.getVersion().compare(versioned.getVersion()); if(occurred == Occurred.BEFORE) { throw new ObsoleteVersionException("Obsolete version for key '" + key + "': " + value.getVersion()); } else if(occurred == Occurred.AFTER) { itemsToRemove.add(versioned); } } items.removeAll(itemsToRemove); items.add(value); map.put(key, items); }
Occurred occurred = curr.getVersion().compare(currentGoodversion); if(occurred == Occurred.BEFORE) {
Versioned<String> localVersioned = adminClient.metadataMgmtOps.getRemoteMetadata(metadataStore.getNodeId(), key); switch(remoteVersioned.getVersion().compare(localVersioned.getVersion())) {
if(file.getName().equals(key)) { VectorClock clock = readVersion(key); if(value.getVersion().compare(clock) == Occurred.AFTER) { } else if(value.getVersion().compare(clock) == Occurred.BEFORE) { throw new ObsoleteVersionException("A successor version " + clock + " to this " + value.getVersion() + " exists for key " + key); } else if(value.getVersion().compare(clock) == Occurred.CONCURRENTLY) { throw new ObsoleteVersionException("Concurrent Operation not allowed on Metadata.");
while(iter.hasNext()) { Versioned<byte[]> curr = iter.next(); Occurred occurred = value.getVersion().compare(curr.getVersion()); if(occurred == Occurred.BEFORE) { throw new ObsoleteVersionException("Key "
} else if(maxVersion.compare(curVersion) == Occurred.BEFORE) { maxVersion = curVersion;
Versioned<byte[]> currentValue = iter.next(); Version currentVersion = currentValue.getVersion(); if(currentVersion.compare(maxVersion) == Occurred.BEFORE) { iter.remove();
@Override /** * FIXME There is a problem here.. Since the versioning is on the file level, SystemStoreClient.put() * will throw OVE, on the insert of the second key, value pair.Ideally, the version should be persisted * along with the entries in the file too.. */ public void put(ByteArray key, Versioned<byte[]> value, byte[] transforms) throws VoldemortException { StoreUtils.assertValidKey(key); // Validate the Vector clock VectorClock clock = readVersion(); if(clock != null) { if(value.getVersion().compare(clock) == Occurred.BEFORE) { throw new ObsoleteVersionException("A successor version " + clock + " to this " + value.getVersion() + " exists for the current file : " + getName()); } else if(value.getVersion().compare(clock) == Occurred.CONCURRENTLY) { throw new ObsoleteVersionException("Concurrent Operation not allowed on Metadata."); } } // Update the cache copy this.metadataMap.put(new String(key.get()), new String(value.getValue())); // Flush the data to the file this.flushData(); // Persist the new Vector clock writeVersion((VectorClock) value.getVersion()); }
Occurred occurred = value.getVersion().compare(versioned.getVersion()); if(occurred == Occurred.BEFORE) throw new ObsoleteVersionException("Obsolete version for key '" + key
while(results.next()) { VectorClock version = new VectorClock(results.getBytes("version_")); Occurred occurred = value.getVersion().compare(version); if(occurred == Occurred.BEFORE) throw new ObsoleteVersionException("Attempt to put version "
private void verifyResults(Version oldVersion, Version newVersion, Versioned<String> getVersioned, String newValue) { // make sure version advances between two puts assertEquals("Versions of put did not advance", Occurred.AFTER, newVersion.compare(oldVersion)); // make sure version of last put equals version of the get assertEquals("Version of put is larger than version of get", Occurred.BEFORE /* before can mean equal, funny! */, newVersion.compare(getVersioned.getVersion())); assertEquals("Version of put is smaller than version of get", Occurred.BEFORE /* before can mean equal, funny! */, getVersioned.getVersion().compare(newVersion)); // make sure we get what we just put in assertEquals("Value of put does not match value of get", newValue, getVersioned.getValue()); } }
while(iter.hasNext()) { Versioned<byte[]> curr = iter.next(); Occurred occurred = value.getVersion().compare(curr.getVersion()); if(occurred == Occurred.BEFORE) throw new ObsoleteVersionException("Key "
Versioned<byte[]> curr = iter.next(); Version currentVersion = curr.getVersion(); if(currentVersion.compare(version) == Occurred.BEFORE) { iter.remove(); numDeletedVersions++;
Versioned<byte[]> curr = iter.next(); Version currentVersion = curr.getVersion(); if(currentVersion.compare(version) == Occurred.BEFORE) { iter.remove(); numDeletedVersions++;