Search in sources :

Example 36 with DatabaseConfig

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);
        }
    }
}
Also used : MapBinding(org.apache.qpid.server.store.berkeleydb.tuple.MapBinding) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Database(com.sleepycat.je.Database) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) Environment(com.sleepycat.je.Environment) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 37 with DatabaseConfig

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();
}
Also used : ReplicatedEnvironmentFacade(org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade) Database(com.sleepycat.je.Database) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CountDownLatch(java.util.concurrent.CountDownLatch) DatabaseConfig(com.sleepycat.je.DatabaseConfig) Test(org.junit.Test)

Example 38 with DatabaseConfig

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;
}
Also used : Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 39 with DatabaseConfig

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;
}
Also used : DatabaseNotFoundException(com.sleepycat.je.DatabaseNotFoundException) Database(com.sleepycat.je.Database) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 40 with DatabaseConfig

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;
    }
}
Also used : BtreeStats(com.sleepycat.je.BtreeStats) StatsConfig(com.sleepycat.je.StatsConfig) Database(com.sleepycat.je.Database) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) TreeMap(java.util.TreeMap) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Aggregations

DatabaseConfig (com.sleepycat.je.DatabaseConfig)56 Database (com.sleepycat.je.Database)30 Environment (com.sleepycat.je.Environment)26 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)23 DatabaseEntry (com.sleepycat.je.DatabaseEntry)13 File (java.io.File)12 Transaction (com.sleepycat.je.Transaction)7 Test (org.junit.Test)7 Cursor (com.sleepycat.je.Cursor)6 DatabaseException (com.sleepycat.je.DatabaseException)6 IOException (java.io.IOException)4 Map (java.util.Map)4 StoreException (org.apache.qpid.server.store.StoreException)4 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 OperationStatus (com.sleepycat.je.OperationStatus)3 HashMap (java.util.HashMap)3 StoredClassCatalog (com.sleepycat.bind.serial.StoredClassCatalog)2 StringBinding (com.sleepycat.bind.tuple.StringBinding)2 TupleInput (com.sleepycat.bind.tuple.TupleInput)2 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)2