use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class UpgradeFrom8To9 method performUpgrade.
@Override
public void performUpgrade(final Environment environment, final UpgradeInteractionHandler handler, final ConfiguredObject<?> parent) {
reportStarting(environment, 8);
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(true);
final Transaction transaction = environment.beginTransaction(null, null);
try {
Database userPreferencesDb = environment.openDatabase(transaction, "USER_PREFERENCES", dbConfig);
userPreferencesDb.close();
try (Database userPreferencesVersionDb = environment.openDatabase(transaction, "USER_PREFERENCES_VERSION", dbConfig)) {
if (userPreferencesVersionDb.count() == 0L) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
StringBinding.stringToEntry(DEFAULT_VERSION, key);
LongBinding.longToEntry(System.currentTimeMillis(), value);
OperationStatus status = userPreferencesVersionDb.put(transaction, key, value);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Error initialising user preference version: " + status);
}
}
}
transaction.commit();
reportFinished(environment, 9);
} catch (RuntimeException e) {
try {
if (transaction.isValid()) {
transaction.abort();
}
} finally {
throw e;
}
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class Upgrader method upgrade.
void upgrade(final int fromVersion, final int toVersion) throws StoreException {
try {
@SuppressWarnings("unchecked") Class<StoreUpgrade> upgradeClass = (Class<StoreUpgrade>) Class.forName("org.apache.qpid.server.store.berkeleydb.upgrade." + "UpgradeFrom" + fromVersion + "To" + toVersion);
Constructor<StoreUpgrade> ctr = upgradeClass.getConstructor();
StoreUpgrade upgrade = ctr.newInstance();
upgrade.performUpgrade(_environment, UpgradeInteractionHandler.DEFAULT_HANDLER, _parent);
} catch (ClassNotFoundException e) {
throw new StoreException("Unable to upgrade BDB data store from version " + fromVersion + " to version" + toVersion, e);
} catch (NoSuchMethodException e) {
throw new StoreException("Unable to upgrade BDB data store from version " + fromVersion + " to version" + toVersion, e);
} catch (InvocationTargetException e) {
throw new StoreException("Unable to upgrade BDB data store from version " + fromVersion + " to version" + toVersion, e);
} catch (InstantiationException e) {
throw new StoreException("Unable to upgrade BDB data store from version " + fromVersion + " to version" + toVersion, e);
} catch (IllegalAccessException e) {
throw new StoreException("Unable to upgrade BDB data store from version " + fromVersion + " to version" + toVersion, e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method getMessageMetaData.
/**
* Retrieves message meta-data.
*
* @param messageId The message to get the meta-data for.
*
* @return The message meta data.
*
* @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist.
*/
StorableMessageMetaData getMessageMetaData(long messageId) throws StoreException {
getLogger().debug("public MessageMetaData getMessageMetaData(Long messageId = {}): called", messageId);
DatabaseEntry key = new DatabaseEntry();
LongBinding.longToEntry(messageId, key);
DatabaseEntry value = new DatabaseEntry();
MessageMetaDataBinding messageBinding = MessageMetaDataBinding.getInstance();
try {
OperationStatus status = getMessageMetaDataDb().get(null, key, value, LockMode.READ_UNCOMMITTED);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Metadata not found for message with id " + messageId);
}
StorableMessageMetaData mdd = messageBinding.entryToObject(value);
return mdd;
} catch (RuntimeException e) {
throw getEnvironmentFacade().handleDatabaseException("Error reading message metadata for message with id " + messageId + ": " + e.getMessage(), e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class BDBLinkStore method getLinkDefinitions.
private Collection<LinkDefinition<Source, Target>> getLinkDefinitions(final LinkStoreUpdater updater) {
Database linksDatabase = getEnvironmentFacade().openDatabase(LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
Collection<LinkDefinition<Source, Target>> links = new HashSet<>();
ModelVersion currentVersion = new ModelVersion(BrokerModel.MODEL_MAJOR_VERSION, BrokerModel.MODEL_MINOR_VERSION);
ModelVersion storedVersion = getStoredVersion();
if (currentVersion.lessThan(storedVersion)) {
throw new StoreException(String.format("Cannot downgrade preference store from '%s' to '%s'", storedVersion, currentVersion));
}
try (Cursor cursor = linksDatabase.openCursor(null, null)) {
final DatabaseEntry key = new DatabaseEntry();
final DatabaseEntry value = new DatabaseEntry();
LinkKeyEntryBinding keyEntryBinding = LinkKeyEntryBinding.getInstance();
LinkValueEntryBinding linkValueEntryBinding = LinkValueEntryBinding.getInstance();
while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
LinkKey linkKey = keyEntryBinding.entryToObject(key);
LinkValue linkValue = linkValueEntryBinding.entryToObject(value);
LinkDefinition<Source, Target> link = new LinkDefinitionImpl<>(linkKey.getRemoteContainerId(), linkKey.getLinkName(), linkKey.getRole(), linkValue.getSource(), linkValue.getTarget());
links.add(link);
}
}
if (storedVersion.lessThan(currentVersion)) {
links = updater.update(storedVersion.toString(), links);
final Transaction txn = getEnvironmentFacade().beginTransaction(null);
try {
linksDatabase = getEnvironmentFacade().clearDatabase(txn, LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
for (LinkDefinition<Source, Target> link : links) {
save(linksDatabase, txn, link);
}
updateVersion(txn, currentVersion.toString());
txn.commit();
linksDatabase.close();
} catch (Exception e) {
txn.abort();
throw e;
}
}
return links;
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class BDBLinkStore method getStoredVersion.
private ModelVersion getStoredVersion() throws RuntimeException {
try (Cursor cursor = getLinksVersionDb().openCursor(null, null)) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
ModelVersion storedVersion = null;
while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
String versionString = StringBinding.entryToString(key);
ModelVersion version = ModelVersion.fromString(versionString);
if (storedVersion == null || storedVersion.lessThan(version)) {
storedVersion = version;
}
}
if (storedVersion == null) {
throw new StoreException("No link version information.");
}
return storedVersion;
} catch (RuntimeException e) {
throw getEnvironmentFacade().handleDatabaseException("Cannot visit link version", e);
}
}
Aggregations