use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgradeFrom5To6Test method loadConfiguredObjects.
private Map<UUID, UpgradeConfiguredObjectRecord> loadConfiguredObjects() {
final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjectsRecords = new HashMap<UUID, UpgradeConfiguredObjectRecord>();
final ConfiguredObjectBinding binding = new ConfiguredObjectBinding();
final UpgradeUUIDBinding uuidBinding = new UpgradeUUIDBinding();
CursorOperation configuredObjectsCursor = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
UUID id = uuidBinding.entryToObject(key);
UpgradeConfiguredObjectRecord object = binding.entryToObject(value);
configuredObjectsRecords.put(id, object);
}
};
new DatabaseTemplate(_environment, CONFIGURED_OBJECTS_DB_NAME, null).run(configuredObjectsCursor);
return configuredObjectsRecords;
}
use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgradeFrom7To8Test method loadConfiguredObjects.
private Map<UUID, UpgradeConfiguredObjectRecord> loadConfiguredObjects() {
final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjectsRecords = new HashMap<UUID, UpgradeConfiguredObjectRecord>();
final UpgradeConfiguredObjectBinding binding = new UpgradeConfiguredObjectBinding();
final UpgradeUUIDBinding uuidBinding = new UpgradeUUIDBinding();
CursorOperation configuredObjectsCursor = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
UUID id = uuidBinding.entryToObject(key);
UpgradeConfiguredObjectRecord object = binding.entryToObject(value);
configuredObjectsRecords.put(id, object);
}
};
new DatabaseTemplate(_environment, CONFIGURED_OBJECTS_DB_NAME, null).run(configuredObjectsCursor);
return configuredObjectsRecords;
}
use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgraderTest method assertContent.
private void assertContent() {
final ByteBufferBinding contentBinding = ByteBufferBinding.getInstance();
CursorOperation contentCursorOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
long id = LongBinding.entryToLong(key);
assertTrue("Unexpected id", id > 0);
QpidByteBuffer content = contentBinding.entryToObject(value);
assertNotNull("Unexpected content", content);
assertTrue("Expected content", content.hasRemaining());
}
};
new DatabaseTemplate(_environment, "MESSAGE_CONTENT", null).run(contentCursorOperation);
}
use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class OrphanConfigurationRecordPurger method purge.
private void purge() throws Exception {
EnvironmentConfig config = EnvironmentConfig.DEFAULT;
config.setAllowCreate(false);
config.setTransactional(true);
try (Environment env = createEnvironment(config)) {
final int version = getVersion(env, READ_ONLY_DB_CONFIG);
if (!ALLOWED_VERSIONS.contains(version)) {
throw new IllegalStateException(String.format("Store has unexpected version. Found %d expected %s", version, ALLOWED_VERSIONS));
}
final Transaction tx = env.beginTransaction(null, TransactionConfig.DEFAULT);
boolean success = false;
try {
purgeOrphans(env, tx);
success = true;
} finally {
if (!success) {
System.out.println("No config or config hierarchy records purged.");
tx.abort();
} else if (_dryRun) {
System.out.println("No config or config hierarchy records purged - -dryRun flag specified.");
tx.abort();
} else {
tx.commit();
System.out.format("Config records(s) and associated hierarchy records purged.");
}
}
}
}
use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgradeFrom4To5 method upgradeContent.
private void upgradeContent(final Environment environment, final UpgradeInteractionHandler handler, final Set<Long> messagesToDiscard, Transaction transaction) {
LOGGER.info("Message Contents");
if (environment.getDatabaseNames().contains(OLD_CONTENT_DB_NAME)) {
final MessageContentKeyBinding keyBinding = new MessageContentKeyBinding();
final ContentBinding contentBinding = new ContentBinding();
CursorOperation cursorOperation = new CursorOperation() {
private long _prevMsgId = -1;
private int _bytesSeenSoFar;
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
// determine the msgId of the current entry
MessageContentKey contentKey = keyBinding.entryToObject(key);
long msgId = contentKey.getMessageId();
// ONLY copy data if message is delivered to existing queue
if (messagesToDiscard.contains(msgId)) {
return;
}
// if this is a new message, restart the byte offset count.
if (_prevMsgId != msgId) {
_bytesSeenSoFar = 0;
}
// determine the content size
ByteBuffer content = contentBinding.entryToObject(value);
int contentSize = content.limit();
// create the new key: id + previously seen data count
MessageContentKey newKey = new MessageContentKey(msgId, _bytesSeenSoFar);
DatabaseEntry newKeyEntry = new DatabaseEntry();
keyBinding.objectToEntry(newKey, newKeyEntry);
DatabaseEntry newValueEntry = new DatabaseEntry();
contentBinding.objectToEntry(content, newValueEntry);
targetDatabase.put(null, newKeyEntry, newValueEntry);
_prevMsgId = msgId;
_bytesSeenSoFar += contentSize;
}
};
new DatabaseTemplate(environment, OLD_CONTENT_DB_NAME, NEW_CONTENT_DB_NAME, transaction).run(cursorOperation);
environment.removeDatabase(transaction, OLD_CONTENT_DB_NAME);
LOGGER.info(cursorOperation.getRowCount() + " Message Content entries");
}
}
Aggregations