use of com.sleepycat.je.LockConflictException in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method store.
@Override
public void store(String tableName, byte[] key, byte[] value, int offset, int length, DatabaseSession databaseSession) throws BimserverDatabaseException, BimserverLockConflictException {
DatabaseEntry dbKey = new DatabaseEntry(key);
DatabaseEntry dbValue = new DatabaseEntry(value, offset, length);
try {
TableWrapper tableWrapper = getTableWrapper(tableName);
tableWrapper.getDatabase().put(getTransaction(databaseSession, tableWrapper), dbKey, dbValue);
} catch (LockConflictException e) {
throw new BimserverLockConflictException(e);
} catch (DatabaseException e) {
throw new BimserverDatabaseException("", e);
}
}
use of com.sleepycat.je.LockConflictException in project BIMserver by opensourceBIM.
the class BerkeleySearchingRecordIterator method last.
@Override
public Record last() throws BimserverLockConflictException {
if (nextStartSearchingAt != null) {
return getFirstNext(nextStartSearchingAt);
}
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
if (onlyKeys) {
value.setPartial(0, 0, true);
}
try {
OperationStatus next = cursor.getLast(key, value, LockMode.DEFAULT);
if (next == OperationStatus.SUCCESS) {
byte[] firstBytes = new byte[mustStartWith.length];
System.arraycopy(key.getData(), 0, firstBytes, 0, mustStartWith.length);
if (Arrays.equals(firstBytes, mustStartWith)) {
return new BerkeleyRecord(key, value);
}
}
} catch (LockConflictException e) {
throw new BimserverLockConflictException(e);
} catch (DatabaseException e) {
LOGGER.error("", e);
}
return null;
}
use of com.sleepycat.je.LockConflictException in project BIMserver by opensourceBIM.
the class BerkeleySearchingRecordIterator method getFirstNext.
private Record getFirstNext(byte[] startSearchingAt) throws BimserverLockConflictException {
this.nextStartSearchingAt = null;
DatabaseEntry key = new DatabaseEntry(startSearchingAt);
DatabaseEntry value = new DatabaseEntry();
if (onlyKeys) {
value.setPartial(0, 0, true);
}
try {
OperationStatus next = cursor.getSearchKeyRange(key, value, LockMode.DEFAULT);
if (next == OperationStatus.SUCCESS) {
byte[] firstBytes = new byte[mustStartWith.length];
System.arraycopy(key.getData(), 0, firstBytes, 0, mustStartWith.length);
if (Arrays.equals(firstBytes, mustStartWith)) {
return new BerkeleyRecord(key, value);
}
}
} catch (LockConflictException e) {
throw new BimserverLockConflictException(e);
} catch (DatabaseException e) {
LOGGER.error("", e);
}
return null;
}
use of com.sleepycat.je.LockConflictException in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method delete.
public void delete(String tableName, byte[] key, DatabaseSession databaseSession) throws BimserverLockConflictException {
DatabaseEntry entry = new DatabaseEntry(key);
try {
TableWrapper tableWrapper = getTableWrapper(tableName);
tableWrapper.getDatabase().delete(getTransaction(databaseSession, tableWrapper), entry);
} catch (LockConflictException e) {
throw new BimserverLockConflictException(e);
} catch (DatabaseException e) {
LOGGER.error("", e);
} catch (UnsupportedOperationException e) {
LOGGER.error("", e);
} catch (IllegalArgumentException e) {
LOGGER.error("", e);
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
}
}
use of com.sleepycat.je.LockConflictException 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