Search in sources :

Example 51 with DatabaseEntry

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

the class UpgradeFrom5To6 method getMessageData.

/**
 * @return a (sorted) map of offset -> data for the given message id
 */
private SortedMap<Integer, byte[]> getMessageData(final long messageId, final Database oldDatabase) {
    TreeMap<Integer, byte[]> data = new TreeMap<Integer, byte[]>();
    Cursor cursor = oldDatabase.openCursor(null, CursorConfig.READ_COMMITTED);
    try {
        DatabaseEntry contentKeyEntry = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        CompoundKeyBinding binding = new CompoundKeyBinding();
        binding.objectToEntry(new CompoundKey(messageId, 0), contentKeyEntry);
        OperationStatus status = cursor.getSearchKeyRange(contentKeyEntry, value, LockMode.DEFAULT);
        OldDataBinding dataBinding = new OldDataBinding();
        while (status == OperationStatus.SUCCESS) {
            CompoundKey compoundKey = binding.entryToObject(contentKeyEntry);
            long id = compoundKey.getMessageId();
            if (id != messageId) {
                // we have exhausted all chunks for this message id, break
                break;
            }
            int offsetInMessage = compoundKey.getOffset();
            OldDataValue dataValue = dataBinding.entryToObject(value);
            data.put(offsetInMessage, dataValue.getData());
            status = cursor.getNext(contentKeyEntry, value, LockMode.DEFAULT);
        }
    } finally {
        cursor.close();
    }
    return data;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) TreeMap(java.util.TreeMap) Cursor(com.sleepycat.je.Cursor)

Example 52 with DatabaseEntry

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

the class UpgradeFrom5To6 method upgradeQueueEntries.

private void upgradeQueueEntries(Environment environment, Transaction transaction, final String virtualHostName) {
    LOGGER.info("Queue Delivery Records");
    if (environment.getDatabaseNames().contains(OLD_DELIVERY_DB_NAME)) {
        final OldQueueEntryBinding oldBinding = new OldQueueEntryBinding();
        final NewQueueEntryBinding newBinding = new NewQueueEntryBinding();
        CursorOperation queueEntriesCursor = new CursorOperation() {

            @Override
            public void processEntry(Database oldDeliveryDatabase, Database newDeliveryDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                OldQueueEntryKey oldEntryRecord = oldBinding.entryToObject(key);
                UUID queueId = UUIDGenerator.generateQueueUUID(oldEntryRecord.getQueueName().toString(), virtualHostName);
                NewQueueEntryKey newEntryRecord = new NewQueueEntryKey(queueId, oldEntryRecord.getMessageId());
                DatabaseEntry newKey = new DatabaseEntry();
                newBinding.objectToEntry(newEntryRecord, newKey);
                put(newDeliveryDatabase, transaction, newKey, value);
            }
        };
        new DatabaseTemplate(environment, OLD_DELIVERY_DB_NAME, NEW_DELIVERY_DB_NAME, transaction).run(queueEntriesCursor);
        environment.removeDatabase(transaction, OLD_DELIVERY_DB_NAME);
        LOGGER.info(queueEntriesCursor.getRowCount() + " Queue Delivery Record Entries");
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) UUID(java.util.UUID)

Example 53 with DatabaseEntry

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

the class ReplicatedEnvironmentFacadeTest method getTestKeyValue.

private String getTestKeyValue(final Database db, final int keyValue) {
    final DatabaseEntry key = new DatabaseEntry();
    final DatabaseEntry result = new DatabaseEntry();
    IntegerBinding.intToEntry(keyValue, key);
    final OperationStatus status = db.get(null, key, result, LockMode.DEFAULT);
    if (status == OperationStatus.SUCCESS) {
        return StringBinding.entryToString(result);
    }
    return null;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 54 with DatabaseEntry

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

the class UpgradeFrom4to5Test method assertContent.

private void assertContent() {
    final UpgradeFrom4To5.ContentBinding contentBinding = new UpgradeFrom4To5.ContentBinding();
    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);
            ByteBuffer content = contentBinding.entryToObject(value);
            assertNotNull("Unexpected content", content);
        }
    };
    new DatabaseTemplate(_environment, MESSAGE_CONTENT_DB_NAME, null).run(contentCursorOperation);
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) ByteBuffer(java.nio.ByteBuffer)

Example 55 with DatabaseEntry

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

the class UpgradeFrom4to5Test method assertQueues.

private void assertQueues(Set<String> expectedQueueNames) {
    List<AMQShortString> durableSubNames = Collections.emptyList();
    final UpgradeFrom4To5.QueueRecordBinding binding = new UpgradeFrom4To5.QueueRecordBinding(durableSubNames);
    final Set<String> actualQueueNames = new HashSet<String>();
    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();
            actualQueueNames.add(queueName);
        }
    };
    new DatabaseTemplate(_environment, "queueDb_v5", null).run(queueNameCollector);
    assertEquals("Unexpected queue names", expectedQueueNames, actualQueueNames);
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Transaction(com.sleepycat.je.Transaction) QueueRecord(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.QueueRecord) Database(com.sleepycat.je.Database) HashSet(java.util.HashSet)

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