Search in sources :

Example 66 with StoreException

use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.

the class MapBinding method entryToObject.

@Override
public Map<String, Object> entryToObject(final TupleInput input) {
    String json = input.readString();
    ObjectMapper mapper = ConfiguredObjectJacksonModule.newObjectMapper(true);
    try {
        Map<String, Object> value = mapper.readValue(json, Map.class);
        return value;
    } catch (IOException e) {
        // should never happen
        throw new StoreException(e);
    }
}
Also used : IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StoreException(org.apache.qpid.server.store.StoreException)

Example 67 with StoreException

use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.

the class UpgradeFrom5To6 method upgradeMessage.

/**
 * Upgrade an individual message, that is read all the data from the old
 * database, consolidate it into a single byte[] and then (in a transaction)
 * remove the record from the old database and add the corresponding record
 * to the new database
 */
private void upgradeMessage(final long messageId, final Database oldDatabase, final Database newDatabase, final UpgradeInteractionHandler handler, Transaction txn, Database oldMetadataDatabase) {
    SortedMap<Integer, byte[]> messageData = getMessageData(messageId, oldDatabase);
    byte[] consolidatedData = new byte[0];
    for (Map.Entry<Integer, byte[]> entry : messageData.entrySet()) {
        int offset = entry.getKey();
        if (offset != consolidatedData.length) {
            String message;
            if (offset < consolidatedData.length) {
                message = "Missing data in message id " + messageId + " between offset " + consolidatedData.length + " and " + offset + ". ";
            } else {
                message = "Duplicate data in message id " + messageId + " between offset " + offset + " and " + consolidatedData.length + ". ";
            }
            UpgradeInteractionResponse action = handler.requireResponse(message + "Do you wish do recover as much of this message as " + "possible (answering NO will delete the message)?", ABORT, YES, NO, ABORT);
            switch(action) {
                case YES:
                    byte[] oldData = consolidatedData;
                    consolidatedData = new byte[offset];
                    System.arraycopy(oldData, 0, consolidatedData, 0, Math.min(oldData.length, consolidatedData.length));
                    break;
                case NO:
                    DatabaseEntry key = new DatabaseEntry();
                    LongBinding.longToEntry(messageId, key);
                    oldMetadataDatabase.delete(txn, key);
                    return;
                case ABORT:
                    LOGGER.error(message);
                    throw new StoreException("Unable to upgrade message " + messageId);
            }
        }
        byte[] data = new byte[consolidatedData.length + entry.getValue().length];
        System.arraycopy(consolidatedData, 0, data, 0, consolidatedData.length);
        System.arraycopy(entry.getValue(), 0, data, offset, entry.getValue().length);
        consolidatedData = data;
    }
    CompoundKeyBinding binding = new CompoundKeyBinding();
    for (int offset : messageData.keySet()) {
        DatabaseEntry key = new DatabaseEntry();
        binding.objectToEntry(new CompoundKey(messageId, offset), key);
        oldDatabase.delete(txn, key);
    }
    DatabaseEntry key = new DatabaseEntry();
    LongBinding.longToEntry(messageId, key);
    NewDataBinding dataBinding = new NewDataBinding();
    DatabaseEntry value = new DatabaseEntry();
    dataBinding.objectToEntry(consolidatedData, value);
    put(newDatabase, txn, key, value);
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 68 with StoreException

use of org.apache.qpid.server.store.StoreException 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)

Example 69 with StoreException

use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.

the class Upgrader method upgradeIfNecessary.

public void upgradeIfNecessary() {
    boolean isEmpty = _environment.getDatabaseNames().isEmpty();
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    Database versionDb = null;
    try {
        versionDb = _environment.openDatabase(null, VERSION_DB_NAME, dbConfig);
        if (versionDb.count() == 0L) {
            int sourceVersion = isEmpty ? BDBConfigurationStore.VERSION : identifyOldStoreVersion();
            DatabaseEntry key = new DatabaseEntry();
            IntegerBinding.intToEntry(sourceVersion, key);
            DatabaseEntry value = new DatabaseEntry();
            LongBinding.longToEntry(System.currentTimeMillis(), value);
            versionDb.put(null, key, value);
        }
        int version = getSourceVersion(versionDb);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Source message store version is " + version);
        }
        if (version > BDBConfigurationStore.VERSION) {
            throw new StoreException("Database version " + version + " is higher than the most recent known version: " + BDBConfigurationStore.VERSION);
        }
        performUpgradeFromVersion(version, versionDb);
    } finally {
        if (versionDb != null) {
            versionDb.close();
        }
    }
}
Also used : Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseConfig(com.sleepycat.je.DatabaseConfig) StoreException(org.apache.qpid.server.store.StoreException)

Example 70 with StoreException

use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.

the class AbstractBDBMessageStore method getAllContent.

QpidByteBuffer getAllContent(long messageId) throws StoreException {
    DatabaseEntry contentKeyEntry = new DatabaseEntry();
    LongBinding.longToEntry(messageId, contentKeyEntry);
    DatabaseEntry value = new DatabaseEntry();
    getLogger().debug("Message Id: {} Getting content body", messageId);
    try {
        OperationStatus status = getMessageContentDb().get(null, contentKeyEntry, value, LockMode.READ_UNCOMMITTED);
        if (status == OperationStatus.SUCCESS) {
            byte[] data = value.getData();
            int offset = value.getOffset();
            int length = value.getSize();
            QpidByteBuffer buf = QpidByteBuffer.allocateDirect(length);
            buf.put(data, offset, length);
            buf.flip();
            return buf;
        } else {
            throw new StoreException("Unable to find message with id " + messageId);
        }
    } catch (RuntimeException e) {
        throw getEnvironmentFacade().handleDatabaseException("Error getting AMQMessage with id " + messageId + " to database: " + e.getMessage(), e);
    }
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException)

Aggregations

StoreException (org.apache.qpid.server.store.StoreException)70 SQLException (java.sql.SQLException)28 Connection (java.sql.Connection)23 PreparedStatement (java.sql.PreparedStatement)21 DatabaseEntry (com.sleepycat.je.DatabaseEntry)20 IOException (java.io.IOException)18 OperationStatus (com.sleepycat.je.OperationStatus)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 ResultSet (java.sql.ResultSet)10 UUID (java.util.UUID)8 Database (com.sleepycat.je.Database)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 ModelVersion (org.apache.qpid.server.model.ModelVersion)7 LinkKey (org.apache.qpid.server.protocol.v1_0.LinkKey)7 HashSet (java.util.HashSet)5 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)5 Cursor (com.sleepycat.je.Cursor)4 DatabaseConfig (com.sleepycat.je.DatabaseConfig)4