Search in sources :

Example 1 with Environment

use of com.sleepycat.je.Environment in project OpenRefine by OpenRefine.

the class RefineBrokerImpl method init.

@Override
public void init(ServletConfig config) throws Exception {
    logger.trace("> init");
    super.init(config);
    timer = new Timer();
    expirer = new Expirer();
    timer.schedule(expirer, 0, LOCK_EXPIRATION_CHECK_DELAY);
    String dataDir = config.getInitParameter("refine.data");
    if (dataDir == null)
        dataDir = "data";
    File dataPath = new File(dataDir);
    if (!dataPath.exists())
        dataPath.mkdirs();
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(true);
    env = new Environment(dataPath, envConfig);
    StoreConfig storeConfig = new StoreConfig();
    storeConfig.setAllowCreate(true);
    storeConfig.setTransactional(true);
    projectStore = new EntityStore(env, "ProjectsStore", storeConfig);
    lockStore = new EntityStore(env, "LockStore", storeConfig);
    projectById = projectStore.getPrimaryIndex(String.class, Project.class);
    lockById = lockStore.getPrimaryIndex(String.class, Lock.class);
    locksByProject = lockStore.getSecondaryIndex(lockById, String.class, "pid");
    logger.trace("< init");
}
Also used : Timer(java.util.Timer) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) StoreConfig(com.sleepycat.persist.StoreConfig) EntityStore(com.sleepycat.persist.EntityStore) File(java.io.File)

Example 2 with Environment

use of com.sleepycat.je.Environment in project GeoGig by boundlessgeo.

the class JEObjectDatabase method createDatabase.

protected Database createDatabase() {
    final String databaseName = "ObjectDatabase";
    Environment environment;
    try {
        environment = createEnvironment(readOnly);
    } catch (EnvironmentLockedException e) {
        throw new IllegalStateException("The repository is already open by another process for writing", e);
    }
    if (!environment.getDatabaseNames().contains(databaseName)) {
        if (readOnly) {
            environment.close();
            try {
                environment = createEnvironment(false);
            } catch (EnvironmentLockedException e) {
                throw new IllegalStateException(String.format("Environment open readonly but database %s does not exist.", databaseName));
            }
        }
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        Database openDatabase = environment.openDatabase(null, databaseName, dbConfig);
        openDatabase.close();
        environment.flushLog(true);
        environment.close();
        environment = createEnvironment(readOnly);
    }
    // System.err.println("Opened ObjectDatabase at " + env.getHome()
    // + ". Environment read-only: " + environment.getConfig().getReadOnly()
    // + " database read only: " + this.readOnly);
    Database database;
    try {
        LOGGER.debug("Opening ObjectDatabase at {}", environment.getHome());
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setCacheMode(CacheMode.MAKE_COLD);
        // can result in a slightly smaller db size
        dbConfig.setKeyPrefixing(false);
        dbConfig.setReadOnly(readOnly);
        boolean transactional = environment.getConfig().getTransactional();
        dbConfig.setTransactional(transactional);
        dbConfig.setDeferredWrite(!transactional);
        database = environment.openDatabase(null, databaseName, dbConfig);
    } catch (RuntimeException e) {
        if (environment != null) {
            environment.close();
        }
        throw e;
    }
    this.env = environment;
    return database;
}
Also used : EnvironmentLockedException(com.sleepycat.je.EnvironmentLockedException) AbstractObjectDatabase(org.locationtech.geogig.storage.AbstractObjectDatabase) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) Database(com.sleepycat.je.Database) Environment(com.sleepycat.je.Environment) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 3 with Environment

use of com.sleepycat.je.Environment in project vertigo by KleeGroup.

the class BerkeleyKVStorePlugin method buildFsEnvironment.

private static Environment buildFsEnvironment(final File dbFile, final boolean readOnly) {
    dbFile.mkdirs();
    final EnvironmentConfig fsEnvironmentConfig = new EnvironmentConfig().setConfigParam(EnvironmentConfig.LOG_MEM_ONLY, "false").setConfigParam(EnvironmentConfig.CLEANER_MIN_UTILIZATION, "90").setConfigParam(EnvironmentConfig.CLEANER_MIN_FILE_UTILIZATION, "50").setReadOnly(readOnly).setAllowCreate(!readOnly).setTransactional(!readOnly);
    return new Environment(dbFile, fsEnvironmentConfig);
}
Also used : EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment)

Example 4 with Environment

use of com.sleepycat.je.Environment in project jvarkit by lindenb.

the class Biostar92368 method doWork.

