Search in sources :

Example 46 with DatabaseEntry

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

the class AbstractBDBMessageStore method visitMessagesInternal.

private void visitMessagesInternal(MessageHandler handler, EnvironmentFacade environmentFacade) {
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    MessageMetaDataBinding valueBinding = MessageMetaDataBinding.getInstance();
    try (Cursor cursor = getMessageMetaDataDb().openCursor(null, null)) {
        while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
            long messageId = LongBinding.entryToLong(key);
            StorableMessageMetaData metaData = valueBinding.entryToObject(value);
            StoredBDBMessage message = createStoredBDBMessage(messageId, metaData, true);
            if (!handler.handle(message)) {
                break;
            }
        }
    } catch (RuntimeException e) {
        throw environmentFacade.handleDatabaseException("Cannot visit messages", e);
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) MessageMetaDataBinding(org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData)

Example 47 with DatabaseEntry

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

the class AbstractBDBMessageStore method addContent.

/**
 * Stores a chunk of message data.
 *
 * @param tx         The transaction for the operation.
 * @param messageId       The message to store the data for.
 * @param contentBody     The content of the data chunk.
 *
 * @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist.
 */
private void addContent(final Transaction tx, long messageId, QpidByteBuffer contentBody) throws StoreException {
    DatabaseEntry key = new DatabaseEntry();
    LongBinding.longToEntry(messageId, key);
    DatabaseEntry value = new DatabaseEntry();
    byte[] data = new byte[contentBody.remaining()];
    contentBody.copyTo(data);
    value.setData(data);
    try {
        OperationStatus status = getMessageContentDb().put(tx, key, value);
        if (status != OperationStatus.SUCCESS) {
            throw new StoreException("Error adding content for message id " + messageId + ": " + status);
        }
        getLogger().debug("Storing content for message {} in transaction {}", messageId, tx);
    } catch (RuntimeException e) {
        throw getEnvironmentFacade().handleDatabaseException("Error writing AMQMessage with id " + messageId + " to database: " + e.getMessage(), e);
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException)

Example 48 with DatabaseEntry

use of com.sleepycat.je.DatabaseEntry 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 49 with DatabaseEntry

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

the class AbstractBDBMessageStore method storeMetaData.

/**
 * Stores message meta-data.
 *
 * @param tx         The transaction for the operation.
 * @param messageId       The message to store the data for.
 * @param messageMetaData The message meta data to store.
 *
 * @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist.
 */
private void storeMetaData(final Transaction tx, long messageId, StorableMessageMetaData messageMetaData) throws StoreException {
    getLogger().debug("storeMetaData called for transaction {}, messageId {}, messageMetaData {} ", tx, messageId, messageMetaData);
    DatabaseEntry key = new DatabaseEntry();
    LongBinding.longToEntry(messageId, key);
    DatabaseEntry value = new DatabaseEntry();
    MessageMetaDataBinding messageBinding = MessageMetaDataBinding.getInstance();
    messageBinding.objectToEntry(messageMetaData, value);
    boolean complete = false;
    int attempts = 0;
    do {
        try {
            getMessageMetaDataDb().put(tx, key, value);
            getLogger().debug("Storing message metadata for message id {} in transaction {}", messageId, tx);
            complete = true;
        } catch (LockConflictException e) {
            sleepOrThrowOnLockConflict(attempts++, "Cannot store metadata", e);
        } catch (RuntimeException e) {
            throw getEnvironmentFacade().handleDatabaseException("Error writing message metadata with id " + messageId + " to database: " + e.getMessage(), e);
        }
    } while (!complete);
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) LockConflictException(com.sleepycat.je.LockConflictException) MessageMetaDataBinding(org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 50 with DatabaseEntry

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

the class UpgradeFrom5To6 method upgradeExchanges.

private List<String> upgradeExchanges(Environment environment, Transaction transaction, final String virtualHostName) {
    final List<String> exchangeNames = new ArrayList<String>();
    LOGGER.info("Exchanges");
    if (environment.getDatabaseNames().contains(OLD_EXCHANGE_DB_NAME)) {
        final ExchangeBinding exchangeBinding = new ExchangeBinding();
        CursorOperation exchangeCursor = new CursorOperation() {

            @Override
            public void processEntry(Database exchangeDatabase, Database configuredObjectsDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                ExchangeRecord exchangeRecord = exchangeBinding.entryToObject(value);
                String exchangeName = exchangeRecord.getNameShortString().toString();
                if (!DEFAULT_EXCHANGES_SET.contains(exchangeName) && !"<<default>>".equals(exchangeName)) {
                    String exchangeType = exchangeRecord.getType().toString();
                    boolean autoDelete = exchangeRecord.isAutoDelete();
                    UUID exchangeId = UUIDGenerator.generateExchangeUUID(exchangeName, virtualHostName);
                    UpgradeConfiguredObjectRecord configuredObject = createExchangeConfiguredObjectRecord(exchangeName, exchangeType, autoDelete);
                    storeConfiguredObjectEntry(configuredObjectsDatabase, exchangeId, configuredObject, transaction);
                    exchangeNames.add(exchangeName);
                }
            }
        };
        new DatabaseTemplate(environment, OLD_EXCHANGE_DB_NAME, CONFIGURED_OBJECTS_DB_NAME, transaction).run(exchangeCursor);
        environment.removeDatabase(transaction, OLD_EXCHANGE_DB_NAME);
        LOGGER.info(exchangeCursor.getRowCount() + " Exchange Entries");
    }
    return exchangeNames;
}
Also used : ArrayList(java.util.ArrayList) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) UUID(java.util.UUID)

Aggregations

DatabaseEntry (com.sleepycat.je.DatabaseEntry)153 OperationStatus (com.sleepycat.je.OperationStatus)70 Transaction (com.sleepycat.je.Transaction)58 Database (com.sleepycat.je.Database)46 Cursor (com.sleepycat.je.Cursor)31 DatabaseException (com.sleepycat.je.DatabaseException)26 StoreException (org.apache.qpid.server.store.StoreException)20 UUID (java.util.UUID)17 ArrayList (java.util.ArrayList)13 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)12 DatabaseConfig (com.sleepycat.je.DatabaseConfig)11 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)11 LockConflictException (com.sleepycat.je.LockConflictException)9 HashMap (java.util.HashMap)9 Versioned (voldemort.versioning.Versioned)9 HashSet (java.util.HashSet)8 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)8 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)6 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)6 SirixIOException (org.sirix.exception.SirixIOException)6