Search in sources :

Example 71 with DatabaseEntry

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

the class UpgradeFrom4To5 method createQueue.

protected void createQueue(final Environment environment, Transaction transaction, final String queueName) {
    final QueueRecordBinding binding = new QueueRecordBinding(null);
    final BindingTuple bindingTuple = new BindingTuple();
    DatabaseRunnable queueCreateOperation = new DatabaseRunnable() {

        @Override
        public void run(Database newQueueDatabase, Database newBindingsDatabase, Transaction transaction) {
            AMQShortString queueNameAMQ = AMQShortString.createAMQShortString(queueName);
            QueueRecord record = new QueueRecord(queueNameAMQ, null, false, null);
            DatabaseEntry key = new DatabaseEntry();
            TupleOutput output = new TupleOutput();
            AMQShortStringEncoding.writeShortString(record.getNameShortString(), output);
            TupleBase.outputToEntry(output, key);
            DatabaseEntry newValue = new DatabaseEntry();
            binding.objectToEntry(record, newValue);
            newQueueDatabase.put(transaction, key, newValue);
            FieldTable emptyArguments = FieldTableFactory.createFieldTable(Collections.emptyMap());
            addBindingToDatabase(bindingTuple, newBindingsDatabase, transaction, queueNameAMQ, AMQShortString.valueOf(ExchangeDefaults.DIRECT_EXCHANGE_NAME), queueNameAMQ, emptyArguments);
            // TODO QPID-3490 we should not persist a default exchange binding
            addBindingToDatabase(bindingTuple, newBindingsDatabase, transaction, queueNameAMQ, AMQShortString.valueOf(ExchangeDefaults.DEFAULT_EXCHANGE_NAME), queueNameAMQ, emptyArguments);
        }
    };
    new DatabaseTemplate(environment, NEW_QUEUE_DB_NAME, NEW_BINDINGS_DB_NAME, transaction).run(queueCreateOperation);
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Transaction(com.sleepycat.je.Transaction) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) TupleOutput(com.sleepycat.bind.tuple.TupleOutput)

Example 72 with DatabaseEntry

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

the class UpgradeFrom4To5 method upgradeQueueBindings.

private void upgradeQueueBindings(Environment environment, UpgradeInteractionHandler handler, final List<AMQShortString> potentialDurableSubs, Transaction transaction) {
    if (environment.getDatabaseNames().contains(OLD_BINDINGS_DB_NAME)) {
        LOGGER.info("Queue Bindings");
        final BindingTuple bindingTuple = new BindingTuple();
        CursorOperation databaseOperation = new CursorOperation() {

            @Override
            public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                // All the information required in binding entries is actually in the *key* not value.
                BindingRecord oldBindingRecord = bindingTuple.entryToObject(key);
                AMQShortString queueName = oldBindingRecord.getQueueName();
                AMQShortString exchangeName = oldBindingRecord.getExchangeName();
                AMQShortString routingKey = oldBindingRecord.getRoutingKey();
                FieldTable arguments = oldBindingRecord.getArguments();
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(String.format("Processing binding for queue %s, exchange %s, routingKey %s arguments %s", queueName, exchangeName, routingKey, arguments));
                }
                // only topic exchange should have a JMS selector key in binding
                if (potentialDurableSubs.contains(queueName) && exchangeName.equals(AMQShortString.valueOf(ExchangeDefaults.TOPIC_EXCHANGE_NAME))) {
                    Map<String, Object> argumentsMap = new HashMap<>();
                    if (arguments != null) {
                        argumentsMap.putAll(FieldTable.convertToMap(arguments));
                    }
                    String selectorFilterKey = AMQPFilterTypes.JMS_SELECTOR.getValue();
                    if (!argumentsMap.containsKey(selectorFilterKey)) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.info("adding the empty string (i.e. 'no selector') value for " + queueName + " and exchange " + exchangeName);
                        }
                        argumentsMap.put(selectorFilterKey, "");
                    }
                    arguments = FieldTable.convertToFieldTable(argumentsMap);
                }
                addBindingToDatabase(bindingTuple, targetDatabase, transaction, queueName, exchangeName, routingKey, arguments);
            }
        };
        new DatabaseTemplate(environment, OLD_BINDINGS_DB_NAME, NEW_BINDINGS_DB_NAME, transaction).run(databaseOperation);
        environment.removeDatabase(transaction, OLD_BINDINGS_DB_NAME);
        LOGGER.info(databaseOperation.getRowCount() + " Queue Binding entries");
    }
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) HashMap(java.util.HashMap) DatabaseEntry(com.sleepycat.je.DatabaseEntry) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 73 with DatabaseEntry

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

the class UpgradeFrom4To5 method upgradeMetaData.

private void upgradeMetaData(final Environment environment, final UpgradeInteractionHandler handler, final Set<Long> messagesToDiscard, Transaction transaction) {
    LOGGER.info("Message MetaData");
    if (environment.getDatabaseNames().contains(OLD_METADATA_DB_NAME)) {
        final MessageMetaDataBinding binding = new MessageMetaDataBinding();
        CursorOperation databaseOperation = new CursorOperation() {

            @Override
            public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                StorableMessageMetaData metaData = binding.entryToObject(value);
                // get message id
                Long messageId = LongBinding.entryToLong(key);
                // ONLY copy data if message is delivered to existing queue
                if (messagesToDiscard.contains(messageId)) {
                    return;
                }
                DatabaseEntry newValue = new DatabaseEntry();
                binding.objectToEntry(metaData, newValue);
                targetDatabase.put(transaction, key, newValue);
                targetDatabase.put(transaction, key, newValue);
                deleteCurrent();
            }
        };
        new DatabaseTemplate(environment, OLD_METADATA_DB_NAME, NEW_METADATA_DB_NAME, transaction).run(databaseOperation);
        environment.removeDatabase(transaction, OLD_METADATA_DB_NAME);
        LOGGER.info(databaseOperation.getRowCount() + " Message MetaData entries");
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData)

Example 74 with DatabaseEntry

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

the class CursorTemplate method processEntries.

public void processEntries() {
    _cursor = _database.openCursor(_transaction, CursorConfig.READ_COMMITTED);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    try {
        _iterating = true;
        while (_iterating && _cursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
            _databaseEntryCallback.processEntry(_database, _transaction, key, value);
        }
    } finally {
        _cursor.close();
    }
}
Also used : DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 75 with DatabaseEntry

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

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