Search in sources :

Example 56 with Transaction

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

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

the class UpgradeFrom7To8Test method loadConfiguredObjects.

private Map<UUID, UpgradeConfiguredObjectRecord> loadConfiguredObjects() {
    final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjectsRecords = new HashMap<UUID, UpgradeConfiguredObjectRecord>();
    final UpgradeConfiguredObjectBinding binding = new UpgradeConfiguredObjectBinding();
    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 : 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 Transaction

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

Example 59 with Transaction

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

the class OrphanConfigurationRecordPurger method purge.

private void purge() throws Exception {
    EnvironmentConfig config = EnvironmentConfig.DEFAULT;
    config.setAllowCreate(false);
    config.setTransactional(true);
    try (Environment env = createEnvironment(config)) {
        final int version = getVersion(env, READ_ONLY_DB_CONFIG);
        if (!ALLOWED_VERSIONS.contains(version)) {
            throw new IllegalStateException(String.format("Store has unexpected version. Found %d expected %s", version, ALLOWED_VERSIONS));
        }
        final Transaction tx = env.beginTransaction(null, TransactionConfig.DEFAULT);
        boolean success = false;
        try {
            purgeOrphans(env, tx);
            success = true;
        } finally {
            if (!success) {
                System.out.println("No config or config hierarchy records purged.");
                tx.abort();
            } else if (_dryRun) {
                System.out.println("No config or config hierarchy records purged - -dryRun flag specified.");
                tx.abort();
            } else {
                tx.commit();
                System.out.format("Config records(s) and associated hierarchy records purged.");
            }
        }
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) ReplicatedEnvironment(com.sleepycat.je.rep.ReplicatedEnvironment)

Example 60 with Transaction

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

the class UpgradeFrom4To5 method upgradeContent.

private void upgradeContent(final Environment environment, final UpgradeInteractionHandler handler, final Set<Long> messagesToDiscard, Transaction transaction) {
    LOGGER.info("Message Contents");
    if (environment.getDatabaseNames().contains(OLD_CONTENT_DB_NAME)) {
        final MessageContentKeyBinding keyBinding = new MessageContentKeyBinding();
        final ContentBinding contentBinding = new ContentBinding();
        CursorOperation cursorOperation = new CursorOperation() {

            private long _prevMsgId = -1;

            private int _bytesSeenSoFar;

            @Override
            public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                // determine the msgId of the current entry
                MessageContentKey contentKey = keyBinding.entryToObject(key);
                long msgId = contentKey.getMessageId();
                // ONLY copy data if message is delivered to existing queue
                if (messagesToDiscard.contains(msgId)) {
                    return;
                }
                // if this is a new message, restart the byte offset count.
                if (_prevMsgId != msgId) {
                    _bytesSeenSoFar = 0;
                }
                // determine the content size
                ByteBuffer content = contentBinding.entryToObject(value);
                int contentSize = content.limit();
                // create the new key: id + previously seen data count
                MessageContentKey newKey = new MessageContentKey(msgId, _bytesSeenSoFar);
                DatabaseEntry newKeyEntry = new DatabaseEntry();
                keyBinding.objectToEntry(newKey, newKeyEntry);
                DatabaseEntry newValueEntry = new DatabaseEntry();
                contentBinding.objectToEntry(content, newValueEntry);
                targetDatabase.put(null, newKeyEntry, newValueEntry);
                _prevMsgId = msgId;
                _bytesSeenSoFar += contentSize;
            }
        };
        new DatabaseTemplate(environment, OLD_CONTENT_DB_NAME, NEW_CONTENT_DB_NAME, transaction).run(cursorOperation);
        environment.removeDatabase(transaction, OLD_CONTENT_DB_NAME);
        LOGGER.info(cursorOperation.getRowCount() + " Message Content entries");
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

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