use of com.sleepycat.je.LockConflictException in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method storeNoOverwrite.
@Override
public void storeNoOverwrite(String tableName, byte[] key, byte[] value, int index, int length, DatabaseSession databaseSession) throws BimserverDatabaseException, BimserverLockConflictException, BimserverConcurrentModificationDatabaseException {
DatabaseEntry dbKey = new DatabaseEntry(key);
DatabaseEntry dbValue = new DatabaseEntry(value, index, length);
try {
TableWrapper tableWrapper = getTableWrapper(tableName);
OperationStatus putNoOverwrite = tableWrapper.getDatabase().putNoOverwrite(getTransaction(databaseSession, tableWrapper), dbKey, dbValue);
if (putNoOverwrite == OperationStatus.KEYEXIST) {
// TODO temporary test
tableWrapper.getDatabase().put(getTransaction(databaseSession, tableWrapper), dbKey, dbValue);
ByteBuffer keyBuffer = ByteBuffer.wrap(key);
if (key.length == 16) {
int pid = keyBuffer.getInt();
long oid = keyBuffer.getLong();
int rid = -keyBuffer.getInt();
LOGGER.warn("Key exists: pid: " + pid + ", oid: " + oid + ", rid: " + rid + ", " + databaseSession.getEClassForOid(oid).getName());
throw new BimserverConcurrentModificationDatabaseException("Key exists: pid: " + pid + ", oid: " + oid + ", rid: " + rid);
} else {
LOGGER.warn("Key exists");
// throw new BimserverConcurrentModificationDatabaseException("Key exists: " );
}
}
} 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 next.
@Override
public Record next() 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.getNext(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 BerkeleyTransaction method commit.
@Override
public void commit() throws BimserverLockConflictException, BimserverDatabaseException {
try {
transaction.commit();
transactionAlive = false;
} catch (LockConflictException e) {
throw new BimserverLockConflictException(e);
} catch (DatabaseException e) {
throw new BimserverDatabaseException(e);
}
}
use of com.sleepycat.je.LockConflictException in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method removeMessage.
void removeMessage(long messageId, boolean sync) 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().commit(tx, sync);
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) {
getLogger().error("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;
}
}
}
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);
}
}
Aggregations