Search in sources :

Example 16 with Transaction

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

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

the class UpgradeFrom4To5 method upgradeQueues.

private Set<String> upgradeQueues(final Environment environment, final UpgradeInteractionHandler handler, List<AMQShortString> potentialDurableSubs, Transaction transaction) {
    LOGGER.info("Queues");
    final Set<String> existingQueues = new HashSet<String>();
    if (environment.getDatabaseNames().contains(OLD_QUEUE_DB_NAME)) {
        final QueueRecordBinding binding = new QueueRecordBinding(potentialDurableSubs);
        CursorOperation databaseOperation = new CursorOperation() {

            @Override
            public void processEntry(final Database sourceDatabase, final Database targetDatabase, final Transaction transaction, final DatabaseEntry key, final DatabaseEntry value) {
                QueueRecord record = binding.entryToObject(value);
                DatabaseEntry newValue = new DatabaseEntry();
                binding.objectToEntry(record, newValue);
                targetDatabase.put(transaction, key, newValue);
                existingQueues.add(record.getNameShortString().toString());
                sourceDatabase.delete(transaction, key);
            }
        };
        new DatabaseTemplate(environment, OLD_QUEUE_DB_NAME, NEW_QUEUE_DB_NAME, transaction).run(databaseOperation);
        environment.removeDatabase(transaction, OLD_QUEUE_DB_NAME);
        LOGGER.info(databaseOperation.getRowCount() + " Queue entries");
    }
    return existingQueues;
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) HashSet(java.util.HashSet)

Example 18 with Transaction

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

Example 19 with Transaction

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

the class ReplicatedEnvironmentFacadeTest method testBeginTransaction.

public void testBeginTransaction() throws Exception {
    ReplicatedEnvironmentFacade facade = createMaster();
    Transaction txn = null;
    try {
        TransactionConfig transactionConfig = new TransactionConfig();
        transactionConfig.setDurability(facade.getRealMessageStoreDurability());
        txn = facade.beginTransaction(transactionConfig);
        assertNotNull("Transaction is not created", txn);
        txn.commit();
        txn = null;
    } finally {
        if (txn != null) {
            txn.abort();
        }
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) TransactionConfig(com.sleepycat.je.TransactionConfig)

Example 20 with Transaction

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

the class ReplicatedEnvironmentFacadeTest method testReplicaTransactionBeginsImmediately.

public void testReplicaTransactionBeginsImmediately() throws Exception {
    ReplicatedEnvironmentFacade master = createMaster();
    String nodeName2 = TEST_NODE_NAME + "_2";
    String host = "localhost";
    int port = _portHelper.getNextAvailable();
    String node2NodeHostPort = host + ":" + port;
    final ReplicatedEnvironmentFacade replica = createReplica(nodeName2, node2NodeHostPort, new NoopReplicationGroupListener());
    // close the master
    master.close();
    // try to create a transaction in a separate thread
    // and make sure that transaction is created immediately.
    ExecutorService service = Executors.newSingleThreadExecutor();
    try {
        Future<Transaction> future = service.submit(new Callable<Transaction>() {

            @Override
            public Transaction call() throws Exception {
                return replica.beginTransaction(null);
            }
        });
        Transaction transaction = future.get(_timeout, TimeUnit.SECONDS);
        assertNotNull("Transaction was not created during expected time", transaction);
        transaction.abort();
    } finally {
        service.shutdown();
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) ExecutorService(java.util.concurrent.ExecutorService) ReplicaWriteException(com.sleepycat.je.rep.ReplicaWriteException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException)

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