Search in sources :

Example 56 with DatabaseEntry

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

the class UpgradeFrom4to5Test method assertQueueHasOwner.

private void assertQueueHasOwner(String queueName, final String expectedOwner) {
    List<AMQShortString> durableSubNames = Collections.emptyList();
    final UpgradeFrom4To5.QueueRecordBinding binding = new UpgradeFrom4To5.QueueRecordBinding(durableSubNames);
    final AtomicReference<String> actualOwner = new AtomicReference<String>();
    final AtomicBoolean foundQueue = new AtomicBoolean(false);
    CursorOperation queueNameCollector = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            QueueRecord record = binding.entryToObject(value);
            String queueName = record.getNameShortString().toString();
            if (queueName.equals(queueName)) {
                foundQueue.set(true);
                actualOwner.set(AMQShortString.toString(record.getOwner()));
            }
        }
    };
    new DatabaseTemplate(_environment, "queueDb_v5", null).run(queueNameCollector);
    assertTrue("Could not find queue in database", foundQueue.get());
    assertEquals("Queue has unexpected owner", expectedOwner, actualOwner.get());
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) AtomicReference(java.util.concurrent.atomic.AtomicReference) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(com.sleepycat.je.Transaction) QueueRecord(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.QueueRecord) Database(com.sleepycat.je.Database)

Example 57 with DatabaseEntry

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

the class UpgradeFrom7To8Test method loadConfiguredObjectHierarchy.

private Map<UpgradeHierarchyKey, UUID> loadConfiguredObjectHierarchy() {
    final Map<UpgradeHierarchyKey, UUID> hierarchyRecords = new HashMap<UpgradeHierarchyKey, UUID>();
    final UpgradeHierarchyKeyBinding hierarchyKeyBinding = new UpgradeHierarchyKeyBinding();
    final UpgradeUUIDBinding uuidParentBinding = new UpgradeUUIDBinding();
    CursorOperation hierarchyCursor = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            UpgradeHierarchyKey hierarchyKey = hierarchyKeyBinding.entryToObject(key);
            UUID parentId = uuidParentBinding.entryToObject(value);
            hierarchyRecords.put(hierarchyKey, parentId);
        }
    };
    new DatabaseTemplate(_environment, CONFIGURED_OBJECT_HIERARCHY_DB_NAME, null).run(hierarchyCursor);
    return hierarchyRecords;
}
Also used : Transaction(com.sleepycat.je.Transaction) HashMap(java.util.HashMap) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) UUID(java.util.UUID)

Example 58 with DatabaseEntry

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

the class UpgradeFrom5To6 method upgradeQueues.

private List<String> upgradeQueues(Environment environment, Transaction transaction, final String virtualHostName) {
    final List<String> queueNames = new ArrayList<String>();
    LOGGER.info("Queues");
    if (environment.getDatabaseNames().contains(OLD_QUEUE_DB_NAME)) {
        final UpgradeQueueBinding queueBinding = new UpgradeQueueBinding();
        CursorOperation queueCursor = new CursorOperation() {

            @Override
            public void processEntry(Database queueDatabase, Database configuredObjectsDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                OldQueueRecord queueRecord = queueBinding.entryToObject(value);
                String queueName = queueRecord.getNameShortString().toString();
                queueNames.add(queueName);
                String owner = queueRecord.getOwner() == null ? null : queueRecord.getOwner().toString();
                boolean exclusive = queueRecord.isExclusive();
                FieldTable arguments = queueRecord.getArguments();
                UUID queueId = UUIDGenerator.generateQueueUUID(queueName, virtualHostName);
                UpgradeConfiguredObjectRecord configuredObject = createQueueConfiguredObjectRecord(queueName, owner, exclusive, arguments);
                storeConfiguredObjectEntry(configuredObjectsDatabase, queueId, configuredObject, transaction);
            }
        };
        new DatabaseTemplate(environment, OLD_QUEUE_DB_NAME, CONFIGURED_OBJECTS_DB_NAME, transaction).run(queueCursor);
        environment.removeDatabase(transaction, OLD_QUEUE_DB_NAME);
        LOGGER.info(queueCursor.getRowCount() + " Queue Entries");
    }
    return queueNames;
}
Also used : FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) 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 59 with DatabaseEntry

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

the class UpgradeFrom5To6 method storeConfiguredObjectEntry.

private void storeConfiguredObjectEntry(Database configuredObjectsDatabase, UUID id, UpgradeConfiguredObjectRecord configuredObject, Transaction transaction) {
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    UpgradeUUIDBinding uuidBinding = new UpgradeUUIDBinding();
    uuidBinding.objectToEntry(id, key);
    ConfiguredObjectBinding configuredBinding = new ConfiguredObjectBinding();
    configuredBinding.objectToEntry(configuredObject, value);
    put(configuredObjectsDatabase, transaction, key, value);
}
Also used : DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 60 with DatabaseEntry

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

the class UpgradeFrom5To6 method upgradeXidEntries.

private void upgradeXidEntries(Environment environment, Transaction transaction, final String virtualHostName) {
    if (environment.getDatabaseNames().contains(OLD_XID_DB_NAME)) {
        LOGGER.info("Xid Records");
        final OldPreparedTransactionBinding oldTransactionBinding = new OldPreparedTransactionBinding();
        final NewPreparedTransactionBinding newTransactionBinding = new NewPreparedTransactionBinding();
        CursorOperation xidEntriesCursor = new CursorOperation() {

            @Override
            public void processEntry(Database oldXidDatabase, Database newXidDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                OldPreparedTransaction oldPreparedTransaction = oldTransactionBinding.entryToObject(value);
                OldRecordImpl[] oldDequeues = oldPreparedTransaction.getDequeues();
                OldRecordImpl[] oldEnqueues = oldPreparedTransaction.getEnqueues();
                NewRecordImpl[] newEnqueues = null;
                NewRecordImpl[] newDequeues = null;
                if (oldDequeues != null) {
                    newDequeues = new NewRecordImpl[oldDequeues.length];
                    for (int i = 0; i < newDequeues.length; i++) {
                        OldRecordImpl dequeue = oldDequeues[i];
                        UUID id = UUIDGenerator.generateQueueUUID(dequeue.getQueueName(), virtualHostName);
                        newDequeues[i] = new NewRecordImpl(id, dequeue.getMessageNumber());
                    }
                }
                if (oldEnqueues != null) {
                    newEnqueues = new NewRecordImpl[oldEnqueues.length];
                    for (int i = 0; i < newEnqueues.length; i++) {
                        OldRecordImpl enqueue = oldEnqueues[i];
                        UUID id = UUIDGenerator.generateQueueUUID(enqueue.getQueueName(), virtualHostName);
                        newEnqueues[i] = new NewRecordImpl(id, enqueue.getMessageNumber());
                    }
                }
                NewPreparedTransaction newPreparedTransaction = new NewPreparedTransaction(newEnqueues, newDequeues);
                DatabaseEntry newValue = new DatabaseEntry();
                newTransactionBinding.objectToEntry(newPreparedTransaction, newValue);
                put(newXidDatabase, transaction, key, newValue);
            }
        };
        new DatabaseTemplate(environment, OLD_XID_DB_NAME, NEW_XID_DB_NAME, transaction).run(xidEntriesCursor);
        environment.removeDatabase(transaction, OLD_XID_DB_NAME);
        LOGGER.info(xidEntriesCursor.getRowCount() + " Xid Entries");
    }
}
Also used : 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