use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method addContent.
/**
* Stores a chunk of message data.
*
* @param tx The transaction for the operation.
* @param messageId The message to store the data for.
* @param contentBody The content of the data chunk.
*
* @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist.
*/
private void addContent(final Transaction tx, long messageId, QpidByteBuffer contentBody) throws StoreException {
DatabaseEntry key = new DatabaseEntry();
LongBinding.longToEntry(messageId, key);
DatabaseEntry value = new DatabaseEntry();
byte[] data = new byte[contentBody.remaining()];
contentBody.copyTo(data);
value.setData(data);
try {
OperationStatus status = getMessageContentDb().put(tx, key, value);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Error adding content for message id " + messageId + ": " + status);
}
getLogger().debug("Storing content for message {} in transaction {}", messageId, tx);
} catch (RuntimeException e) {
throw getEnvironmentFacade().handleDatabaseException("Error writing AMQMessage with id " + messageId + " to database: " + e.getMessage(), e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method dequeueMessage.
/**
* Extracts a message from a specified queue, in a given transaction.
*
* @param tx The transaction for the operation.
* @param queueId The id of the queue to take the message from.
* @param messageId The message to dequeue.
*
* @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist.
*/
private void dequeueMessage(final Transaction tx, final UUID queueId, long messageId) throws StoreException {
DatabaseEntry key = new DatabaseEntry();
QueueEntryKey queueEntryKey = new QueueEntryKey(queueId, messageId);
UUID id = queueId;
QueueEntryBinding.objectToEntry(queueEntryKey, key);
getLogger().debug("Dequeue message id {} from queue with id {}", messageId, id);
try {
OperationStatus status = getDeliveryDb().delete(tx, key);
if (status == OperationStatus.NOTFOUND) {
throw new StoreException("Unable to find message with id " + messageId + " on queue with id " + id);
} else if (status != OperationStatus.SUCCESS) {
throw new StoreException("Unable to remove message with id " + messageId + " on queue with id " + id);
}
getLogger().debug("Removed message {} on queue with id {}", messageId, id);
} catch (RuntimeException e) {
getLogger().error("Failed to dequeue message " + messageId + " in transaction " + tx, e);
throw getEnvironmentFacade().handleDatabaseException("Error accessing database while dequeuing message: " + e.getMessage(), e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractBDBPreferenceStore method updateOrCreateInternal.
private void updateOrCreateInternal(final Transaction txn, final Collection<PreferenceRecord> preferenceRecords) {
Database preferencesDb = getPreferencesDb();
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
MapBinding valueBinding = MapBinding.getInstance();
for (PreferenceRecord record : preferenceRecords) {
keyBinding.objectToEntry(record.getId(), key);
valueBinding.objectToEntry(record.getAttributes(), value);
OperationStatus status = preferencesDb.put(txn, key, value);
if (status != OperationStatus.SUCCESS) {
throw new StoreException(String.format("Error writing preference with id '%s' (status %s)", record.getId(), status.name()));
}
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractBDBPreferenceStore method getStoredVersion.
ModelVersion getStoredVersion() {
try (Cursor cursor = getPreferencesVersionDb().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 preference version information.");
}
return storedVersion;
} catch (RuntimeException e) {
throw getEnvironmentFacade().handleDatabaseException("Cannot visit preference version", e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractBDBPreferenceStore method openAndLoad.
@Override
public Collection<PreferenceRecord> openAndLoad(final PreferenceStoreUpdater updater) throws StoreException {
if (!_storeState.compareAndSet(StoreState.CLOSED, StoreState.OPENING)) {
throw new IllegalStateException(String.format("PreferenceStore cannot be opened when in state '%s'", getStoreState()));
}
EnvironmentFacade environmentFacade = getEnvironmentFacade();
try {
_storeState.set(StoreState.OPENED);
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));
}
Collection<PreferenceRecord> records = getPreferenceRecords(environmentFacade);
if (storedVersion.lessThan(currentVersion)) {
final Collection<UUID> ids = new HashSet<>();
for (PreferenceRecord record : records) {
ids.add(record.getId());
}
records = updater.updatePreferences(storedVersion.toString(), records);
removeAndAdd(ids, records, transaction -> updateVersion(transaction, currentVersion.toString()));
}
return records;
} catch (Exception e) {
_storeState.set(StoreState.ERRORED);
close();
throw e;
}
}
Aggregations