use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.
the class JEObjectDatabase method getRawInternal.
@Override
protected InputStream getRawInternal(final ObjectId id, final boolean failIfNotFound) {
checkOpen();
Preconditions.checkNotNull(id, "id");
DatabaseEntry key = new DatabaseEntry(id.getRawValue());
DatabaseEntry data = new DatabaseEntry();
final LockMode lockMode = LockMode.READ_UNCOMMITTED;
Transaction transaction = null;
OperationStatus operationStatus = objectDb.get(transaction, key, data, lockMode);
if (NOTFOUND.equals(operationStatus)) {
if (failIfNotFound) {
throw new IllegalArgumentException("Object does not exist: " + id.toString() + " at " + env.getHome().getAbsolutePath());
}
return null;
}
final byte[] cData = data.getData();
return new ByteArrayInputStream(cData);
}
use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.
the class JEObjectDatabase method putInternal.
private OperationStatus putInternal(final ObjectId id, final byte[] rawData, Transaction transaction) {
OperationStatus status;
final byte[] rawKey = id.getRawValue();
DatabaseEntry key = new DatabaseEntry(rawKey);
DatabaseEntry data = new DatabaseEntry(rawData);
status = objectDb.putNoOverwrite(transaction, key, data);
return status;
}
use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.
the class JEObjectDatabase method exists.
/**
* @see org.locationtech.geogig.storage.ObjectDatabase#exists(org.locationtech.geogig.api.ObjectId)
*/
@Override
public boolean exists(final ObjectId id) {
checkOpen();
Preconditions.checkNotNull(id, "id");
DatabaseEntry key = new DatabaseEntry(id.getRawValue());
DatabaseEntry data = new DatabaseEntry();
// tell db not to retrieve data
data.setPartial(0, 0, true);
final LockMode lockMode = LockMode.READ_UNCOMMITTED;
Transaction transaction = null;
OperationStatus status = objectDb.get(transaction, key, data, lockMode);
return SUCCESS == status;
}
use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.
the class JEObjectDatabase method deleteAll.
@Override
public long deleteAll(Iterator<ObjectId> ids, final BulkOpListener listener) {
checkWritable();
long count = 0;
UnmodifiableIterator<List<ObjectId>> partition = partition(ids, getBulkPartitionSize());
final DatabaseEntry data = new DatabaseEntry();
// do not retrieve data
data.setPartial(0, 0, true);
while (partition.hasNext()) {
List<ObjectId> nextIds = Lists.newArrayList(partition.next());
Collections.sort(nextIds);
final Transaction transaction = newTransaction();
CursorConfig cconfig = new CursorConfig();
final Cursor cursor = objectDb.openCursor(transaction, cconfig);
try {
DatabaseEntry key = new DatabaseEntry(new byte[ObjectId.NUM_BYTES]);
for (ObjectId id : nextIds) {
// copy id to key object without allocating new byte[]
id.getRawValue(key.getData());
OperationStatus status = cursor.getSearchKey(key, data, LockMode.DEFAULT);
if (OperationStatus.SUCCESS.equals(status)) {
OperationStatus delete = cursor.delete();
if (OperationStatus.SUCCESS.equals(delete)) {
listener.deleted(id);
count++;
} else {
listener.notFound(id);
}
} else {
listener.notFound(id);
}
}
cursor.close();
} catch (Exception e) {
cursor.close();
abort(transaction);
Throwables.propagate(e);
}
commit(transaction);
}
return count;
}
use of com.sleepycat.je.OperationStatus 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());
}
}
}
Aggregations