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);
}
}
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());
}
}
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");
}
}
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);
}
}
}
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);
}
}
}
Aggregations