use of voldemort.store.PersistenceFailureException 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.store.PersistenceFailureException in project voldemort by voldemort.
the class RocksDbStorageEngine method multiVersionPut.
@Override
public List<Versioned<byte[]>> multiVersionPut(ByteArray key, List<Versioned<byte[]>> values) {
// TODO Implement getandLock() and putAndUnlock() and then remove this
// method
StoreUtils.assertValidKey(key);
long startTimeNs = -1;
if (logger.isTraceEnabled())
startTimeNs = System.nanoTime();
List<Versioned<byte[]>> currentValues = null;
List<Versioned<byte[]>> obsoleteVals = null;
synchronized (this.locks.lockFor(key.get())) {
/*
* Get the existing values. Make sure to "get" from the underlying
* storage instead of using the get method described in this class.
* Invoking the get method from this class will unnecessarily double
* prefix the key in case of PartitionPrefixedRocksdbStorageEngine
* and can cause unpredictable results.
*/
try {
byte[] result = getRocksDB().get(storeHandle, key.get());
if (result != null) {
currentValues = StoreBinaryFormat.fromByteArray(result);
} else {
currentValues = new ArrayList<Versioned<byte[]>>();
}
} catch (RocksDBException e) {
logger.error(e);
throw new PersistenceFailureException(e);
}
obsoleteVals = resolveAndConstructVersionsToPersist(currentValues, values);
try {
getRocksDB().put(storeHandle, key.get(), StoreBinaryFormat.toByteArray(currentValues));
} catch (RocksDBException e) {
logger.error(e);
throw new PersistenceFailureException(e);
} finally {
if (logger.isTraceEnabled()) {
String valueStr = "";
for (Versioned<byte[]> val : currentValues) {
valueStr += val + ",";
}
logger.trace("Completed PUT (" + getName() + ") to key " + key + " (keyRef: " + System.identityHashCode(key) + " values " + valueStr + " in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
}
}
}
return obsoleteVals;
}
use of voldemort.store.PersistenceFailureException in project voldemort by voldemort.
the class RocksDbStorageEngine method getValueForKey.
private List<Versioned<byte[]>> getValueForKey(ByteArray key, byte[] transforms) throws PersistenceFailureException {
long startTimeNs = -1;
if (logger.isTraceEnabled())
startTimeNs = System.nanoTime();
List<Versioned<byte[]>> value = null;
try {
byte[] result = getRocksDB().get(storeHandle, key.get());
if (result != null) {
value = StoreBinaryFormat.fromByteArray(result);
} else {
return Collections.emptyList();
}
} catch (RocksDBException e) {
logger.error(e);
throw new PersistenceFailureException(e);
} finally {
if (logger.isTraceEnabled()) {
logger.trace("Completed GET (" + getName() + ") from key " + key + " (keyRef: " + System.identityHashCode(key) + ") in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
}
}
return value;
}
use of voldemort.store.PersistenceFailureException in project voldemort by voldemort.
the class RocksDbStorageEngine method getAll.
@Override
public Map<ByteArray, List<Versioned<byte[]>>> getAll(Iterable<ByteArray> keys, Map<ByteArray, byte[]> transforms) throws VoldemortException {
// TODO Does RocksDB multiget supports atomicity ?
StoreUtils.assertValidKeys(keys);
long startTimeNs = -1;
if (logger.isTraceEnabled())
startTimeNs = System.nanoTime();
Map<ByteArray, List<Versioned<byte[]>>> results = null;
try {
results = StoreUtils.getAll(this, keys, transforms);
} catch (PersistenceFailureException e) {
logger.error(e);
throw new PersistenceFailureException(e);
} finally {
if (logger.isTraceEnabled()) {
String keyStr = "";
for (ByteArray key : keys) keyStr += key + " ";
logger.trace("Completed GETALL (" + getName() + ") from keys " + keyStr + " in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
}
}
return results;
}
use of voldemort.store.PersistenceFailureException in project voldemort by voldemort.
the class RocksDbStorageEngine method put.
@Override
public void put(ByteArray key, Versioned<byte[]> value, byte[] transforms) throws PersistenceFailureException {
StoreUtils.assertValidKey(key);
long startTimeNs = -1;
if (logger.isTraceEnabled())
startTimeNs = System.nanoTime();
synchronized (this.locks.lockFor(key.get())) {
/*
* Get the existing values. Make sure to "get" from the underlying
* storage instead of using the get method described in this class.
* Invoking the get method from this class will unnecessarily double
* prefix the key in case of PartitionPrefixedRocksdbStorageEngine
* and can cause unpredictable results.
*/
List<Versioned<byte[]>> currentValues;
try {
byte[] result = getRocksDB().get(storeHandle, key.get());
if (result != null) {
currentValues = StoreBinaryFormat.fromByteArray(result);
} else {
currentValues = Collections.emptyList();
}
} catch (RocksDBException e) {
logger.error(e);
throw new PersistenceFailureException(e);
}
if (currentValues.size() > 0) {
// compare vector clocks and throw out old ones, for updates
Iterator<Versioned<byte[]>> iter = currentValues.iterator();
while (iter.hasNext()) {
Versioned<byte[]> curr = iter.next();
Occurred occurred = value.getVersion().compare(curr.getVersion());
if (occurred == Occurred.BEFORE) {
throw new ObsoleteVersionException("Key " + new String(hexCodec.encode(key.get())) + " " + value.getVersion().toString() + " is obsolete, it is no greater than the current version of " + curr.getVersion().toString() + ".");
} else if (occurred == Occurred.AFTER) {
iter.remove();
}
}
} else {
// if value does not exist add the value from put request to
// existing values
currentValues = new ArrayList<Versioned<byte[]>>(1);
}
currentValues.add(value);
try {
getRocksDB().put(storeHandle, key.get(), StoreBinaryFormat.toByteArray(currentValues));
} catch (RocksDBException e) {
logger.error(e);
throw new PersistenceFailureException(e);
} finally {
if (logger.isTraceEnabled()) {
logger.trace("Completed PUT (" + getName() + ") to key " + key + " (keyRef: " + System.identityHashCode(key) + " value " + value + " in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
}
}
}
}
Aggregations