use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class Upgrader method upgradeIfNecessary.
public void upgradeIfNecessary() {
boolean isEmpty = _environment.getDatabaseNames().isEmpty();
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(true);
Database versionDb = null;
try {
versionDb = _environment.openDatabase(null, VERSION_DB_NAME, dbConfig);
if (versionDb.count() == 0L) {
int sourceVersion = isEmpty ? BDBConfigurationStore.VERSION : identifyOldStoreVersion();
DatabaseEntry key = new DatabaseEntry();
IntegerBinding.intToEntry(sourceVersion, key);
DatabaseEntry value = new DatabaseEntry();
LongBinding.longToEntry(System.currentTimeMillis(), value);
versionDb.put(null, key, value);
}
int version = getSourceVersion(versionDb);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Source message store version is " + version);
}
if (version > BDBConfigurationStore.VERSION) {
throw new StoreException("Database version " + version + " is higher than the most recent known version: " + BDBConfigurationStore.VERSION);
}
performUpgradeFromVersion(version, versionDb);
} finally {
if (versionDb != null) {
versionDb.close();
}
}
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacadeTest method testNodeRolledback.
@Test
public void testNodeRolledback() throws Exception {
DatabaseConfig createConfig = createDatabaseConfig();
TestStateChangeListener masterListener = new TestStateChangeListener();
ReplicatedEnvironmentFacade node1 = addNode(TEST_NODE_NAME, TEST_NODE_HOST_PORT, true, masterListener, new NoopReplicationGroupListener());
assertTrue("Environment was not created", masterListener.awaitForStateChange(State.MASTER, _timeout, TimeUnit.SECONDS));
String replicaNodeHostPort = "localhost:" + _portHelper.getNextAvailable();
String replicaName = TEST_NODE_NAME + 1;
ReplicatedEnvironmentFacade node2 = createReplica(replicaName, replicaNodeHostPort, new NoopReplicationGroupListener());
Database db = node1.openDatabase("mydb", createConfig);
// Put a record (that will be replicated)
putRecord(node1, db, 1, "value1", false);
node2.close();
// Put a record (that will be only on node1 as node2 is now offline)
putRecord(node1, db, 2, "value2", false);
db.close();
// Stop node1
node1.close();
LOGGER.debug("RESTARTING " + replicaName);
// Restart the node2, making it primary so it becomes master
TestStateChangeListener node2StateChangeListener = new TestStateChangeListener();
node2 = addNode(replicaName, replicaNodeHostPort, true, node2StateChangeListener, new NoopReplicationGroupListener());
boolean awaitForStateChange = node2StateChangeListener.awaitForStateChange(State.MASTER, _timeout, TimeUnit.SECONDS);
assertTrue(replicaName + " did not go into desired state; current actual state is " + node2StateChangeListener.getCurrentActualState(), awaitForStateChange);
db = node2.openDatabase("mydb", DatabaseConfig.DEFAULT);
// Do a transaction on node2. The two environments will have diverged
putRecord(node2, db, 3, "diverged", false);
LOGGER.debug("RESTARTING " + TEST_NODE_NAME);
// Now restart node1 and ensure that it realises it needs to rollback before it can rejoin.
TestStateChangeListener node1StateChangeListener = new TestStateChangeListener();
final CountDownLatch _replicaRolledback = new CountDownLatch(1);
node1 = addNode(node1StateChangeListener, new NoopReplicationGroupListener() {
@Override
public void onNodeRolledback() {
LOGGER.debug("onNodeRolledback in " + TEST_NODE_NAME);
_replicaRolledback.countDown();
}
});
assertTrue("Node 1 did not go into desired state", node1StateChangeListener.awaitForStateChange(State.REPLICA, _timeout, TimeUnit.SECONDS));
assertTrue("Node 1 did not experience rollback within timeout", _replicaRolledback.await(_timeout, TimeUnit.SECONDS));
// Finally do one more transaction through the master
putRecord(node2, db, 4, "value4", false);
db.close();
LOGGER.debug("CLOSING");
node1.close();
node2.close();
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom4to5Test method loadBindings.
private List<BindingRecord> loadBindings() {
final BindingTuple bindingTuple = new BindingTuple();
final List<BindingRecord> queueBindings = new ArrayList<BindingRecord>();
CursorOperation databaseOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
BindingRecord bindingRecord = bindingTuple.entryToObject(key);
AMQShortString queueName = bindingRecord.getQueueName();
AMQShortString exchangeName = bindingRecord.getExchangeName();
AMQShortString routingKey = bindingRecord.getRoutingKey();
FieldTable arguments = bindingRecord.getArguments();
queueBindings.add(new BindingRecord(exchangeName, queueName, routingKey, arguments));
}
};
new DatabaseTemplate(_environment, BINDING_DB_NAME, null).run(databaseOperation);
return queueBindings;
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom4to5Test method assertMetadataForQueue.
private void assertMetadataForQueue(final String queueName, final int expectedQueueSize, final Set<Long> messageIdsForQueue) {
final AtomicInteger metadataCounter = new AtomicInteger();
CursorOperation databaseOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
Long messageId = LongBinding.entryToLong(key);
boolean messageIsForTheRightQueue = messageIdsForQueue.contains(messageId);
if (messageIsForTheRightQueue) {
metadataCounter.incrementAndGet();
}
}
};
new DatabaseTemplate(_environment, MESSAGE_META_DATA_DB_NAME, null).run(databaseOperation);
assertEquals("Unxpected number of entries in metadata db for queue " + queueName, expectedQueueSize, metadataCounter.get());
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom4to5Test method assertDeliveriesForQueue.
private Set<Long> assertDeliveriesForQueue(final String queueName, final int expectedQueueSize) {
final QueueEntryKeyBinding queueEntryKeyBinding = new QueueEntryKeyBinding();
final AtomicInteger deliveryCounter = new AtomicInteger();
final Set<Long> messagesForQueue = new HashSet<Long>();
CursorOperation deliveryDatabaseOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
QueueEntryKey entryKey = queueEntryKeyBinding.entryToObject(key);
String thisQueueName = entryKey.getQueueName().toString();
if (thisQueueName.equals(queueName)) {
deliveryCounter.incrementAndGet();
messagesForQueue.add(entryKey.getMessageId());
}
}
};
new DatabaseTemplate(_environment, DELIVERY_DB_NAME, null).run(deliveryDatabaseOperation);
assertEquals("Unxpected number of entries in delivery db for queue " + queueName, expectedQueueSize, deliveryCounter.get());
return messagesForQueue;
}
Aggregations