Search in sources :

Example 36 with OperationStatus

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

the class AbstractBDBMessageStore method dequeueMessage.

/**
 * Extracts a message from a specified queue, in a given transaction.
 *
 * @param tx   The transaction for the operation.
 * @param queueId     The id of the queue to take the message from.
 * @param messageId The message to dequeue.
 *
 * @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist.
 */
private void dequeueMessage(final Transaction tx, final UUID queueId, long messageId) throws StoreException {
    DatabaseEntry key = new DatabaseEntry();
    QueueEntryKey queueEntryKey = new QueueEntryKey(queueId, messageId);
    UUID id = queueId;
    QueueEntryBinding.objectToEntry(queueEntryKey, key);
    getLogger().debug("Dequeue message id {} from queue with id {}", messageId, id);
    try {
        OperationStatus status = getDeliveryDb().delete(tx, key);
        if (status == OperationStatus.NOTFOUND) {
            throw new StoreException("Unable to find message with id " + messageId + " on queue with id " + id);
        } else if (status != OperationStatus.SUCCESS) {
            throw new StoreException("Unable to remove message with id " + messageId + " on queue with id " + id);
        }
        getLogger().debug("Removed message {} on queue with id {}", messageId, id);
    } catch (RuntimeException e) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Failed to dequeue message {} in transaction {}", messageId, tx, e);
        }
        throw getEnvironmentFacade().handleDatabaseException("Error accessing database while dequeuing message: " + e.getMessage(), e);
    }
}
Also used : QueueEntryKey(org.apache.qpid.server.store.berkeleydb.entry.QueueEntryKey) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) UUID(java.util.UUID) StoreException(org.apache.qpid.server.store.StoreException)

Example 37 with OperationStatus

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

the class UpgradeFrom5To6 method getMessageData.

/**
 * @return a (sorted) map of offset -> data for the given message id
 */
private SortedMap<Integer, byte[]> getMessageData(final long messageId, final Database oldDatabase) {
    TreeMap<Integer, byte[]> data = new TreeMap<Integer, byte[]>();
    Cursor cursor = oldDatabase.openCursor(null, CursorConfig.READ_COMMITTED);
    try {
        DatabaseEntry contentKeyEntry = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        CompoundKeyBinding binding = new CompoundKeyBinding();
        binding.objectToEntry(new CompoundKey(messageId, 0), contentKeyEntry);
        OperationStatus status = cursor.getSearchKeyRange(contentKeyEntry, value, LockMode.DEFAULT);
        OldDataBinding dataBinding = new OldDataBinding();
        while (status == OperationStatus.SUCCESS) {
            CompoundKey compoundKey = binding.entryToObject(contentKeyEntry);
            long id = compoundKey.getMessageId();
            if (id != messageId) {
                // we have exhausted all chunks for this message id, break
                break;
            }
            int offsetInMessage = compoundKey.getOffset();
            OldDataValue dataValue = dataBinding.entryToObject(value);
            data.put(offsetInMessage, dataValue.getData());
            status = cursor.getNext(contentKeyEntry, value, LockMode.DEFAULT);
        }
    } finally {
        cursor.close();
    }
    return data;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) TreeMap(java.util.TreeMap) Cursor(com.sleepycat.je.Cursor)

Example 38 with OperationStatus

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

the class ReplicatedEnvironmentFacadeTest method getTestKeyValue.

private String getTestKeyValue(final Database db, final int keyValue) {
    final DatabaseEntry key = new DatabaseEntry();
    final DatabaseEntry result = new DatabaseEntry();
    IntegerBinding.intToEntry(keyValue, key);
    final OperationStatus status = db.get(null, key, result, LockMode.DEFAULT);
    if (status == OperationStatus.SUCCESS) {
        return StringBinding.entryToString(result);
    }
    return null;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 39 with OperationStatus

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

the class UpgradeFrom7To8 method storeConfiguredObjectEntry.

private void storeConfiguredObjectEntry(Database configuredObjectsDb, final Transaction txn, ConfiguredObjectRecord configuredObject) {
    DatabaseEntry key = new DatabaseEntry();
    UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance();
    uuidBinding.objectToEntry(configuredObject.getId(), key);
    DatabaseEntry value = new DatabaseEntry();
    ConfiguredObjectBinding configuredObjectBinding = ConfiguredObjectBinding.getInstance();
    configuredObjectBinding.objectToEntry(configuredObject, value);
    OperationStatus status = configuredObjectsDb.put(txn, key, value);
    if (status != OperationStatus.SUCCESS) {
        throw new StoreException("Error writing configured object " + configuredObject + " to database: " + status);
    }
}
Also used : ConfiguredObjectBinding(org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding) OperationStatus(com.sleepycat.je.OperationStatus) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException)

Example 40 with OperationStatus

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

the class BDBConfigurationStore method writeHierarchyRecords.

private void writeHierarchyRecords(final Transaction txn, final ConfiguredObjectRecord configuredObject) {
    OperationStatus status;
    HierarchyKeyBinding hierarchyBinding = HierarchyKeyBinding.getInstance();
    DatabaseEntry hierarchyKey = new DatabaseEntry();
    DatabaseEntry hierarchyValue = new DatabaseEntry();
    for (Map.Entry<String, UUID> parent : configuredObject.getParents().entrySet()) {
        hierarchyBinding.objectToEntry(new HierarchyKey(configuredObject.getId(), parent.getKey()), hierarchyKey);
        UUIDTupleBinding.getInstance().objectToEntry(parent.getValue(), hierarchyValue);
        status = getConfiguredObjectHierarchyDb().put(txn, hierarchyKey, hierarchyValue);
        if (status != OperationStatus.SUCCESS) {
            throw new StoreException("Error writing configured object " + configuredObject + " parent record to database: " + status);
        }
    }
}
Also used : HierarchyKeyBinding(org.apache.qpid.server.store.berkeleydb.tuple.HierarchyKeyBinding) OperationStatus(com.sleepycat.je.OperationStatus) HierarchyKey(org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey) DatabaseEntry(com.sleepycat.je.DatabaseEntry) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) StoreException(org.apache.qpid.server.store.StoreException)

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