Search in sources :

Example 46 with Database

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

the class UpgradeFrom5To6Test method loadConfiguredObjects.

private Map<UUID, UpgradeConfiguredObjectRecord> loadConfiguredObjects() {
    final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjectsRecords = new HashMap<UUID, UpgradeConfiguredObjectRecord>();
    final ConfiguredObjectBinding binding = new ConfiguredObjectBinding();
    final UpgradeUUIDBinding uuidBinding = new UpgradeUUIDBinding();
    CursorOperation configuredObjectsCursor = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            UUID id = uuidBinding.entryToObject(key);
            UpgradeConfiguredObjectRecord object = binding.entryToObject(value);
            configuredObjectsRecords.put(id, object);
        }
    };
    new DatabaseTemplate(_environment, CONFIGURED_OBJECTS_DB_NAME, null).run(configuredObjectsCursor);
    return configuredObjectsRecords;
}
Also used : UpgradeUUIDBinding(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.UpgradeUUIDBinding) ConfiguredObjectBinding(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.ConfiguredObjectBinding) NewPreparedTransaction(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction) OldPreparedTransaction(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction) Transaction(com.sleepycat.je.Transaction) UpgradeConfiguredObjectRecord(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.UpgradeConfiguredObjectRecord) HashMap(java.util.HashMap) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) UUID(java.util.UUID)

Example 47 with Database

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

the class UpgradeFrom5To6Test method assertXidEntries.

private void assertXidEntries(Environment environment) {
    final DatabaseEntry value = new DatabaseEntry();
    final DatabaseEntry key = getXidKey();
    new DatabaseTemplate(environment, NEW_XID_DB_NAME, null).run(new DatabaseRunnable() {

        @Override
        public void run(Database xidDatabase, Database nullDatabase, Transaction transaction) {
            xidDatabase.get(null, key, value, LockMode.DEFAULT);
        }
    });
    NewPreparedTransactionBinding newBinding = new NewPreparedTransactionBinding();
    NewPreparedTransaction newTransaction = newBinding.entryToObject(value);
    NewRecordImpl[] newEnqueues = newTransaction.getEnqueues();
    NewRecordImpl[] newDequeues = newTransaction.getDequeues();
    assertEquals("Unxpected new enqueus number", 1, newEnqueues.length);
    NewRecordImpl enqueue = newEnqueues[0];
    assertEquals("Unxpected queue id", UUIDGenerator.generateQueueUUID("TEST1", getVirtualHost().getName()), enqueue.getId());
    assertEquals("Unxpected message id", 1, enqueue.getMessageNumber());
    assertEquals("Unxpected new dequeues number", 1, newDequeues.length);
    NewRecordImpl dequeue = newDequeues[0];
    assertEquals("Unxpected queue id", UUIDGenerator.generateQueueUUID("TEST2", getVirtualHost().getName()), dequeue.getId());
    assertEquals("Unxpected message id", 2, dequeue.getMessageNumber());
}
Also used : NewPreparedTransaction(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction) OldPreparedTransaction(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction) Transaction(com.sleepycat.je.Transaction) NewPreparedTransaction(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction) Database(com.sleepycat.je.Database) NewRecordImpl(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewRecordImpl) DatabaseEntry(com.sleepycat.je.DatabaseEntry) NewPreparedTransactionBinding(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransactionBinding)

Example 48 with Database

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

the class UpgradeFrom5To6Test method assertQueueEntries.

private void assertQueueEntries() {
    final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjects = loadConfiguredObjects();
    final NewQueueEntryBinding newBinding = new NewQueueEntryBinding();
    CursorOperation cursorOperation = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            NewQueueEntryKey newEntryRecord = newBinding.entryToObject(key);
            assertTrue("Unexpected queue id", configuredObjects.containsKey(newEntryRecord.getQueueId()));
        }
    };
    new DatabaseTemplate(_environment, NEW_DELIVERY_DB_NAME, null).run(cursorOperation);
}
Also used : NewPreparedTransaction(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction) OldPreparedTransaction(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction) Transaction(com.sleepycat.je.Transaction) UpgradeConfiguredObjectRecord(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.UpgradeConfiguredObjectRecord) NewQueueEntryKey(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewQueueEntryKey) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) UUID(java.util.UUID) NewQueueEntryBinding(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewQueueEntryBinding)

Example 49 with Database

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

the class UpgradeFrom5To6Test method corruptDatabase.

/**
 * modify the chunk offset of a message to be wrong, so we can test logic
 * that preserves incomplete messages
 */
private void corruptDatabase() {
    CursorOperation cursorOperation = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            CompoundKeyBinding binding = new CompoundKeyBinding();
            CompoundKey originalCompoundKey = binding.entryToObject(key);
            int corruptedOffset = originalCompoundKey.getOffset() + 2;
            CompoundKey corruptedCompoundKey = new CompoundKey(originalCompoundKey.getMessageId(), corruptedOffset);
            DatabaseEntry newKey = new DatabaseEntry();
            binding.objectToEntry(corruptedCompoundKey, newKey);
            LOGGER.info("Deliberately corrupted message id " + originalCompoundKey.getMessageId() + ", changed offset from " + originalCompoundKey.getOffset() + " to " + corruptedCompoundKey.getOffset());
            deleteCurrent();
            sourceDatabase.put(transaction, newKey, value);
            abort();
        }
    };
    Transaction transaction = _environment.beginTransaction(null, null);
    new DatabaseTemplate(_environment, OLD_CONTENT_DB_NAME, transaction).run(cursorOperation);
    transaction.commit();
}
Also used : NewPreparedTransaction(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction) OldPreparedTransaction(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction) Transaction(com.sleepycat.je.Transaction) CompoundKey(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.CompoundKey) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) CompoundKeyBinding(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.CompoundKeyBinding)

Example 50 with Database

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

the class UpgraderTest method assertContent.

private void assertContent() {
    final ByteBufferBinding contentBinding = ByteBufferBinding.getInstance();
    CursorOperation contentCursorOperation = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            long id = LongBinding.entryToLong(key);
            assertTrue("Unexpected id", id > 0);
            QpidByteBuffer content = contentBinding.entryToObject(value);
            assertNotNull("Unexpected content", content);
            assertTrue("Expected content", content.hasRemaining());
        }
    };
    new DatabaseTemplate(_environment, "MESSAGE_CONTENT", null).run(contentCursorOperation);
}
Also used : ByteBufferBinding(org.apache.qpid.server.store.berkeleydb.tuple.ByteBufferBinding) Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Aggregations

Database (com.sleepycat.je.Database)73 DatabaseEntry (com.sleepycat.je.DatabaseEntry)46 Transaction (com.sleepycat.je.Transaction)35 DatabaseConfig (com.sleepycat.je.DatabaseConfig)27 UUID (java.util.UUID)12 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)11 Environment (com.sleepycat.je.Environment)10 OperationStatus (com.sleepycat.je.OperationStatus)8 Cursor (com.sleepycat.je.Cursor)7 HashSet (java.util.HashSet)7 StoreException (org.apache.qpid.server.store.StoreException)7 HashMap (java.util.HashMap)6 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)5 File (java.io.File)5 ArrayList (java.util.ArrayList)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 Test (org.junit.Test)5 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)4