use of com.sleepycat.je.Transaction 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);
}
}
use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgradeFrom4To5 method performUpgrade.
@Override
public void performUpgrade(final Environment environment, final UpgradeInteractionHandler handler, ConfiguredObject<?> parent) {
Transaction transaction = null;
reportStarting(environment, 4);
transaction = environment.beginTransaction(null, null);
// find all queues which are bound to a topic exchange and which have a colon in their name
final List<AMQShortString> potentialDurableSubs = findPotentialDurableSubscriptions(environment, transaction);
Set<String> existingQueues = upgradeQueues(environment, handler, potentialDurableSubs, transaction);
upgradeQueueBindings(environment, handler, potentialDurableSubs, transaction);
Set<Long> messagesToDiscard = upgradeDelivery(environment, existingQueues, handler, transaction);
upgradeContent(environment, handler, messagesToDiscard, transaction);
upgradeMetaData(environment, handler, messagesToDiscard, transaction);
renameRemainingDatabases(environment, handler, transaction);
transaction.commit();
reportFinished(environment, 5);
}
use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgradeFrom4To5 method upgradeQueueBindings.
private void upgradeQueueBindings(Environment environment, UpgradeInteractionHandler handler, final List<AMQShortString> potentialDurableSubs, Transaction transaction) {
if (environment.getDatabaseNames().contains(OLD_BINDINGS_DB_NAME)) {
LOGGER.info("Queue Bindings");
final BindingTuple bindingTuple = new BindingTuple();
CursorOperation databaseOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
// All the information required in binding entries is actually in the *key* not value.
BindingRecord oldBindingRecord = bindingTuple.entryToObject(key);
AMQShortString queueName = oldBindingRecord.getQueueName();
AMQShortString exchangeName = oldBindingRecord.getExchangeName();
AMQShortString routingKey = oldBindingRecord.getRoutingKey();
FieldTable arguments = oldBindingRecord.getArguments();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Processing binding for queue %s, exchange %s, routingKey %s arguments %s", queueName, exchangeName, routingKey, arguments));
}
// only topic exchange should have a JMS selector key in binding
if (potentialDurableSubs.contains(queueName) && exchangeName.equals(AMQShortString.valueOf(ExchangeDefaults.TOPIC_EXCHANGE_NAME))) {
if (arguments == null) {
arguments = new FieldTable();
}
AMQShortString selectorFilterKey = AMQShortString.valueOf(AMQPFilterTypes.JMS_SELECTOR.getValue());
if (!arguments.containsKey(selectorFilterKey)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.info("adding the empty string (i.e. 'no selector') value for " + queueName + " and exchange " + exchangeName);
}
arguments.put(selectorFilterKey, "");
}
}
addBindingToDatabase(bindingTuple, targetDatabase, transaction, queueName, exchangeName, routingKey, arguments);
}
};
new DatabaseTemplate(environment, OLD_BINDINGS_DB_NAME, NEW_BINDINGS_DB_NAME, transaction).run(databaseOperation);
environment.removeDatabase(transaction, OLD_BINDINGS_DB_NAME);
LOGGER.info(databaseOperation.getRowCount() + " Queue Binding entries");
}
}
use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgradeFrom4To5 method createQueue.
protected void createQueue(final Environment environment, Transaction transaction, final String queueName) {
final QueueRecordBinding binding = new QueueRecordBinding(null);
final BindingTuple bindingTuple = new BindingTuple();
DatabaseRunnable queueCreateOperation = new DatabaseRunnable() {
@Override
public void run(Database newQueueDatabase, Database newBindingsDatabase, Transaction transaction) {
AMQShortString queueNameAMQ = new AMQShortString(queueName);
QueueRecord record = new QueueRecord(queueNameAMQ, null, false, null);
DatabaseEntry key = new DatabaseEntry();
TupleOutput output = new TupleOutput();
AMQShortStringEncoding.writeShortString(record.getNameShortString(), output);
TupleBase.outputToEntry(output, key);
DatabaseEntry newValue = new DatabaseEntry();
binding.objectToEntry(record, newValue);
newQueueDatabase.put(transaction, key, newValue);
FieldTable emptyArguments = new FieldTable();
addBindingToDatabase(bindingTuple, newBindingsDatabase, transaction, queueNameAMQ, AMQShortString.valueOf(ExchangeDefaults.DIRECT_EXCHANGE_NAME), queueNameAMQ, emptyArguments);
// TODO QPID-3490 we should not persist a default exchange binding
addBindingToDatabase(bindingTuple, newBindingsDatabase, transaction, queueNameAMQ, AMQShortString.valueOf(ExchangeDefaults.DEFAULT_EXCHANGE_NAME), queueNameAMQ, emptyArguments);
}
};
new DatabaseTemplate(environment, NEW_QUEUE_DB_NAME, NEW_BINDINGS_DB_NAME, transaction).run(queueCreateOperation);
}
use of com.sleepycat.je.Transaction 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;
}
Aggregations