Search in sources :

Example 11 with Transaction

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

the class DatabasePinger method pingDb.

public void pingDb(EnvironmentFacade facade) {
    try {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Beginning ping transaction");
        }
        final Database db = facade.openDatabase(PING_DATABASE_NAME, DATABASE_CONFIG);
        DatabaseEntry key = new DatabaseEntry();
        IntegerBinding.intToEntry(ID, key);
        DatabaseEntry value = new DatabaseEntry();
        LongBinding.longToEntry(System.currentTimeMillis(), value);
        Transaction txn = null;
        try {
            txn = facade.beginTransaction(_pingTransactionConfig);
            db.put(txn, key, value);
            txn.commit();
            txn = null;
        } finally {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Ping transaction completed");
            }
            if (txn != null) {
                txn.abort();
            }
        }
    } catch (RuntimeException de) {
        RuntimeException handledException = facade.handleDatabaseException("DatabaseException from DatabasePinger ", de);
        LOGGER.debug("Non fatal exception on invoking DatabasePinger. Ignoring...", handledException);
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 12 with Transaction

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

the class UpgradeFrom4To5 method performUpgrade.

@Override
public void performUpgrade(final Environment environment, final UpgradeInteractionHandler handler, ConfiguredObject<?> parent) {
    Transaction transaction = null;
    reportStarting(environment, 4);
    transaction = environment.beginTransaction(null, null);
    // find all queues which are bound to a topic exchange and which have a colon in their name
    final List<AMQShortString> potentialDurableSubs = findPotentialDurableSubscriptions(environment, transaction);
    Set<String> existingQueues = upgradeQueues(environment, handler, potentialDurableSubs, transaction);
    upgradeQueueBindings(environment, handler, potentialDurableSubs, transaction);
    Set<Long> messagesToDiscard = upgradeDelivery(environment, existingQueues, handler, transaction);
    upgradeContent(environment, handler, messagesToDiscard, transaction);
    upgradeMetaData(environment, handler, messagesToDiscard, transaction);
    renameRemainingDatabases(environment, handler, transaction);
    transaction.commit();
    reportFinished(environment, 5);
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Transaction(com.sleepycat.je.Transaction) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString)

Example 13 with Transaction

use of com.sleepycat.je.Transaction 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))) {
                    if (arguments == null) {
                        arguments = new FieldTable();
                    }
                    AMQShortString selectorFilterKey = AMQShortString.valueOf(AMQPFilterTypes.JMS_SELECTOR.getValue());
                    if (!arguments.containsKey(selectorFilterKey)) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.info("adding the empty string (i.e. 'no selector') value for " + queueName + " and exchange " + exchangeName);
                        }
                        arguments.put(selectorFilterKey, "");
                    }
                }
                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) Transaction(com.sleepycat.je.Transaction) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 14 with Transaction

use of com.sleepycat.je.Transaction 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 = new AMQShortString(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 = new FieldTable();
            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 15 with Transaction

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

the class UpgradeFrom4To5 method upgradeDelivery.

private Set<Long> upgradeDelivery(final Environment environment, final Set<String> existingQueues, final UpgradeInteractionHandler handler, Transaction transaction) {
    final Set<Long> messagesToDiscard = new HashSet<Long>();
    final Set<String> queuesToDiscard = new HashSet<String>();
    final QueueEntryKeyBinding queueEntryKeyBinding = new QueueEntryKeyBinding();
    LOGGER.info("Delivery Records");
    CursorOperation databaseOperation = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            QueueEntryKey entryKey = queueEntryKeyBinding.entryToObject(key);
            Long messageId = entryKey.getMessageId();
            final String queueName = entryKey.getQueueName().toString();
            if (!existingQueues.contains(queueName)) {
                if (queuesToDiscard.contains(queueName)) {
                    messagesToDiscard.add(messageId);
                } else {
                    String lineSeparator = System.getProperty("line.separator");
                    String question = MessageFormat.format("Found persistent messages for non-durable queue ''{1}''. " + " Do you with to create this queue and move all the messages into it?" + lineSeparator + "NOTE: Answering No will result in these messages being discarded!", queueName);
                    UpgradeInteractionResponse response = handler.requireResponse(question, UpgradeInteractionResponse.YES, UpgradeInteractionResponse.YES, UpgradeInteractionResponse.NO, UpgradeInteractionResponse.ABORT);
                    if (response == UpgradeInteractionResponse.YES) {
                        createQueue(environment, transaction, queueName);
                        existingQueues.add(queueName);
                    } else if (response == UpgradeInteractionResponse.NO) {
                        queuesToDiscard.add(queueName);
                        messagesToDiscard.add(messageId);
                    } else {
                        throw new StoreException("Unable is aborted!");
                    }
                }
            }
            if (!messagesToDiscard.contains(messageId)) {
                DatabaseEntry newKey = new DatabaseEntry();
                queueEntryKeyBinding.objectToEntry(entryKey, newKey);
                targetDatabase.put(transaction, newKey, value);
            }
        }
    };
    new DatabaseTemplate(environment, OLD_DELIVERY_DB, NEW_DELIVERY_DB, transaction).run(databaseOperation);
    if (!messagesToDiscard.isEmpty()) {
        databaseOperation = new CursorOperation() {

            @Override
            public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                QueueEntryKey entryKey = queueEntryKeyBinding.entryToObject(key);
                Long messageId = entryKey.getMessageId();
                if (messagesToDiscard.contains(messageId)) {
                    messagesToDiscard.remove(messageId);
                }
            }
        };
        new DatabaseTemplate(environment, NEW_DELIVERY_DB, transaction).run(databaseOperation);
    }
    LOGGER.info(databaseOperation.getRowCount() + " Delivery Records entries ");
    environment.removeDatabase(transaction, OLD_DELIVERY_DB);
    return messagesToDiscard;
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException) Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) HashSet(java.util.HashSet)

Aggregations

Transaction (com.sleepycat.je.Transaction)74 DatabaseEntry (com.sleepycat.je.DatabaseEntry)55 Database (com.sleepycat.je.Database)35 OperationStatus (com.sleepycat.je.OperationStatus)20 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)12 UUID (java.util.UUID)11 Cursor (com.sleepycat.je.Cursor)10 DatabaseConfig (com.sleepycat.je.DatabaseConfig)7 DatabaseException (com.sleepycat.je.DatabaseException)6 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Environment (com.sleepycat.je.Environment)5 HashMap (java.util.HashMap)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 StoreException (org.apache.qpid.server.store.StoreException)4 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)3 LockMode (com.sleepycat.je.LockMode)3