Search in sources :

Example 16 with Environment

use of com.sleepycat.je.Environment in project sessdb by ppdai.

the class BdbBenchmark method open.

@Override
public void open() {
    try {
        EnvironmentConfig envConfig = new EnvironmentConfig();
        envConfig.setAllowCreate(true);
        envConfig.setCachePercent(90);
        File file = new File(databaseDir_);
        if (!file.exists()) {
            file.mkdirs();
        }
        env_ = new Environment(file, envConfig);
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        bdb_ = env_.openDatabase(null, BdbBenchmark.DATABASE_NAME, dbConfig);
    } catch (DatabaseException e) {
        e.printStackTrace();
    }
}
Also used : EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) File(java.io.File) DatabaseException(com.sleepycat.je.DatabaseException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 17 with Environment

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

the class EnvironmentBuilder method get.

/**
     * @return
     * @see com.google.inject.Provider#get()
     */
@Override
public synchronized Environment get() {
    final Optional<URL> repoUrl = new ResolveGeogigDir(platform).call();
    if (!repoUrl.isPresent() && absolutePath == null) {
        throw new IllegalStateException("Can't find geogig repository home");
    }
    final File storeDirectory;
    if (absolutePath != null) {
        storeDirectory = absolutePath;
    } else {
        File currDir;
        try {
            currDir = new File(repoUrl.get().toURI());
        } catch (URISyntaxException e) {
            throw Throwables.propagate(e);
        }
        File dir = currDir;
        for (String subdir : path) {
            dir = new File(dir, subdir);
        }
        storeDirectory = dir;
    }
    if (!storeDirectory.exists() && !storeDirectory.mkdirs()) {
        throw new IllegalStateException("Unable to create Environment directory: '" + storeDirectory.getAbsolutePath() + "'");
    }
    EnvironmentConfig envCfg;
    if (this.forceConfig == null) {
        File conf = new File(storeDirectory, "je.properties");
        if (!conf.exists()) {
            String resource = stagingDatabase ? "je.properties.staging" : "je.properties.objectdb";
            ByteSource from = Resources.asByteSource((getClass().getResource(resource)));
            try {
                from.copyTo(Files.asByteSink(conf));
            } catch (IOException e) {
                Throwables.propagate(e);
            }
        }
        // use the default settings
        envCfg = new EnvironmentConfig();
        envCfg.setAllowCreate(true);
        envCfg.setCacheMode(CacheMode.MAKE_COLD);
        envCfg.setLockTimeout(5, TimeUnit.SECONDS);
        envCfg.setDurability(Durability.COMMIT_SYNC);
    // envCfg.setReadOnly(readOnly);
    } else {
        envCfg = this.forceConfig;
    }
    // // envCfg.setSharedCache(true);
    // //
    // final boolean transactional = false;
    // envCfg.setTransactional(transactional);
    // envCfg.setCachePercent(75);// Use up to 50% of the heap size for the shared db cache
    // envCfg.setConfigParam(EnvironmentConfig.LOG_FILE_MAX, String.valueOf(256 * 1024 * 1024));
    // // check <http://www.oracle.com/technetwork/database/berkeleydb/je-faq-096044.html#35>
    // envCfg.setConfigParam("je.evictor.lruOnly", "false");
    // envCfg.setConfigParam("je.evictor.nodesPerScan", "100");
    //
    // envCfg.setConfigParam(EnvironmentConfig.CLEANER_MIN_UTILIZATION, "25");
    // envCfg.setConfigParam(EnvironmentConfig.CHECKPOINTER_HIGH_PRIORITY, "true");
    //
    // envCfg.setConfigParam(EnvironmentConfig.CLEANER_THREADS, "4");
    // // TODO: check whether we can set is locking to false
    // envCfg.setConfigParam(EnvironmentConfig.ENV_IS_LOCKING, String.valueOf(transactional));
    //
    // envCfg.setConfigParam(EnvironmentConfig.ENV_RUN_CHECKPOINTER,
    // String.valueOf(!transactional));
    // envCfg.setConfigParam(EnvironmentConfig.ENV_RUN_CLEANER, String.valueOf(!transactional));
    //
    // // envCfg.setConfigParam(EnvironmentConfig.ENV_RUN_EVICTOR, "false");
    Environment env;
    try {
        env = new Environment(storeDirectory, envCfg);
    } catch (RuntimeException lockedEx) {
        // lockedEx.printStackTrace();
        if (readOnly) {
            // this happens when trying to open the env in read only mode when its already open
            // in read/write mode inside the same process. So we re-open it read-write but the
            // database itself will be open read-only by JEObjectDatabase.
            envCfg.setReadOnly(true);
            env = new Environment(storeDirectory, envCfg);
        } else {
            throw lockedEx;
        }
    }
    return env;
}
Also used : EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) ByteSource(com.google.common.io.ByteSource) Environment(com.sleepycat.je.Environment) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File) URL(java.net.URL)

