Search in sources :

Example 1 with OperationStatus

use of com.sleepycat.je.OperationStatus 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;
        }
    }
}
Also used : 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)

Example 2 with OperationStatus

use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.

the class BDBJEPointCache method get.

@Override
public CoordinateSequence get(List<Long> ids) {
    Preconditions.checkNotNull(ids, "ids is null");
    OSMCoordinateSequence cs = CSFAC.create(ids.size());
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    for (int index = 0; index < ids.size(); index++) {
        Long nodeID = ids.get(index);
        LongBinding.longToEntry(nodeID.longValue(), key);
        OperationStatus status = database.get(null, key, data, LockMode.DEFAULT);
        if (!OperationStatus.SUCCESS.equals(status)) {
            String msg = String.format("node id %s not found", nodeID);
            throw new IllegalArgumentException(msg);
        }
        int[] c = CoordinateBinding.entryToCoord(data);
        cs.setOrdinate(index, 0, c[0]);
        cs.setOrdinate(index, 1, c[1]);
    }
    return cs;
}
Also used : OSMCoordinateSequence(org.locationtech.geogig.osm.internal.OSMCoordinateSequence) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 3 with OperationStatus

use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.

the class JEObjectDatabase method getRawInternal.

@Override
protected InputStream getRawInternal(final ObjectId id, final boolean failIfNotFound) {
    checkOpen();
    Preconditions.checkNotNull(id, "id");
    DatabaseEntry key = new DatabaseEntry(id.getRawValue());
    DatabaseEntry data = new DatabaseEntry();
    final LockMode lockMode = LockMode.READ_UNCOMMITTED;
    Transaction transaction = null;
    OperationStatus operationStatus = objectDb.get(transaction, key, data, lockMode);
    if (NOTFOUND.equals(operationStatus)) {
        if (failIfNotFound) {
            throw new IllegalArgumentException("Object does not exist: " + id.toString() + " at " + env.getHome().getAbsolutePath());
        }
        return null;
    }
    final byte[] cData = data.getData();
    return new ByteArrayInputStream(cData);
}
Also used : Transaction(com.sleepycat.je.Transaction) ByteArrayInputStream(java.io.ByteArrayInputStream) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) LockMode(com.sleepycat.je.LockMode)

Example 4 with OperationStatus

use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.

the class JEObjectDatabase method putInternal.

private OperationStatus putInternal(final ObjectId id, final byte[] rawData, Transaction transaction) {
    OperationStatus status;
    final byte[] rawKey = id.getRawValue();
    DatabaseEntry key = new DatabaseEntry(rawKey);
    DatabaseEntry data = new DatabaseEntry(rawData);
    status = objectDb.putNoOverwrite(transaction, key, data);
    return status;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 5 with OperationStatus

use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.

the class JEObjectDatabase method exists.

/**
     * @see org.locationtech.geogig.storage.ObjectDatabase#exists(org.locationtech.geogig.api.ObjectId)
     */
@Override
public boolean exists(final ObjectId id) {
    checkOpen();
    Preconditions.checkNotNull(id, "id");
    DatabaseEntry key = new DatabaseEntry(id.getRawValue());
    DatabaseEntry data = new DatabaseEntry();
    // tell db not to retrieve data
    data.setPartial(0, 0, true);
    final LockMode lockMode = LockMode.READ_UNCOMMITTED;
    Transaction transaction = null;
    OperationStatus status = objectDb.get(transaction, key, data, lockMode);
    return SUCCESS == status;
}
Also used : Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) LockMode(com.sleepycat.je.LockMode)

Aggregations

OperationStatus (com.sleepycat.je.OperationStatus)76 DatabaseEntry (com.sleepycat.je.DatabaseEntry)70 Transaction (com.sleepycat.je.Transaction)23 DatabaseException (com.sleepycat.je.DatabaseException)21 Cursor (com.sleepycat.je.Cursor)15 StoreException (org.apache.qpid.server.store.StoreException)13 Versioned (voldemort.versioning.Versioned)9 Database (com.sleepycat.je.Database)8 ArrayList (java.util.ArrayList)7 LockConflictException (com.sleepycat.je.LockConflictException)6 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)6 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)6 UUID (java.util.UUID)4 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)4 SirixIOException (org.sirix.exception.SirixIOException)4 AsyncOperationStatus (voldemort.server.protocol.admin.AsyncOperationStatus)4 PersistenceFailureException (voldemort.store.PersistenceFailureException)4 DatabaseConfig (com.sleepycat.je.DatabaseConfig)3 LockMode (com.sleepycat.je.LockMode)3 VSystemException (io.vertigo.lang.VSystemException)3