use of voldemort.store.PersistenceFailureException in project voldemort by voldemort.
the class RocksdbStorageEngineAPITest method testUnversionedDelete.
@Test
public void testUnversionedDelete() {
logger.info("*********** testing unversioned delete ***********");
// generate random bytes for key
ByteArray key = generateRandomKeys(100);
// generate random bytes for values
Versioned<byte[]> versionedValue = generateVersionedValue(100);
try {
// Do put
this.rocksDbStore.put(key, versionedValue, null);
} catch (PersistenceFailureException pfe) {
Assert.fail("initial put failed unexpectedly. Exception: " + pfe.getMessage());
}
testDelete(key, null);
}
use of voldemort.store.PersistenceFailureException in project voldemort by voldemort.
the class BdbStorageEngine method getAll.
@Override
public Map<ByteArray, List<Versioned<byte[]>>> getAll(Iterable<ByteArray> keys, Map<ByteArray, byte[]> transforms) throws VoldemortException {
StoreUtils.assertValidKeys(keys);
Map<ByteArray, List<Versioned<byte[]>>> results = null;
long startTimeNs = -1;
if (logger.isTraceEnabled())
startTimeNs = System.nanoTime();
try {
results = StoreUtils.getAll(this, keys, transforms);
} catch (PersistenceFailureException pfe) {
throw pfe;
} 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 BdbStorageEngine method delete.
@Override
public boolean delete(ByteArray key, Version version) throws PersistenceFailureException {
StoreUtils.assertValidKey(key);
long startTimeNs = -1;
if (logger.isTraceEnabled())
startTimeNs = System.nanoTime();
Transaction transaction = null;
try {
transaction = this.environment.beginTransaction(null, null);
DatabaseEntry keyEntry = new DatabaseEntry(key.get());
if (version == null) {
// unversioned delete. Just blow away the whole thing
OperationStatus status = getBdbDatabase().delete(transaction, keyEntry);
if (OperationStatus.SUCCESS == status)
return true;
else
return false;
} else {
// versioned deletes; need to determine what to delete
DatabaseEntry valueEntry = new DatabaseEntry();
// do a get for the existing values
OperationStatus status = getBdbDatabase().get(transaction, keyEntry, valueEntry, LockMode.RMW);
// key does not exist to begin with.
if (OperationStatus.NOTFOUND == status)
return false;
List<Versioned<byte[]>> vals = StoreBinaryFormat.fromByteArray(valueEntry.getData());
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
valueEntry.setData(StoreBinaryFormat.toByteArray(vals));
getBdbDatabase().put(transaction, keyEntry, valueEntry);
} else {
// we have deleted all the versions; so get rid of the entry
// in the database
getBdbDatabase().delete(transaction, keyEntry);
}
return numDeletedVersions > 0;
}
} catch (DatabaseException e) {
this.bdbEnvironmentStats.reportException(e);
logger.error(e);
throw new PersistenceFailureException(e);
} finally {
attemptCommit(transaction);
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 BdbStorageEngine method put.
@Override
public void put(ByteArray key, Versioned<byte[]> value, byte[] transforms) throws PersistenceFailureException {
long startTimeNs = -1;
if (logger.isTraceEnabled())
startTimeNs = System.nanoTime();
StoreUtils.assertValidKey(key);
DatabaseEntry keyEntry = new DatabaseEntry(key.get());
DatabaseEntry valueEntry = new DatabaseEntry();
boolean succeeded = false;
Transaction transaction = null;
List<Versioned<byte[]>> vals = null;
try {
transaction = environment.beginTransaction(null, null);
// do a get for the existing values
OperationStatus status = getBdbDatabase().get(transaction, keyEntry, valueEntry, LockMode.RMW);
if (OperationStatus.SUCCESS == status) {
// update
vals = StoreBinaryFormat.fromByteArray(valueEntry.getData());
// compare vector clocks and throw out old ones, for updates
Iterator<Versioned<byte[]>> iter = vals.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 {
// insert
vals = new ArrayList<Versioned<byte[]>>(1);
}
// update the new value
vals.add(value);
valueEntry.setData(StoreBinaryFormat.toByteArray(vals));
status = getBdbDatabase().put(transaction, keyEntry, valueEntry);
if (status != OperationStatus.SUCCESS)
throw new PersistenceFailureException("Put operation failed with status: " + status);
succeeded = true;
} catch (DatabaseException e) {
this.bdbEnvironmentStats.reportException(e);
logger.error("Error in put for store " + this.getName(), e);
throw new PersistenceFailureException(e);
} finally {
if (succeeded)
attemptCommit(transaction);
else
attemptAbort(transaction);
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());
}
}
}
use of voldemort.store.PersistenceFailureException in project voldemort by voldemort.
the class BdbStorageEngine method get.
@Override
public List<Versioned<byte[]>> get(ByteArray key, byte[] transforms) throws PersistenceFailureException {
StoreUtils.assertValidKey(key);
DatabaseEntry keyEntry = new DatabaseEntry(key.get());
DatabaseEntry valueEntry = new DatabaseEntry();
long startTimeNs = -1;
if (logger.isTraceEnabled())
startTimeNs = System.nanoTime();
try {
// uncommitted reads are perfectly fine now, since we have no
// je-delete() in put()
OperationStatus status = getBdbDatabase().get(null, keyEntry, valueEntry, readLockMode);
if (OperationStatus.SUCCESS == status) {
return StoreBinaryFormat.fromByteArray(valueEntry.getData());
} else {
return Collections.emptyList();
}
} catch (DatabaseException e) {
this.bdbEnvironmentStats.reportException(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());
}
}
}
Aggregations