Search in sources :

Example 61 with Database

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

the class UpgradeFrom5To6 method upgradeQueueBindings.

private void upgradeQueueBindings(Environment environment, Transaction transaction, final UpgradeInteractionHandler handler, final String virtualHostName) {
    LOGGER.info("Queue Bindings");
    if (environment.getDatabaseNames().contains(OLD_QUEUE_BINDINGS_DB_NAME)) {
        final QueueBindingBinding binding = new QueueBindingBinding();
        CursorOperation bindingCursor = new CursorOperation() {

            @Override
            public void processEntry(Database exchangeDatabase, Database configuredObjectsDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                // TODO: check and remove orphaned bindings
                BindingRecord bindingRecord = binding.entryToObject(key);
                String exchangeName = bindingRecord.getExchangeName() == null ? ExchangeDefaults.DEFAULT_EXCHANGE_NAME : bindingRecord.getExchangeName().toString();
                String queueName = bindingRecord.getQueueName().toString();
                String routingKey = bindingRecord.getRoutingKey().toString();
                FieldTable arguments = bindingRecord.getArguments();
                UUID bindingId = UUIDGenerator.generateBindingUUID(exchangeName, queueName, routingKey, virtualHostName);
                UpgradeConfiguredObjectRecord configuredObject = createBindingConfiguredObjectRecord(exchangeName, queueName, routingKey, arguments, virtualHostName);
                storeConfiguredObjectEntry(configuredObjectsDatabase, bindingId, configuredObject, transaction);
            }
        };
        new DatabaseTemplate(environment, OLD_QUEUE_BINDINGS_DB_NAME, CONFIGURED_OBJECTS_DB_NAME, transaction).run(bindingCursor);
        environment.removeDatabase(transaction, OLD_QUEUE_BINDINGS_DB_NAME);
        LOGGER.info(bindingCursor.getRowCount() + " Queue Binding Entries");
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) UUID(java.util.UUID)

Example 62 with Database

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

the class AbstractBDBPreferenceStore method updateVersion.

private Database updateVersion(Transaction txn, final String currentVersion) {
    final Database preferencesVersionDb = getEnvironmentFacade().openDatabase(PREFERENCES_VERSION_DB_NAME, DEFAULT_DATABASE_CONFIG);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    StringBinding.stringToEntry(currentVersion, key);
    LongBinding.longToEntry(System.currentTimeMillis(), value);
    preferencesVersionDb.put(txn, key, value);
    return preferencesVersionDb;
}
Also used : Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 63 with Database

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

Example 64 with Database

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

the class DatabaseTemplate method call.

public <T> T call(DatabaseCallable<T> databaseCallable) {
    Database sourceDatabase = null;
    Database targetDatabase = null;
    try {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setTransactional(true);
        dbConfig.setAllowCreate(true);
        sourceDatabase = _environment.openDatabase(_parentTransaction, _sourceDatabaseName, dbConfig);
        if (_targetDatabaseName != null) {
            targetDatabase = _environment.openDatabase(_parentTransaction, _targetDatabaseName, dbConfig);
        }
        return databaseCallable.call(sourceDatabase, targetDatabase, _parentTransaction);
    } finally {
        closeDatabase(sourceDatabase);
        closeDatabase(targetDatabase);
    }
}
Also used : Database(com.sleepycat.je.Database) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 65 with Database

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

the class UpgradeFrom6To7 method performUpgrade.

@Override
public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent) {
    reportStarting(environment, 6);
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    Database versionDb = environment.openDatabase(null, "CONFIG_VERSION", dbConfig);
    if (versionDb.count() == 0L) {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        IntegerBinding.intToEntry(DEFAULT_CONFIG_VERSION, value);
        ByteBinding.byteToEntry((byte) 0, key);
        OperationStatus status = versionDb.put(null, key, value);
        if (status != OperationStatus.SUCCESS) {
            throw new StoreException("Error initialising config version: " + status);
        }
    }
    versionDb.close();
    reportFinished(environment, 7);
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseConfig(com.sleepycat.je.DatabaseConfig) StoreException(org.apache.qpid.server.store.StoreException)

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