@Override
public int doWork(List<String> args) {
    if (this.dbHome == null) {
        LOG.error("Undefined DB-Home");
        return -1;
    }
    environment = null;
    EnvironmentConfig envCfg = new EnvironmentConfig();
    this.database = null;
    Transaction txn = null;
    PrintStream out = null;
    try {
        envCfg.setAllowCreate(true);
        this.environment = new Environment(dbHome, envCfg);
        DatabaseConfig cfg = new DatabaseConfig();
        cfg.setAllowCreate(true);
        cfg.setTemporary(true);
        this.database = environment.openDatabase(txn, "interactions", cfg);
        if (args.isEmpty()) {
            LOG.info("reading stdin");
            LineIterator r = IOUtils.openStdinForLineIterator();
            load(txn, r);
            CloserUtil.close(r);
        } else {
            for (String filename : args) {
                LOG.info("reading " + filename);
                LineIterator r = IOUtils.openURIForLineIterator(filename);
                load(txn, r);
                CloserUtil.close(r);
            }
        }
        out = super.openFileOrStdoutAsPrintStream(outputFile);
        DatabaseEntry key1 = new DatabaseEntry();
        DatabaseEntry data1 = new DatabaseEntry();
        DatabaseEntry key2 = new DatabaseEntry();
        DatabaseEntry data2 = new DatabaseEntry();
        Cursor c1 = this.database.openCursor(txn, null);
        Cursor c2 = this.database.openCursor(txn, null);
        while (c1.getNext(key1, data1, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
            String prot1 = StringBinding.entryToString(key1);
            boolean first = true;
            while ((first ? c2.getFirst(key2, data2, LockMode.DEFAULT) : c2.getNext(key2, data2, LockMode.DEFAULT)) == OperationStatus.SUCCESS) {
                first = false;
                String prot2 = StringBinding.entryToString(key2);
                if (prot2.compareTo(prot1) <= 0)
                    continue;
                Stack<String> path = new Stack<String>();
                path.push(prot1);
                int depth = recursive(txn, prot2, path, -1, maxDepth);
                if (depth != -1) {
                    out.println(prot1 + "\t" + prot2 + "\t" + depth);
                } else {
                // System.out.println(prot1+"\t"+prot2+"\t"+depth);
                }
                if (out.checkError())
                    break;
            }
        }
        CloserUtil.close(c2);
        CloserUtil.close(c1);
        out.flush();
        out.close();
        return 0;
    } catch (Exception err) {
        LOG.error(err);
        return -1;
    } finally {
        CloserUtil.close(this.database);
        CloserUtil.close(this.environment);
    }
}
Also used : PrintStream(java.io.PrintStream) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) LineIterator(htsjdk.tribble.readers.LineIterator) Stack(java.util.Stack) Transaction(com.sleepycat.je.Transaction) Environment(com.sleepycat.je.Environment) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 5 with Environment

use of com.sleepycat.je.Environment in project jvarkit by lindenb.

the class VcfAnnotWithBeacon method doWork.

@Override
public int doWork(final List<String> args) {
    try {
        if (this.bdbDir != null) {
            LOG.info("open BDB " + this.bdbDir);
            IOUtil.assertDirectoryIsWritable(this.bdbDir);
            final EnvironmentConfig envCfg = new EnvironmentConfig();
            envCfg.setAllowCreate(true);
            envCfg.setReadOnly(false);
            this.bdbEnv = new Environment(this.bdbDir, envCfg);
            final DatabaseConfig cfg = new DatabaseConfig();
            cfg.setAllowCreate(true);
            cfg.setReadOnly(false);
            this.beaconDatabase = this.bdbEnv.openDatabase(this.txn, "ga4ghBeaconBuffer", cfg);
        }
        return doVcfToVcf(args, outputFile);
    } catch (final Exception err) {
        LOG.error(err);
        return -1;
    } finally {
        CloserUtil.close(beaconDatabase);
        CloserUtil.close(bdbEnv);
    }
}
Also used : EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) RuntimeIOException(htsjdk.samtools.util.RuntimeIOException) CertificateException(java.security.cert.CertificateException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Aggregations

Environment (com.sleepycat.je.Environment)38 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)20 DatabaseConfig (com.sleepycat.je.DatabaseConfig)18 File (java.io.File)15 Database (com.sleepycat.je.Database)10 DatabaseException (com.sleepycat.je.DatabaseException)9 DatabaseEntry (com.sleepycat.je.DatabaseEntry)5 Transaction (com.sleepycat.je.Transaction)5 IOException (java.io.IOException)5 Cursor (com.sleepycat.je.Cursor)3 EnvironmentMutableConfig (com.sleepycat.je.EnvironmentMutableConfig)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 VoldemortException (voldemort.VoldemortException)3 CheckpointConfig (com.sleepycat.je.CheckpointConfig)2 StatsConfig (com.sleepycat.je.StatsConfig)2 ReplicatedEnvironment (com.sleepycat.je.rep.ReplicatedEnvironment)2 RuntimeIOException (htsjdk.samtools.util.RuntimeIOException)2 LineIterator (htsjdk.tribble.readers.LineIterator)2 BdbDbCreationException (nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.BdbDbCreationException)2