private static void printVersions(Versioned<Properties> versionedProps) { Version version = versionedProps.getVersion(); Properties props = versionedProps.getValue(); System.out.println("Version value " + version); for(String propName: props.stringPropertyNames()) { SubCommandMetaCheckVersion.printProperty(propName, props.getProperty(propName)); } }
public UpdateElementById(VListKey<K> key, Versioned<E> element) { _key = key; _element = element.getValue(); _version = element.getVersion(); }
@Override public List<Version> getVersions(String key) { List<Versioned<String>> values = get(key, (String) null); List<Version> versions = new ArrayList<Version>(values.size()); for(Versioned<?> value: values) { versions.add(value.getVersion()); } return versions; }
@Override public List<Version> getVersions(ByteArray key) { List<Versioned<byte[]>> values = get(key, null); List<Version> versions = new ArrayList<Version>(values.size()); for(Versioned<?> value: values) { versions.add(value.getVersion()); } return versions; }
protected void printVersioned(Versioned<Object> v) { if(v == null) { commandOutput.println("null"); } else { commandOutput.print(v.getVersion()); commandOutput.print(": "); printObject(v.getValue()); commandOutput.println(); } }
@Override public boolean equals(Object o) { if(o == this) return true; else if(!(o instanceof Versioned<?>)) return false; Versioned<?> versioned = (Versioned<?>) o; return Objects.equal(getVersion(), versioned.getVersion()) && Utils.deepEquals(getValue(), versioned.getValue()); }
public byte[] toBytes(Versioned<T> versioned) { byte[] versionBytes = null; if(versioned.getVersion() == null) versionBytes = new byte[] { -1 }; else versionBytes = ((VectorClock) versioned.getVersion()).toBytes(); byte[] objectBytes = innerSerializer.toBytes(versioned.getValue()); return ByteUtils.cat(versionBytes, objectBytes); }
@Override public boolean delete(K key) { Versioned<V> versioned = get(key); if(versioned == null) return false; return this.clientStore.delete(key, versioned.getVersion()); }
@Override public void put(K key, Versioned<byte[]> value, byte[] transforms) throws VoldemortException { try { getInnerStore().put(key, new Versioned<byte[]>(IOUtils.toByteArray(new GZIPInputStream(new ByteArrayInputStream(value.getValue()))), value.getVersion()), transforms); } catch(IOException e) { throw new VoldemortException(e); } }
private void logFailedProxyPutIfNeeded(Exception e) { redirectingStore.reportProxyPutFailure(); // only log OVE if trace debugging is on. if(e instanceof ObsoleteVersionException && !logger.isTraceEnabled()) { return; } logger.error("Exception in proxy put for proxyNode: " + destinationNode + " from node:" + metadata.getNodeId() + " on key " + ByteUtils.toHexString(key.get()) + " Version:" + value.getVersion(), e); } }
@Override public List<Versioned<V>> get(K key, T transforms) throws VoldemortException { List<Versioned<byte[]>> found = store.get(keyToBytes(key), (transformsSerializer != null && transforms != null) ? transformsSerializer.toBytes(transforms) : null); List<Versioned<V>> results = new ArrayList<Versioned<V>>(found.size()); for(Versioned<byte[]> versioned: found) results.add(new Versioned<V>(valueSerializer.toObject(versioned.getValue()), versioned.getVersion())); return results; }
private Versioned<byte[]> incremented(Versioned<byte[]> versioned, int nodeId) { return new Versioned<byte[]>(versioned.getValue(), ((VectorClock) versioned.getVersion()).incremented(nodeId, time.getMilliseconds())); }
public Versioned<E> peekVersioned() { Versioned<VListNode<E>> node = getListNode(0); if(node == null) { return null; } else { return new Versioned<E>(node.getValue().getValue(), node.getVersion()); } }
private Versioned<byte[]> inflateValue(Versioned<byte[]> versioned) throws VoldemortException { byte[] inflatedData = null; try { inflatedData = valueCompressionStrategy.inflate(versioned.getValue()); } catch(IOException e) { throw new VoldemortException(e); } return new Versioned<byte[]>(inflatedData, versioned.getVersion()); }
private void checkValues(Versioned<byte[]> value, List<Versioned<byte[]>> list, ByteArray key) { assertEquals("should return exactly one value ", 1, list.size()); assertEquals("should return the last saved version", value.getVersion(), list.get(0) .getVersion()); assertEquals("should return the last saved value (key:" + ByteUtils.getString(key.get(), "UTF-8") + ")", new String(value.getValue()), new String(list.get(0).getValue())); }
public void testClone() { Versioned<Integer> v1 = getVersioned(2, 1, 2, 3); Versioned<Integer> v2 = v1.cloneVersioned(); assertEquals(v1, v2); assertTrue(v1 != v2); assertTrue(v1.getVersion() != v2.getVersion()); ((VectorClock) v2.getVersion()).incrementVersion(1, System.currentTimeMillis()); assertTrue(!v1.equals(v2)); }
protected void assertEquals(String message, Versioned<V> v1, Versioned<V> v2) { String assertTrueMessage = v1 + " != " + v2 + "."; if(message != null) assertTrueMessage += message; assertTrue(assertTrueMessage, valuesEqual(v1.getValue(), v2.getValue())); assertEquals(message, v1.getVersion(), v2.getVersion()); }
@Override public void truncate() { ViewIterator iterator = new ViewIterator(target.entries()); while(iterator.hasNext()) { Pair<ByteArray, Versioned<byte[]>> pair = iterator.next(); target.delete(pair.getFirst(), pair.getSecond().getVersion()); } }
@Test public void testSimpleGetAndPut() { for(int i = 0; i <= TEST_RUNS; i++) { ByteArray key = getValidKey(); VectorClock clock = (VectorClock) metadataStore.get(key, null).get(0).getVersion(); Versioned<byte[]> value = new Versioned<byte[]>(getValidValue(key), clock.incremented(0, 1)); metadataStore.put(key, value, null); checkValues(value, metadataStore.get(key, null), key); } }
@Test public void testGet() { assertEquals("GET of non-existant key should return null.", null, client.get("k")); client.put("k", "v"); assertEquals("After a PUT get should return the value", "v", client.get("k").getValue()); assertNotNull("The version of the value found should be non-null", client.get("k") .getVersion()); }