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);
}
}
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);
}
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);
}
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();
}
}
}
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);
}
}
Aggregations