use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class UpgradeFrom5To6Test method getXidKey.
protected DatabaseEntry getXidKey() {
final DatabaseEntry value = new DatabaseEntry();
byte[] globalId = { 1 };
byte[] branchId = { 2 };
Xid xid = new Xid(1l, globalId, branchId);
XidBinding xidBinding = XidBinding.getInstance();
xidBinding.objectToEntry(xid, value);
return value;
}
use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class UpgraderTest method getStoreVersion.
private int getStoreVersion(Environment environment) {
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(true);
int storeVersion = -1;
try (Database versionDb = environment.openDatabase(null, Upgrader.VERSION_DB_NAME, dbConfig);
Cursor cursor = versionDb.openCursor(null, null)) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
while (cursor.getNext(key, value, null) == OperationStatus.SUCCESS) {
int version = IntegerBinding.entryToInt(key);
if (storeVersion < version) {
storeVersion = version;
}
}
}
return storeVersion;
}
use of com.sleepycat.je.DatabaseEntry 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.DatabaseEntry in project qpid-broker-j by apache.
the class UpgradeFrom4To5 method upgradeQueues.
private Set<String> upgradeQueues(final Environment environment, final UpgradeInteractionHandler handler, List<AMQShortString> potentialDurableSubs, Transaction transaction) {
LOGGER.info("Queues");
final Set<String> existingQueues = new HashSet<String>();
if (environment.getDatabaseNames().contains(OLD_QUEUE_DB_NAME)) {
final QueueRecordBinding binding = new QueueRecordBinding(potentialDurableSubs);
CursorOperation databaseOperation = new CursorOperation() {
@Override
public void processEntry(final Database sourceDatabase, final Database targetDatabase, final Transaction transaction, final DatabaseEntry key, final DatabaseEntry value) {
QueueRecord record = binding.entryToObject(value);
DatabaseEntry newValue = new DatabaseEntry();
binding.objectToEntry(record, newValue);
targetDatabase.put(transaction, key, newValue);
existingQueues.add(record.getNameShortString().toString());
sourceDatabase.delete(transaction, key);
}
};
new DatabaseTemplate(environment, OLD_QUEUE_DB_NAME, NEW_QUEUE_DB_NAME, transaction).run(databaseOperation);
environment.removeDatabase(transaction, OLD_QUEUE_DB_NAME);
LOGGER.info(databaseOperation.getRowCount() + " Queue entries");
}
return existingQueues;
}
use of com.sleepycat.je.DatabaseEntry 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