use of com.sleepycat.je.OperationStatus in project janusgraph by JanusGraph.
the class BerkeleyJEKeyValueStore method delete.
@Override
public void delete(StaticBuffer key, StoreTransaction txh) throws BackendException {
log.trace("Deletion");
Transaction tx = getTransaction(txh);
try {
log.trace("db={}, op=delete, tx={}", name, txh);
OperationStatus status = db.delete(tx, key.as(ENTRY_FACTORY));
if (status != OperationStatus.SUCCESS && status != OperationStatus.NOTFOUND) {
throw new PermanentBackendException("Could not remove: " + status);
}
} catch (DatabaseException e) {
throw new PermanentBackendException(e);
}
}
use of com.sleepycat.je.OperationStatus in project janusgraph by JanusGraph.
the class BerkeleyJEKeyValueStore method insert.
public void insert(StaticBuffer key, StaticBuffer value, StoreTransaction txh, boolean allowOverwrite, Integer ttl) throws BackendException {
Transaction tx = getTransaction(txh);
OperationStatus status;
log.trace("db={}, op=insert, tx={}", name, txh);
WriteOptions writeOptions = getWriteOptions(txh);
if (ttl != null && ttl > 0) {
int convertedTtl = ttlConverter.apply(ttl);
writeOptions.setTTL(convertedTtl, TimeUnit.HOURS);
}
if (allowOverwrite) {
OperationResult result = db.put(tx, key.as(ENTRY_FACTORY), value.as(ENTRY_FACTORY), Put.OVERWRITE, writeOptions);
EnvironmentFailureException.assertState(result != null);
status = OperationStatus.SUCCESS;
} else {
OperationResult result = db.put(tx, key.as(ENTRY_FACTORY), value.as(ENTRY_FACTORY), Put.NO_OVERWRITE, writeOptions);
status = result == null ? OperationStatus.KEYEXIST : OperationStatus.SUCCESS;
}
if (status != OperationStatus.SUCCESS) {
throw new PermanentBackendException("Key already exists on no-overwrite.");
}
}
use of com.sleepycat.je.OperationStatus in project qpid-broker-j by apache.
the class UpgradeFrom6To7 method performUpgrade.
@Override
public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent) {
reportStarting(environment, 6);
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(true);
Database versionDb = environment.openDatabase(null, "CONFIG_VERSION", dbConfig);
if (versionDb.count() == 0L) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
IntegerBinding.intToEntry(DEFAULT_CONFIG_VERSION, value);
ByteBinding.byteToEntry((byte) 0, key);
OperationStatus status = versionDb.put(null, key, value);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Error initialising config version: " + status);
}
}
versionDb.close();
reportFinished(environment, 7);
}
use of com.sleepycat.je.OperationStatus in project qpid-broker-j by apache.
the class BDBLinkStore method save.
private void save(Database database, Transaction txn, final LinkDefinition<Source, Target> link) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
LinkKey linkKey = new LinkKey(link);
LinkKeyEntryBinding.getInstance().objectToEntry(linkKey, key);
LinkValueEntryBinding.getInstance().objectToEntry(new LinkValue(link), value);
// TODO: create transaction
OperationStatus status = database.put(txn, key, value);
if (status != OperationStatus.SUCCESS) {
throw new StoreException(String.format("Cannot save link %s", linkKey));
}
}
use of com.sleepycat.je.OperationStatus in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method removeMessage.
void removeMessage(long messageId) throws StoreException {
boolean complete = false;
Transaction tx = null;
int attempts = 0;
try {
do {
tx = null;
try {
tx = getEnvironmentFacade().beginTransaction(null);
// remove the message meta data from the store
DatabaseEntry key = new DatabaseEntry();
LongBinding.longToEntry(messageId, key);
getLogger().debug("Removing message id {}", messageId);
OperationStatus status = getMessageMetaDataDb().delete(tx, key);
if (status == OperationStatus.NOTFOUND) {
getLogger().debug("Message id {} not found (attempt to remove failed - probably application initiated rollback)", messageId);
}
getLogger().debug("Deleted metadata for message {}", messageId);
// now remove the content data from the store if there is any.
DatabaseEntry contentKeyEntry = new DatabaseEntry();
LongBinding.longToEntry(messageId, contentKeyEntry);
getMessageContentDb().delete(tx, contentKeyEntry);
getLogger().debug("Deleted content for message {}", messageId);
getEnvironmentFacade().commitNoSync(tx);
complete = true;
tx = null;
} catch (LockConflictException e) {
try {
if (tx != null) {
tx.abort();
}
} catch (RuntimeException e2) {
getLogger().warn("Unable to abort transaction after LockConflictException on removal of message with id {}", messageId, e2);
// been logged.
throw getEnvironmentFacade().handleDatabaseException("Cannot remove message with id " + messageId, e);
}
sleepOrThrowOnLockConflict(attempts++, "Cannot remove messages", e);
}
} while (!complete);
} catch (RuntimeException e) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Unexpected BDB exception", e);
}
try {
abortTransactionSafely(tx, getEnvironmentFacade());
} finally {
tx = null;
}
throw getEnvironmentFacade().handleDatabaseException("Error removing message with id " + messageId + " from database: " + e.getMessage(), e);
} finally {
try {
abortTransactionSafely(tx, getEnvironmentFacade());
} finally {
tx = null;
}
}
}
Aggregations