Search in sources :

Example 6 with LockConflictException

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);
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 7 with LockConflictException

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;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException)

Example 8 with LockConflictException

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;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException)

Example 9 with LockConflictException

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);
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 10 with LockConflictException

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;
        }
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) PreparedTransaction(org.apache.qpid.server.store.berkeleydb.entry.PreparedTransaction) Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Aggregations

LockConflictException (com.sleepycat.je.LockConflictException)10 DatabaseEntry (com.sleepycat.je.DatabaseEntry)9 DatabaseException (com.sleepycat.je.DatabaseException)7 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)7 OperationStatus (com.sleepycat.je.OperationStatus)6 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 Transaction (com.sleepycat.je.Transaction)2 PreparedTransaction (org.apache.qpid.server.store.berkeleydb.entry.PreparedTransaction)2 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)2 ByteBuffer (java.nio.ByteBuffer)1 MessageMetaDataBinding (org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding)1