use of com.sleepycat.je.DatabaseConfig in project qpid-broker-j by apache.
the class BDBPreferenceStoreTest method populateTestData.
private void populateTestData(final List<PreferenceRecord> records, final String modelVersion) {
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setTransactional(false);
try (Environment environment = new Environment(_storeFile, envConfig)) {
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
try (Database versionDb = environment.openDatabase(null, "USER_PREFERENCES_VERSION", dbConfig);
Database preferencesDb = environment.openDatabase(null, "USER_PREFERENCES", dbConfig)) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
MapBinding valueBinding = MapBinding.getInstance();
for (PreferenceRecord record : records) {
keyBinding.objectToEntry(record.getId(), key);
valueBinding.objectToEntry(record.getAttributes(), value);
preferencesDb.put(null, key, value);
}
ByteBinding.byteToEntry((byte) 0, value);
StringBinding.stringToEntry(modelVersion, key);
versionDb.put(null, key, value);
}
}
}
use of com.sleepycat.je.DatabaseConfig 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.DatabaseConfig in project qpid-broker-j by apache.
the class UpgraderFailOnNewerVersionTest method getStoreVersion.
private int getStoreVersion() {
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.DatabaseConfig in project qpid-broker-j by apache.
the class BDBLinkStore method getLinksVersionDb.
private Database getLinksVersionDb() {
Database linksVersionDb;
try {
DatabaseConfig config = new DatabaseConfig().setTransactional(true).setAllowCreate(false);
linksVersionDb = getEnvironmentFacade().openDatabase(LINKS_VERSION_DB_NAME, config);
} catch (DatabaseNotFoundException e) {
updateVersion(null, BrokerModel.MODEL_VERSION);
linksVersionDb = getEnvironmentFacade().openDatabase(LINKS_VERSION_DB_NAME, DEFAULT_DATABASE_CONFIG);
}
return linksVersionDb;
}
use of com.sleepycat.je.DatabaseConfig in project qpid-broker-j by apache.
the class EnvironmentUtils method getDatabaseStatistics.
public static Map<String, Object> getDatabaseStatistics(Environment environment, String database, boolean reset) {
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setReadOnly(true);
DbInternal.setUseExistingConfig(dbConfig, true);
try (Database db = environment.openDatabase(null, database, dbConfig)) {
StatsConfig config = new StatsConfig();
config.setClear(reset);
config.setFast(false);
BtreeStats stats = (BtreeStats) db.getStats(config);
Map<String, Object> results = new TreeMap<>();
results.put(BTREE_BIN_COUNT.getName(), stats.getBottomInternalNodeCount());
results.put(BTREE_DELETED_LN_COUNT.getName(), stats.getDeletedLeafNodeCount());
results.put(BTREE_IN_COUNT.getName(), stats.getInternalNodeCount());
results.put(BTREE_LN_COUNT.getName(), stats.getLeafNodeCount());
results.put(BTREE_MAINTREE_MAXDEPTH.getName(), stats.getMainTreeMaxDepth());
results.put(BTREE_INS_BYLEVEL.getName(), Arrays.asList(stats.getINsByLevel()));
results.put(BTREE_BINS_BYLEVEL.getName(), Arrays.asList(stats.getBINsByLevel()));
results.put(BTREE_BIN_ENTRIES_HISTOGRAM.getName(), Arrays.asList(stats.getBINEntriesHistogram()));
results.put(BTREE_RELATCHES_REQUIRED.getName(), stats.getRelatches());
results.put(BTREE_ROOT_SPLITS.getName(), stats.getRootSplits());
return results;
}
}
Aggregations