Search in sources :

Example 66 with DatabaseEntry

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

the class UpgradeFrom5To6Test method getXidKey.

protected DatabaseEntry getXidKey() {
    final DatabaseEntry value = new DatabaseEntry();
    byte[] globalId = { 1 };
    byte[] branchId = { 2 };
    Xid xid = new Xid(1l, globalId, branchId);
    XidBinding xidBinding = XidBinding.getInstance();
    xidBinding.objectToEntry(xid, value);
    return value;
}
Also used : Xid(org.apache.qpid.server.txn.Xid) XidBinding(org.apache.qpid.server.store.berkeleydb.tuple.XidBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 67 with DatabaseEntry

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

the class UpgraderTest method getStoreVersion.

private int getStoreVersion(Environment environment) {
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    int storeVersion = -1;
    try (Database versionDb = environment.openDatabase(null, Upgrader.VERSION_DB_NAME, dbConfig);
        Cursor cursor = versionDb.openCursor(null, null)) {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        while (cursor.getNext(key, value, null) == OperationStatus.SUCCESS) {
            int version = IntegerBinding.entryToInt(key);
            if (storeVersion < version) {
                storeVersion = version;
            }
        }
    }
    return storeVersion;
}
Also used : Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 68 with DatabaseEntry

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

the class DatabasePinger method pingDb.

public void pingDb(EnvironmentFacade facade) {
    try {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Beginning ping transaction");
        }
        final Database db = facade.openDatabase(PING_DATABASE_NAME, DATABASE_CONFIG);
        DatabaseEntry key = new DatabaseEntry();
        IntegerBinding.intToEntry(ID, key);
        DatabaseEntry value = new DatabaseEntry();
        LongBinding.longToEntry(System.currentTimeMillis(), value);
        Transaction txn = null;
        try {
            txn = facade.beginTransaction(_pingTransactionConfig);
            db.put(txn, key, value);
            txn.commit();
            txn = null;
        } finally {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Ping transaction completed");
            }
            if (txn != null) {
                txn.abort();
            }
        }
    } catch (RuntimeException de) {
        RuntimeException handledException = facade.handleDatabaseException("DatabaseException from DatabasePinger ", de);
        LOGGER.debug("Non fatal exception on invoking DatabasePinger. Ignoring...", handledException);
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 69 with DatabaseEntry

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

the class UpgradeFrom4To5 method upgradeQueues.

private Set<String> upgradeQueues(final Environment environment, final UpgradeInteractionHandler handler, List<AMQShortString> potentialDurableSubs, Transaction transaction) {
    LOGGER.info("Queues");
    final Set<String> existingQueues = new HashSet<String>();
    if (environment.getDatabaseNames().contains(OLD_QUEUE_DB_NAME)) {
        final QueueRecordBinding binding = new QueueRecordBinding(potentialDurableSubs);
        CursorOperation databaseOperation = new CursorOperation() {

            @Override
            public void processEntry(final Database sourceDatabase, final Database targetDatabase, final Transaction transaction, final DatabaseEntry key, final DatabaseEntry value) {
                QueueRecord record = binding.entryToObject(value);
                DatabaseEntry newValue = new DatabaseEntry();
                binding.objectToEntry(record, newValue);
                targetDatabase.put(transaction, key, newValue);
                existingQueues.add(record.getNameShortString().toString());
                sourceDatabase.delete(transaction, key);
            }
        };
        new DatabaseTemplate(environment, OLD_QUEUE_DB_NAME, NEW_QUEUE_DB_NAME, transaction).run(databaseOperation);
        environment.removeDatabase(transaction, OLD_QUEUE_DB_NAME);
        LOGGER.info(databaseOperation.getRowCount() + " Queue entries");
    }
    return existingQueues;
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) HashSet(java.util.HashSet)

Example 70 with DatabaseEntry

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

the class UpgradeFrom4To5 method upgradeDelivery.

private Set<Long> upgradeDelivery(final Environment environment, final Set<String> existingQueues, final UpgradeInteractionHandler handler, Transaction transaction) {
    final Set<Long> messagesToDiscard = new HashSet<Long>();
    final Set<String> queuesToDiscard = new HashSet<String>();
    final QueueEntryKeyBinding queueEntryKeyBinding = new QueueEntryKeyBinding();
    LOGGER.info("Delivery Records");
    CursorOperation databaseOperation = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            QueueEntryKey entryKey = queueEntryKeyBinding.entryToObject(key);
            Long messageId = entryKey.getMessageId();
            final String queueName = entryKey.getQueueName().toString();
            if (!existingQueues.contains(queueName)) {
                if (queuesToDiscard.contains(queueName)) {
                    messagesToDiscard.add(messageId);
                } else {
                    String lineSeparator = System.getProperty("line.separator");
                    String question = MessageFormat.format("Found persistent messages for non-durable queue ''{1}''. " + " Do you with to create this queue and move all the messages into it?" + lineSeparator + "NOTE: Answering No will result in these messages being discarded!", queueName);
                    UpgradeInteractionResponse response = handler.requireResponse(question, UpgradeInteractionResponse.YES, UpgradeInteractionResponse.YES, UpgradeInteractionResponse.NO, UpgradeInteractionResponse.ABORT);
                    if (response == UpgradeInteractionResponse.YES) {
                        createQueue(environment, transaction, queueName);
                        existingQueues.add(queueName);
                    } else if (response == UpgradeInteractionResponse.NO) {
                        queuesToDiscard.add(queueName);
                        messagesToDiscard.add(messageId);
                    } else {
                        throw new StoreException("Unable is aborted!");
                    }
                }
            }
            if (!messagesToDiscard.contains(messageId)) {
                DatabaseEntry newKey = new DatabaseEntry();
                queueEntryKeyBinding.objectToEntry(entryKey, newKey);
                targetDatabase.put(transaction, newKey, value);
            }
        }
    };
    new DatabaseTemplate(environment, OLD_DELIVERY_DB, NEW_DELIVERY_DB, transaction).run(databaseOperation);
    if (!messagesToDiscard.isEmpty()) {
        databaseOperation = new CursorOperation() {

            @Override
            public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                QueueEntryKey entryKey = queueEntryKeyBinding.entryToObject(key);
                Long messageId = entryKey.getMessageId();
                if (messagesToDiscard.contains(messageId)) {
                    messagesToDiscard.remove(messageId);
                }
            }
        };
        new DatabaseTemplate(environment, NEW_DELIVERY_DB, transaction).run(databaseOperation);
    }
    LOGGER.info(databaseOperation.getRowCount() + " Delivery Records entries ");
    environment.removeDatabase(transaction, OLD_DELIVERY_DB);
    return messagesToDiscard;
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException) Transaction(com.sleepycat.je.Transaction) 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