Example 18 with Environment

use of com.sleepycat.je.Environment in project sirix by sirixdb.

the class BerkeleyStorageFactory method createStorage.

/**
 * Create a new storage.
 *
 * @param resourceConfig the resource configuration
 * @return the berkeley DB storage
 * @throws NullPointerException if {@link ResourceConfiguration} is {@code null}
 * @throws SirixIOException if the storage couldn't be created because of an I/O exception
 */
public BerkeleyStorage createStorage(final ResourceConfiguration resourceConfig) {
    try {
        final Path repoFile = resourceConfig.mPath.resolve(ResourceConfiguration.ResourcePaths.DATA.getFile());
        if (!Files.exists(repoFile)) {
            Files.createDirectories(repoFile);
        }
        final ByteHandlePipeline byteHandler = checkNotNull(resourceConfig.mByteHandler);
        final DatabaseConfig conf = generateDBConf();
        final EnvironmentConfig config = generateEnvConf();
        final List<Path> path;
        try (final Stream<Path> stream = Files.list(repoFile)) {
            path = stream.collect(toList());
        }
        if (path.isEmpty() || (path.size() == 1 && "sirix.data".equals(path.get(0).getFileName().toString()))) {
            conf.setAllowCreate(true);
            config.setAllowCreate(true);
        }
        final Environment env = new Environment(repoFile.toFile(), config);
        final Database database = env.openDatabase(null, NAME, conf);
        return new BerkeleyStorage(env, database, byteHandler);
    } catch (final DatabaseException | IOException e) {
        throw new SirixIOException(e);
    }
}
Also used : Path(java.nio.file.Path) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) IOException(java.io.IOException) SirixIOException(org.sirix.exception.SirixIOException) SirixIOException(org.sirix.exception.SirixIOException) Database(com.sleepycat.je.Database) Environment(com.sleepycat.je.Environment) ByteHandlePipeline(org.sirix.io.bytepipe.ByteHandlePipeline) DatabaseException(com.sleepycat.je.DatabaseException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 19 with Environment

use of com.sleepycat.je.Environment in project leopard by tanhaichao.

the class BdbImpl method init.

public void init() throws EnvironmentLockedException, DatabaseException {
    EnvironmentConfig environmentConfig = new EnvironmentConfig();
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setAllowCreate(true);
    dbConfig.setSortedDuplicates(true);
    environmentConfig.setReadOnly(false);
    environmentConfig.setAllowCreate(true);
    // Open the environment and entity store
    if (!dataDir.exists()) {
        dataDir.mkdirs();
    }
    environment = new Environment(dataDir, environmentConfig);
    // Database database = environment.openDatabase(transaction, "BDB", dbConfig);
    this.bdb = new BdbDatabaseImpl(environment, "DEFAULT");
}
Also used : EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 20 with Environment

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

the class BdbStorageConfiguration method adjustCacheSizes.

/**
 * When a reservation is made, we need to shrink the shared cache
 * accordingly to guarantee memory foot print of the new store. NOTE: This
 * is not an instantaneous operation. Changes will take effect only when
 * traffic is thrown and eviction happens.( Won't happen until Network ports
 * are opened anyway which is rightfully done after storage service).When
 * changing this dynamically, we might want to block until the shared cache
 * shrinks enough
 */
private void adjustCacheSizes() {
    long newSharedCacheSize = voldemortConfig.getBdbCacheSize() - this.reservedCacheSize;
    logger.info("Setting the shared cache size to " + newSharedCacheSize);
    for (Environment environment : unreservedStores) {
        EnvironmentMutableConfig mConfig = environment.getMutableConfig();
        mConfig.setCacheSize(newSharedCacheSize);
        environment.setMutableConfig(mConfig);
    }
}
Also used : EnvironmentMutableConfig(com.sleepycat.je.EnvironmentMutableConfig) Environment(com.sleepycat.je.Environment)

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