use of com.sleepycat.je.OperationStatus in project voldemort by voldemort.
the class BdbRevertPidScanToNewDup method transfer.
@Override
public void transfer() throws Exception {
cursor = srcDB.openCursor(null, null);
DatabaseEntry keyEntry = new DatabaseEntry();
DatabaseEntry valueEntry = new DatabaseEntry();
List<Versioned<byte[]>> vals;
long startTime = System.currentTimeMillis();
int scanCount = 0;
int keyCount = 0;
while (cursor.getNext(keyEntry, valueEntry, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
keyCount++;
vals = StoreBinaryFormat.fromByteArray(valueEntry.getData());
scanCount += vals.size();
// pull out the real key
byte[] stripedKey = StoreBinaryFormat.extractKey(keyEntry.getData());
OperationStatus putStatus = dstDB.put(null, new DatabaseEntry(stripedKey), valueEntry);
if (OperationStatus.SUCCESS != putStatus) {
String errorStr = "Put failed with " + putStatus + " for key" + BdbConvertData.writeAsciiString(keyEntry.getData());
logger.error(errorStr);
throw new Exception(errorStr);
}
if (scanCount % 1000000 == 0)
logger.info("Reverted " + scanCount + " entries in " + (System.currentTimeMillis() - startTime) / 1000 + " secs");
}
logger.info("Reverted " + scanCount + " entries and " + keyCount + " keys in " + (System.currentTimeMillis() - startTime) / 1000 + " secs");
}
use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.
the class JEObjectDatabase method lookUpInternal.
@Override
protected List<ObjectId> lookUpInternal(final byte[] partialId) {
checkOpen();
DatabaseEntry key;
{
byte[] keyData = partialId.clone();
key = new DatabaseEntry(keyData);
}
DatabaseEntry data = new DatabaseEntry();
// do not retrieve data
data.setPartial(0, 0, true);
List<ObjectId> matches;
CursorConfig cursorConfig = new CursorConfig();
cursorConfig.setReadUncommitted(true);
Transaction transaction = null;
Cursor cursor = objectDb.openCursor(transaction, cursorConfig);
try {
// position cursor at the first closest key to the one looked up
OperationStatus status = cursor.getSearchKeyRange(key, data, LockMode.READ_UNCOMMITTED);
if (SUCCESS.equals(status)) {
matches = new ArrayList<ObjectId>(2);
final byte[] compKey = new byte[partialId.length];
while (SUCCESS.equals(status)) {
byte[] keyData = key.getData();
System.arraycopy(keyData, 0, compKey, 0, compKey.length);
if (Arrays.equals(partialId, compKey)) {
matches.add(new ObjectId(keyData));
} else {
break;
}
status = cursor.getNext(key, data, LockMode.READ_UNCOMMITTED);
}
} else {
matches = Collections.emptyList();
}
return matches;
} finally {
cursor.close();
}
}
use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.
the class JEObjectDatabase method delete.
@Override
public boolean delete(final ObjectId id) {
checkWritable();
final byte[] rawKey = id.getRawValue();
final DatabaseEntry key = new DatabaseEntry(rawKey);
final Transaction transaction = newTransaction();
final OperationStatus status;
try {
status = objectDb.delete(transaction, key);
commit(transaction);
} catch (RuntimeException e) {
abort(transaction);
throw e;
}
return SUCCESS.equals(status);
}
use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.
the class JEObjectDatabase method putInternal.
@Override
protected boolean putInternal(final ObjectId id, final byte[] rawData) {
checkWritable();
final Transaction transaction = newTransaction();
final OperationStatus status;
try {
status = putInternal(id, rawData, transaction);
commit(transaction);
} catch (RuntimeException e) {
abort(transaction);
throw e;
}
final boolean didntExist = SUCCESS.equals(status);
return didntExist;
}
use of com.sleepycat.je.OperationStatus in project sirix by sirixdb.
the class BerkeleyStorage method exists.
@Override
public boolean exists() throws SirixIOException {
final DatabaseEntry valueEntry = new DatabaseEntry();
final DatabaseEntry keyEntry = new DatabaseEntry();
boolean returnVal = false;
try {
final Reader reader = new BerkeleyReader(mEnv, mDatabase, mByteHandler);
TupleBinding.getPrimitiveBinding(Long.class).objectToEntry(-1l, keyEntry);
final OperationStatus status = mDatabase.get(null, keyEntry, valueEntry, LockMode.DEFAULT);
if (status == OperationStatus.SUCCESS) {
returnVal = true;
}
reader.close();
} catch (final DatabaseException exc) {
throw new SirixIOException(exc);
}
return returnVal;
}
Aggregations