Search in sources :

Example 1 with Transaction

use of com.sleepycat.je.Transaction in project OpenRefine by OpenRefine.

the class RefineBrokerImpl method startProject.

// ----------------------------------------------------------------------------------------------------
@Override
protected void startProject(HttpServletResponse response, String pid, String uid, String lid, byte[] data, String metadata, List<String> transformations) throws Exception {
    Transaction txn = env.beginTransaction(null, null);
    try {
        if (projectById.contains(pid)) {
            throw new RuntimeException("Project '" + pid + "' already exists");
        }
        Lock lock = getLock(lid, pid, uid);
        if (lock.type != ALL) {
            throw new RuntimeException("The lock you have is not enough to start a project");
        }
        projectById.put(txn, new Project(pid, data, metadata, transformations));
        txn.commit();
    } finally {
        if (txn != null) {
            txn.abort();
            txn = null;
        }
    }
    respond(response, OK);
}
Also used : Transaction(com.sleepycat.je.Transaction)

Example 2 with Transaction

use of com.sleepycat.je.Transaction in project OpenRefine by OpenRefine.

the class RefineBrokerImpl method releaseLock.

@Override
protected void releaseLock(HttpServletResponse response, String pid, String uid, String lid) throws Exception {
    Transaction txn = env.beginTransaction(null, null);
    try {
        Lock lock = getLock(lid, pid, uid);
        if (lock != null) {
            if (!lock.uid.equals(uid)) {
                throw new RuntimeException("User id doesn't match the lock owner, can't release the lock");
            }
            lockById.delete(lid);
            txn.commit();
        }
    } finally {
        if (txn != null) {
            txn.abort();
            txn = null;
        }
    }
    if (response != null) {
        // this because the expiration thread can call this method without a real response
        respond(response, OK);
    }
}
Also used : Transaction(com.sleepycat.je.Transaction)

Example 3 with Transaction

use of com.sleepycat.je.Transaction 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 4 with Transaction

use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacadeTest method putRecord.

private void putRecord(final ReplicatedEnvironmentFacade master, final Database db, final int keyValue, final String dataValue) {
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    TransactionConfig transactionConfig = new TransactionConfig();
    transactionConfig.setDurability(master.getRealMessageStoreDurability());
    Transaction txn = master.beginTransaction(transactionConfig);
    IntegerBinding.intToEntry(keyValue, key);
    StringBinding.stringToEntry(dataValue, data);
    db.put(txn, key, data);
    txn.commit();
}
Also used : Transaction(com.sleepycat.je.Transaction) DatabaseEntry(com.sleepycat.je.DatabaseEntry) TransactionConfig(com.sleepycat.je.TransactionConfig)

Example 5 with Transaction

use of com.sleepycat.je.Transaction 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)

Aggregations

Transaction (com.sleepycat.je.Transaction)80 DatabaseEntry (com.sleepycat.je.DatabaseEntry)58 Database (com.sleepycat.je.Database)35 OperationStatus (com.sleepycat.je.OperationStatus)23 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)12 UUID (java.util.UUID)11 Cursor (com.sleepycat.je.Cursor)10 DatabaseException (com.sleepycat.je.DatabaseException)8 DatabaseConfig (com.sleepycat.je.DatabaseConfig)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 Environment (com.sleepycat.je.Environment)5 TransactionConfig (com.sleepycat.je.TransactionConfig)5 FieldTable (org.apache.qpid.server.protocol.v0_8.FieldTable)5 NewPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction)5 OldPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction)5 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)4 LockMode (com.sleepycat.je.LockMode)4 StoreException (org.apache.qpid.server.store.StoreException)4