Search in sources :

Example 21 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig in project BIMserver by opensourceBIM.

the class BerkeleyKeyValueStore method createTable.

public boolean createTable(String tableName, DatabaseSession databaseSession, boolean transactional) throws BimserverDatabaseException {
    if (tables.containsKey(tableName)) {
        throw new BimserverDatabaseException("Table " + tableName + " already created");
    }
    DatabaseConfig databaseConfig = new DatabaseConfig();
    databaseConfig.setKeyPrefixing(keyPrefixing);
    databaseConfig.setAllowCreate(true);
    boolean finalTransactional = transactional && useTransactions;
    databaseConfig.setDeferredWrite(!finalTransactional);
    // if (!transactional) {
    // databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
    // }
    databaseConfig.setTransactional(finalTransactional);
    databaseConfig.setSortedDuplicates(false);
    Database database = environment.openDatabase(null, tableName, databaseConfig);
    if (database == null) {
        return false;
    }
    tables.put(tableName, new TableWrapper(database, finalTransactional));
    return true;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) Database(com.sleepycat.je.Database) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 22 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig in project radixdlt by radixdlt.

the class BerkeleySafetyStateStore method open.

private Database open() {
    DatabaseConfig primaryConfig = new DatabaseConfig();
    primaryConfig.setAllowCreate(true);
    primaryConfig.setTransactional(true);
    try {
        // This SuppressWarnings here is valid, as ownership of the underlying
        // resource is not changed here, the resource is just accessed.
        @SuppressWarnings("resource") Environment env = this.dbEnv.getEnvironment();
        return env.openDatabase(null, SAFETY_STORE_NAME, primaryConfig);
    } catch (Exception e) {
        throw new BerkeleyStoreException("Error while opening database", e);
    }
}
Also used : DatabaseEnvironment(com.radixdlt.store.DatabaseEnvironment) Environment(com.sleepycat.je.Environment) DeserializeException(com.radixdlt.serialization.DeserializeException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 23 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig in project radixdlt by radixdlt.

the class BerkeleyRecoverableProcessedTxnStore method open.

@Override
public void open(DatabaseEnvironment dbEnv) {
    recoverableTransactionsDatabase = dbEnv.getEnvironment().openDatabase(null, RECOVERABLE_TRANSACTIONS_DB_NAME, new DatabaseConfig().setAllowCreate(true).setTransactional(true).setKeyPrefixing(true).setBtreeComparator(lexicographicalComparator()));
    accumulatorDatabase = dbEnv.getEnvironment().openDatabase(null, ACCUMULATOR_HASH_DB_NAME, new DatabaseConfig().setAllowCreate(true).setTransactional(true).setKeyPrefixing(true).setBtreeComparator(lexicographicalComparator()));
    try (var cursor = accumulatorDatabase.openCursor(null, null)) {
        var key = new DatabaseEntry(Longs.toByteArray(Long.MAX_VALUE));
        var value = new DatabaseEntry();
        cursor.getSearchKeyRange(key, value, null);
        var status = cursor.getPrev(key, value, null);
        if (status == SUCCESS) {
            var accumulatorHash = HashCode.fromBytes(value.getData());
            var stateVersion = Longs.fromByteArray(key.getData());
            this.accumulatorState = new AccumulatorState(stateVersion, accumulatorHash);
        } else {
            this.accumulatorState = new AccumulatorState(0, HashUtils.zero256());
        }
    }
}
Also used : AccumulatorState(com.radixdlt.ledger.AccumulatorState) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 24 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig in project kcache by rayokota.

the class BdbJECache method openDB.

@Override
protected void openDB() {
    try {
        // Environment and database opens
        EnvironmentConfig envConfig = new EnvironmentConfig();
        envConfig.setAllowCreate(true);
        envConfig.setTransactional(true);
        // Data is synced in flush()
        envConfig.setDurability(Durability.COMMIT_NO_SYNC);
        env = new Environment(dbDir(), envConfig);
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        dbConfig.setTransactional(true);
        dbConfig.setKeyPrefixing(true);
        dbConfig.setBtreeComparator(new KeyBytesComparator<>(keySerde(), comparator()));
        db = env.openDatabase(null, name(), dbConfig);
    } catch (final Exception e) {
        throw new CacheInitializationException("Error opening store " + name() + " at location " + dbDir(), e);
    }
}
Also used : EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) CacheInitializationException(io.kcache.exceptions.CacheInitializationException) SerializationException(org.apache.kafka.common.errors.SerializationException) CacheInitializationException(io.kcache.exceptions.CacheInitializationException) NoSuchElementException(java.util.NoSuchElementException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 25 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig in project parliament by SemWebCentral.

the class PersistentTemporalIndex method initializeEnvironment.

private void initializeEnvironment(boolean newEnvironment) throws EnvironmentLockedException, DatabaseException {
    if (newEnvironment) {
        File dirFile = new File(dirName);
        dirFile.mkdirs();
        envConfig = new EnvironmentConfig();
        envConfig.setAllowCreate(true);
        envConfig.setLocking(false);
        envConfig.setReadOnly(false);
        envConfig.setTransactional(false);
        environment = new Environment(dirFile, envConfig);
    }
    dbConfig = new DatabaseConfig();
    dbConfig.setAllowCreate(true);
    dbConfig.setDeferredWrite(true);
    dbConfig.setReadOnly(false);
    dbConfig.setTransactional(false);
    // Create secondary database for indexing Starts
    startsConfig = new SecondaryConfig();
    startsConfig.setAllowCreate(true);
    startsConfig.setSortedDuplicates(true);
    startsConfig.setAllowPopulate(true);
    startsConfig.setKeyCreator(new StartsKeyCreator());
    // Create secondary database for indexing Ends
    endsConfig = new SecondaryConfig();
    endsConfig.setAllowCreate(true);
    endsConfig.setSortedDuplicates(true);
    endsConfig.setAllowPopulate(true);
    endsConfig.setKeyCreator(new EndsKeyCreator());
    initialized = true;
}
Also used : SecondaryConfig(com.sleepycat.je.SecondaryConfig) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) File(java.io.File) 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