use of voldemort.versioning.Version in project voldemort by voldemort.
the class RocksDbStorageEngine method delete.
@Override
public boolean delete(ByteArray key, Version version) throws PersistenceFailureException {
StoreUtils.assertValidKey(key);
long startTimeNs = -1;
if (logger.isTraceEnabled())
startTimeNs = System.nanoTime();
synchronized (this.locks.lockFor(key.get())) {
try {
byte[] value = getRocksDB().get(storeHandle, key.get());
if (value == null) {
return false;
}
if (version == null) {
// unversioned delete. Just blow away the whole thing
getRocksDB().remove(storeHandle, key.get());
return true;
} else {
// versioned deletes; need to determine what to delete
List<Versioned<byte[]>> vals = StoreBinaryFormat.fromByteArray(value);
Iterator<Versioned<byte[]>> iter = vals.iterator();
int numVersions = vals.size();
int numDeletedVersions = 0;
// supplied version
while (iter.hasNext()) {
Versioned<byte[]> curr = iter.next();
Version currentVersion = curr.getVersion();
if (currentVersion.compare(version) == Occurred.BEFORE) {
iter.remove();
numDeletedVersions++;
}
}
if (numDeletedVersions < numVersions) {
// we still have some valid versions
value = StoreBinaryFormat.toByteArray(vals);
getRocksDB().put(storeHandle, key.get(), value);
} else {
// we have deleted all the versions; so get rid of the
// entry
// in the database
getRocksDB().remove(storeHandle, key.get());
}
return numDeletedVersions > 0;
}
} catch (RocksDBException e) {
logger.error(e);
throw new PersistenceFailureException(e);
} finally {
if (logger.isTraceEnabled()) {
logger.trace("Completed DELETE (" + getName() + ") of key " + ByteUtils.toHexString(key.get()) + " (keyRef: " + System.identityHashCode(key) + ") in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
}
}
}
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class UpdateElementById method update.
@Override
public void update(StoreClient<Map<String, Object>, Map<String, Object>> storeClient) {
Versioned<Map<String, Object>> nodeMap = storeClient.get(_key.mapValue());
if (nodeMap == null)
throw new IndexOutOfBoundsException("invalid id " + _key.getId());
Version version = (_version != null) ? _version : nodeMap.getVersion();
VListNode<E> listNode = VListNode.valueOf(nodeMap.getValue());
if (!listNode.isStable()) {
throw new ObsoleteVersionException("node " + _key.getId() + " not stable.");
}
_result = listNode.getValue();
VListNode<E> newNode = new VListNode<E>(_element, listNode.getId(), listNode.getPreviousId(), listNode.getNextId(), true);
storeClient.put(_key.mapValue(), new Versioned<Map<String, Object>>(newNode.mapValue(), version));
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class GetVersionRequestHandler method writeResponse.
@Override
public void writeResponse(DataOutputStream outputStream) throws IOException {
outputStream.writeShort(0);
outputStream.writeInt(results.size());
for (Version v : results) {
byte[] clock = ((VectorClock) v).toBytes();
outputStream.writeInt(clock.length);
outputStream.write(clock);
}
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class DynamicTimeoutStoreClient method putWithCustomTimeout.
/**
* Performs a put operation with the specified composite request object
*
* @param requestWrapper A composite request object containing the key and
* value
* @return Version of the value for the successful put
*/
public Version putWithCustomTimeout(CompositeVoldemortRequest<K, V> requestWrapper) {
validateTimeout(requestWrapper.getRoutingTimeoutInMs());
List<Versioned<V>> versionedValues;
long startTime = System.currentTimeMillis();
String keyHexString = "";
if (logger.isDebugEnabled()) {
ByteArray key = (ByteArray) requestWrapper.getKey();
keyHexString = RestUtils.getKeyHexString(key);
logger.debug("PUT requested for key: " + keyHexString + " , for store: " + this.storeName + " at time(in ms): " + startTime + " . Nested GET and PUT VERSION requests to follow ---");
}
// We use the full timeout for doing the Get. In this, we're being
// optimistic that the subsequent put might be faster such that all the
// steps might finish within the allotted time
requestWrapper.setResolveConflicts(true);
versionedValues = getWithCustomTimeout(requestWrapper);
Versioned<V> versioned = getItemOrThrow(requestWrapper.getKey(), null, versionedValues);
long endTime = System.currentTimeMillis();
if (versioned == null)
versioned = Versioned.value(requestWrapper.getRawValue(), new VectorClock());
else
versioned.setObject(requestWrapper.getRawValue());
// This should not happen unless there's a bug in the
// getWithCustomTimeout
long timeLeft = requestWrapper.getRoutingTimeoutInMs() - (endTime - startTime);
if (timeLeft <= 0) {
throw new StoreTimeoutException("PUT request timed out");
}
CompositeVersionedPutVoldemortRequest<K, V> putVersionedRequestObject = new CompositeVersionedPutVoldemortRequest<K, V>(requestWrapper.getKey(), versioned, timeLeft);
putVersionedRequestObject.setRequestOriginTimeInMs(requestWrapper.getRequestOriginTimeInMs());
Version result = putVersionedWithCustomTimeout(putVersionedRequestObject);
long endTimeInMs = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("PUT response received for key: " + keyHexString + " , for store: " + this.storeName + " at time(in ms): " + endTimeInMs);
}
return result;
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class DefaultStoreClient method put.
public Version put(K key, V value) {
Version version = getVersionForPut(key);
Versioned<V> versioned = Versioned.value(value, version);
return put(key, versioned);
}
Aggregations