Search in sources :

Example 6 with Environment

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

the class PubmedOrcidGraph method doWork.

@Override
public int doWork(final List<String> args) {
    if (!this.ncbiApiKey.isApiKeyDefined()) {
        LOG.error("NCBI API key is not defined");
        return -1;
    }
    InputStream in = null;
    XMLEventReader r = null;
    try {
        // open BDB
        final EnvironmentConfig envCfg = new EnvironmentConfig();
        envCfg.setAllowCreate(true);
        envCfg.setReadOnly(false);
        LOG.info("open BDB env...");
        this.environment = new Environment(this.bdbDir, envCfg);
        LOG.info("open BDB databases...");
        final DatabaseConfig config = new DatabaseConfig();
        config.setAllowCreate(true);
        config.setReadOnly(false);
        config.setTemporary(true);
        this.authorDatabase = this.environment.openDatabase(txn, "authors", config);
        this.articleDatabase = this.environment.openDatabase(txn, "articles", config);
        this.linkDatabase = this.environment.openDatabase(txn, "links", config);
        if (this.dumpStrangeOrcidFile != null) {
            this.errPrintWriter = super.openFileOrStdoutAsPrintStream(this.dumpStrangeOrcidFile);
        }
        if (this.input_is_orcid_id) {
            /* recursively scan authors */
            for (final String orcid : args) {
                scanOrcid(orcid, 0);
            }
            while (complete()) {
            // run...
            }
        } else {
            /* input is a efetch stream */
            String inputName = oneFileOrNull(args);
            in = (inputName == null ? stdin() : IOUtils.openURIForReading(inputName));
            scanArticles(in, 0);
            in.close();
            in = null;
        }
        dumpGexf();
        this.errPrintWriter.flush();
        if (this.dumpStrangeOrcidFile != null) {
            this.errPrintWriter.close();
        }
        return 0;
    } catch (Exception e) {
        LOG.error(e);
        return -1;
    } finally {
        CloserUtil.close(in);
        CloserUtil.close(r);
        CloserUtil.close(authorDatabase);
        CloserUtil.close(articleDatabase);
        CloserUtil.close(linkDatabase);
        CloserUtil.close(environment);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) XMLEventReader(javax.xml.stream.XMLEventReader) Environment(com.sleepycat.je.Environment) XMLStreamException(javax.xml.stream.XMLStreamException) JvarkitException(com.github.lindenb.jvarkit.lang.JvarkitException) RuntimeIOException(htsjdk.samtools.util.RuntimeIOException) IOException(java.io.IOException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 7 with Environment

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

the class CatBdbStore method main.

public static void main(String[] args) throws Exception {
    if (args.length != 2)
        Utils.croak("USAGE: java " + CatBdbStore.class.getName() + " bdb_dir" + " storeName" + " server.properties.path");
    String bdbDir = args[0];
    String storeName = args[1];
    String serverProperties = args[2];
    VoldemortConfig config = new VoldemortConfig(new Props(new File(serverProperties)));
    EnvironmentConfig environmentConfig = new EnvironmentConfig();
    environmentConfig.setDurability(Durability.COMMIT_NO_SYNC);
    environmentConfig.setAllowCreate(true);
    environmentConfig.setTransactional(config.isBdbWriteTransactionsEnabled());
    Environment environment = new Environment(new File(bdbDir), environmentConfig);
    DatabaseConfig databaseConfig = new DatabaseConfig();
    databaseConfig.setAllowCreate(true);
    databaseConfig.setTransactional(config.isBdbWriteTransactionsEnabled());
    databaseConfig.setSortedDuplicates(false);
    Database database = environment.openDatabase(null, storeName, databaseConfig);
    StorageEngine<ByteArray, byte[], byte[]> store = null;
    if (config.getBdbPrefixKeysWithPartitionId()) {
        store = new PartitionPrefixedBdbStorageEngine(storeName, environment, database, new BdbRuntimeConfig(), TestUtils.makeSingleNodeRoutingStrategy());
    } else {
        store = new BdbStorageEngine(storeName, environment, database, new BdbRuntimeConfig());
    }
    StorageEngine<String, String, String> stringStore = SerializingStorageEngine.wrap(store, new StringSerializer(), new StringSerializer(), new StringSerializer());
    Iterator<Pair<String, Versioned<String>>> iter = stringStore.entries();
    while (iter.hasNext()) {
        Pair<String, Versioned<String>> entry = iter.next();
        System.out.println(entry.getFirst() + " => " + entry.getSecond().getValue());
    }
}
Also used : BdbRuntimeConfig(voldemort.store.bdb.BdbRuntimeConfig) Versioned(voldemort.versioning.Versioned) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Props(voldemort.utils.Props) VoldemortConfig(voldemort.server.VoldemortConfig) PartitionPrefixedBdbStorageEngine(voldemort.store.bdb.PartitionPrefixedBdbStorageEngine) BdbStorageEngine(voldemort.store.bdb.BdbStorageEngine) PartitionPrefixedBdbStorageEngine(voldemort.store.bdb.PartitionPrefixedBdbStorageEngine) Database(com.sleepycat.je.Database) Environment(com.sleepycat.je.Environment) ByteArray(voldemort.utils.ByteArray) File(java.io.File) StringSerializer(voldemort.serialization.StringSerializer) DatabaseConfig(com.sleepycat.je.DatabaseConfig) Pair(voldemort.utils.Pair)

Example 8 with Environment

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

the class BdbStorageConfiguration method update.

/**
 * Detect what has changed in the store definition and rewire BDB
 * environments accordingly.
 *
 * @param storeDef updated store definition
 */
public void update(StoreDefinition storeDef) {
    if (!useOneEnvPerStore)
        throw new VoldemortException("Memory foot print can be set only when using different environments per store");
    String storeName = storeDef.getName();
    Environment environment = environments.get(storeName);
    // change reservation amount of reserved store
    if (!unreservedStores.contains(environment) && storeDef.hasMemoryFootprint()) {
        EnvironmentMutableConfig mConfig = environment.getMutableConfig();
        long currentCacheSize = mConfig.getCacheSize();
        long newCacheSize = storeDef.getMemoryFootprintMB() * ByteUtils.BYTES_PER_MB;
        if (currentCacheSize != newCacheSize) {
            long newReservedCacheSize = this.reservedCacheSize - currentCacheSize + newCacheSize;
            // check that we leave a 'minimum' shared cache
            if ((voldemortConfig.getBdbCacheSize() - newReservedCacheSize) < voldemortConfig.getBdbMinimumSharedCache()) {
                throw new StorageInitializationException("Reservation of " + storeDef.getMemoryFootprintMB() + " MB for store " + storeName + " violates minimum shared cache size of " + voldemortConfig.getBdbMinimumSharedCache());
            }
            this.reservedCacheSize = newReservedCacheSize;
            adjustCacheSizes();
            mConfig.setCacheSize(newCacheSize);
            environment.setMutableConfig(mConfig);
            logger.info("Setting private cache for store " + storeDef.getName() + " to " + newCacheSize);
        }
    } else {
        // versa since the sharedCache param is not mutable
        throw new VoldemortException("Cannot switch between shared and private cache dynamically");
    }
}
Also used : StorageInitializationException(voldemort.store.StorageInitializationException) EnvironmentMutableConfig(com.sleepycat.je.EnvironmentMutableConfig) Environment(com.sleepycat.je.Environment) VoldemortException(voldemort.VoldemortException)

Example 9 with Environment

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

the class BdbStorageConfiguration method getStore.

public StorageEngine<ByteArray, byte[], byte[]> getStore(StoreDefinition storeDef, RoutingStrategy strategy) {
    synchronized (lock) {
        try {
            String storeName = storeDef.getName();
            Environment environment = getEnvironment(storeDef);
            Database db = environment.openDatabase(null, storeName, databaseConfig);
            BdbRuntimeConfig runtimeConfig = new BdbRuntimeConfig(voldemortConfig);
            BdbStorageEngine engine = null;
            if (voldemortConfig.getBdbPrefixKeysWithPartitionId()) {
                engine = new PartitionPrefixedBdbStorageEngine(storeName, environment, db, runtimeConfig, strategy);
            } else {
                engine = new BdbStorageEngine(storeName, environment, db, runtimeConfig);
            }
            if (voldemortConfig.isJmxEnabled()) {
                // register the environment stats mbean
                JmxUtils.registerMbean(storeName, engine.getBdbEnvironmentStats());
                // aggregated stats
                if (useOneEnvPerStore) {
                    aggBdbStats.trackEnvironment(engine.getBdbEnvironmentStats());
                }
            }
            return engine;
        } catch (DatabaseException d) {
            throw new StorageInitializationException(d);
        }
    }
}
Also used : StorageInitializationException(voldemort.store.StorageInitializationException) Database(com.sleepycat.je.Database) Environment(com.sleepycat.je.Environment) DatabaseException(com.sleepycat.je.DatabaseException)

Example 10 with Environment

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

the class BdbStorageConfiguration method close.

public void close() {
    synchronized (lock) {
        try {
            for (Environment environment : environments.values()) {
                environment.sync();
                environment.close();
            }
        } catch (DatabaseException e) {
            throw new VoldemortException(e);
        }
    }
}
Also used : Environment(com.sleepycat.je.Environment) DatabaseException(com.sleepycat.je.DatabaseException) VoldemortException(voldemort.VoldemortException)

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