use of com.sleepycat.je.DatabaseException 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());
}
}
}
use of com.sleepycat.je.DatabaseException in project voldemort by voldemort.
the class BdbStorageEngine method putAndUnlock.
@Override
public void putAndUnlock(ByteArray key, KeyLockHandle<byte[]> handle) {
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;
try {
transaction = (Transaction) handle.getKeyLock();
valueEntry.setData(StoreBinaryFormat.toByteArray(handle.getValues()));
OperationStatus status = getBdbDatabase().put(transaction, keyEntry, valueEntry);
if (status != OperationStatus.SUCCESS)
throw new PersistenceFailureException("putAndUnlock operation failed with status: " + status);
succeeded = true;
} catch (DatabaseException e) {
this.bdbEnvironmentStats.reportException(e);
logger.error("Error in putAndUnlock for store " + this.getName(), e);
throw new PersistenceFailureException(e);
} finally {
if (succeeded)
attemptCommit(transaction);
else
attemptAbort(transaction);
if (logger.isTraceEnabled()) {
logger.trace("Completed PUTANDUNLOCK (" + getName() + ") to key " + key + " (keyRef: " + System.identityHashCode(key) + " in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
}
handle.close();
}
}
use of com.sleepycat.je.DatabaseException in project sessdb by ppdai.
the class BdbBenchmark method open.
@Override
public void open() {
try {
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setCachePercent(90);
File file = new File(databaseDir_);
if (!file.exists()) {
file.mkdirs();
}
env_ = new Environment(file, envConfig);
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
bdb_ = env_.openDatabase(null, BdbBenchmark.DATABASE_NAME, dbConfig);
} catch (DatabaseException e) {
e.printStackTrace();
}
}
use of com.sleepycat.je.DatabaseException in project leopard by tanhaichao.
the class IdTransverterBdbImpl method transform.
@Override
public String transform(String tableName, String id) {
try {
Bdb database = bdb.getDatabase(tableName);
// System.err.println("getString tableName:" + tableName + " id:" + id + " count:" + bdb.count());
String newId = database.getString(id);
return newId;
} catch (DatabaseException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of com.sleepycat.je.DatabaseException in project leopard by tanhaichao.
the class IdTransverterBdbImpl method add.
@Override
public boolean add(String tableName, String id, String newId) {
try {
Bdb database = bdb.getDatabase(tableName);
System.err.println("add tableName:" + tableName + " id:" + id);
return database.putNoDupData(id, newId);
} catch (DuplicateEntryException e) {
logger.warn(e.getMessage());
return false;
} catch (DatabaseException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
Aggregations