Java Code Examples for com.sleepycat.je.EnvironmentConfig#setTransactional()
The following examples show how to use
com.sleepycat.je.EnvironmentConfig#setTransactional() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestKDTreeSplit.java From bboxdb with Apache License 2.0 | 6 votes |
public TestKDTreeSplit(final File tmpDir, final List<Pair<String, String>> filesAndFormats, final List<Integer> experimentSize) { this.filesAndFormats = filesAndFormats; this.experimentSize = experimentSize; this.elements = new HashMap<>(); this.elementCounter = new HashMap<>(); this.boxDimension = new HashMap<>(); // Setup database dir tmpDir.mkdirs(); FileUtil.deleteDirOnExit(tmpDir.toPath()); final EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(false); envConfig.setAllowCreate(true); envConfig.setSharedCache(true); dbEnv = new Environment(tmpDir, envConfig); dbConfig = new DatabaseConfig(); dbConfig.setTransactional(false); dbConfig.setAllowCreate(true); }
Example 2
Source File: FileLineIndex.java From bboxdb with Apache License 2.0 | 6 votes |
/** * Open the Berkeley DB * @throws IOException */ protected void openDatabase() throws IOException { final EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(false); envConfig.setAllowCreate(true); envConfig.setSharedCache(true); tmpDatabaseDir = Files.createTempDirectory(null); dbEnv = new Environment(tmpDatabaseDir.toFile(), envConfig); logger.info("Database dir is {}", tmpDatabaseDir); // Delete database on exit FileUtil.deleteDirOnExit(tmpDatabaseDir); final DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setTransactional(false); dbConfig.setAllowCreate(true); dbConfig.setDeferredWrite(true); database = dbEnv.openDatabase(null, "lines", dbConfig); }
Example 3
Source File: WebGraph.java From codes-scratch-crawler with Apache License 2.0 | 6 votes |
/** * 构造函数 */ public WebGraph(String dbDir) throws DatabaseException { File envDir = new File(dbDir); EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(false); envConfig.setAllowCreate(true); Environment env = new Environment(envDir, envConfig); StoreConfig storeConfig = new StoreConfig(); storeConfig.setAllowCreate(true); storeConfig.setTransactional(false); store = new EntityStore(env, "classDb", storeConfig); outLinkIndex = store.getPrimaryIndex(String.class, Link.class); inLinkIndex = store.getSecondaryIndex(outLinkIndex, String.class, "toURL"); }
Example 4
Source File: AbstractFrontier.java From codes-scratch-crawler with Apache License 2.0 | 6 votes |
public AbstractFrontier(String homeDirectory) { EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(true); envConfig.setAllowCreate(true); env = new Environment(new File(homeDirectory), envConfig); // 设置databaseconfig DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setTransactional(true); dbConfig.setAllowCreate(true); // 打开 catalogdatabase = env.openDatabase(null, CLASS_CATALOG, dbConfig); javaCatalog = new StoredClassCatalog(catalogdatabase); // 设置databaseconfig DatabaseConfig dbConfig0 = new DatabaseConfig(); dbConfig0.setTransactional(true); dbConfig0.setAllowCreate(true); database = env.openDatabase(null, "URL", dbConfig0); }
Example 5
Source File: JE_Repository.java From tddl with Apache License 2.0 | 6 votes |
@Override public void init() { EnvironmentConfig envConfig = new EnvironmentConfig(); commonConfig(envConfig); envConfig.setCachePercent(config.getCachePercent()); envConfig.setAllowCreate(true); if (config.isTransactional()) { envConfig.setCachePercent(config.getCachePercent()); envConfig.setTransactional(config.isTransactional()); envConfig.setTxnTimeout(config.getTxnTimeout(), TimeUnit.SECONDS); this.durability = config.isCommitSync() ? Durability.COMMIT_SYNC : Durability.COMMIT_NO_SYNC; envConfig.setDurability(this.durability); } File repo_dir = new File(config.getRepoDir()); if (!repo_dir.exists()) { repo_dir.mkdirs(); } this.env = new Environment(repo_dir, envConfig); cef = new CommandHandlerFactoryBDBImpl(); cursorFactoryBDBImp = new CursorFactoryBDBImp(); }
Example 6
Source File: AbstractUpgradeTestCase.java From qpid-broker-j with Apache License 2.0 | 5 votes |
protected Environment createEnvironment(File storeLocation) { EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setAllowCreate(true); envConfig.setTransactional(true); envConfig.setConfigParam("je.lock.nLockTables", "7"); envConfig.setReadOnly(false); envConfig.setSharedCache(false); envConfig.setCacheSize(0); return new Environment(storeLocation, envConfig); }
Example 7
Source File: BDBPreferenceStoreTest.java From qpid-broker-j with Apache License 2.0 | 5 votes |
private void populateTestData(final List<PreferenceRecord> records, final String modelVersion) { EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setAllowCreate(true); envConfig.setTransactional(false); try (Environment environment = new Environment(_storeFile, envConfig)) { DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); try (Database versionDb = environment.openDatabase(null, "USER_PREFERENCES_VERSION", dbConfig); Database preferencesDb = environment.openDatabase(null, "USER_PREFERENCES", dbConfig)) { DatabaseEntry key = new DatabaseEntry(); DatabaseEntry value = new DatabaseEntry(); UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance(); MapBinding valueBinding = MapBinding.getInstance(); for (PreferenceRecord record : records) { keyBinding.objectToEntry(record.getId(), key); valueBinding.objectToEntry(record.getAttributes(), value); preferencesDb.put(null, key, value); } ByteBinding.byteToEntry((byte) 0, value); StringBinding.stringToEntry(modelVersion, key); versionDb.put(null, key, value); } } }
Example 8
Source File: BDBTupleStore.java From bboxdb with Apache License 2.0 | 5 votes |
@Override public void open() throws Exception { final EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(USE_TRANSACTIONS); envConfig.setAllowCreate(true); environment = new Environment(dir, envConfig); Transaction txn = null; if(USE_TRANSACTIONS) { txn = environment.beginTransaction(null, null); } final DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setTransactional(USE_TRANSACTIONS); dbConfig.setAllowCreate(true); //dbConfig.setSortedDuplicates(true); dbConfig.setDeferredWrite(true); //dbConfig.setKeyPrefixing(true); //dbConfig.setNodeMaxEntries(128); database = environment.openDatabase(txn, "test", dbConfig); if(txn != null) { txn.commit(); } }
Example 9
Source File: BdbPersistentEnvironmentCreator.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
@JsonCreator public BdbPersistentEnvironmentCreator(@JsonProperty("databaseLocation") String databaseLocation) { this.databaseLocation = databaseLocation; configuration = new EnvironmentConfig(new Properties()); configuration.setTransactional(true); configuration.setDurability(Durability.COMMIT_NO_SYNC); configuration.setAllowCreate(true); configuration.setSharedCache(true); bdbBackupper = new BdbBackupper(); }
Example 10
Source File: BdbNonPersistentEnvironmentCreator.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
public BdbNonPersistentEnvironmentCreator() { configuration = new EnvironmentConfig(new Properties()); configuration.setTransactional(true); configuration.setAllowCreate(true); configuration.setSharedCache(true); dbHome = Files.createTempDir(); databases = Maps.newHashMap(); environmentMap = Maps.newHashMap(); }
Example 11
Source File: MultiNodeTest.java From qpid-broker-j with Apache License 2.0 | 4 votes |
@Test public void testClusterCannotStartWithIntruder() throws Exception { int intruderPort = new PortHelper().getNextAvailable(Arrays.stream(getBrokerAdmin().getBdbPorts()).max().getAsInt() + 1); String nodeName = "intruder"; String nodeHostPort = getBrokerAdmin().getHost() + ":" + intruderPort; File environmentPathFile = Files.createTempDirectory("qpid-work-intruder").toFile(); try { environmentPathFile.mkdirs(); ReplicationConfig replicationConfig = new ReplicationConfig("test", nodeName, nodeHostPort); replicationConfig.setHelperHosts(getBrokerAdmin().getHelperHostPort()); EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setAllowCreate(true); envConfig.setTransactional(true); envConfig.setDurability(new Durability(Durability.SyncPolicy.SYNC, Durability.SyncPolicy.WRITE_NO_SYNC, Durability.ReplicaAckPolicy.SIMPLE_MAJORITY)); final String currentThreadName = Thread.currentThread().getName(); try (ReplicatedEnvironment intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig)) { LOGGER.debug("Intruder started"); } finally { Thread.currentThread().setName(currentThreadName); } Set<Integer> ports = Arrays.stream(getBrokerAdmin().getGroupAmqpPorts()).boxed().collect(Collectors.toSet()); for (int port : ports) { getBrokerAdmin().awaitNodeToAttainAttributeValue(port, BDBHAVirtualHostNode.STATE, State.ERRORED.name()); } getBrokerAdmin().stop(); try { getBrokerAdmin().start(); fail("Cluster cannot start with an intruder node"); } catch (Exception e) { // pass } } finally { FileUtils.delete(environmentPathFile, true); } }
Example 12
Source File: StandardEnvironmentFacade.java From qpid-broker-j with Apache License 2.0 | 4 votes |
public StandardEnvironmentFacade(StandardEnvironmentConfiguration configuration) { _storePath = configuration.getStorePath(); if (LOGGER.isInfoEnabled()) { LOGGER.info("Creating environment at environment path " + _storePath); } _environmentPath = new File(_storePath); if (!_environmentPath.exists()) { if (!_environmentPath.mkdirs()) { throw new IllegalArgumentException("Environment path " + _environmentPath + " could not be read or created. " + "Ensure the path is correct and that the permissions are correct."); } } else if(_environmentPath.isFile()) { throw new IllegalArgumentException("Environment path " + _environmentPath + " exists as a file - not a directory. " + "Ensure the path is correct."); } String name = configuration.getName(); EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setAllowCreate(true); envConfig.setTransactional(true); envConfig.setCacheMode(configuration.getCacheMode()); envConfig.setLoggingHandler(new Slf4jLoggingHandler(configuration)); LOGGER.debug("Cache mode {}", envConfig.getCacheMode()); Map<String, String> params = new HashMap<>(EnvironmentFacade.ENVCONFIG_DEFAULTS); params.putAll(configuration.getParameters()); for (Map.Entry<String, String> configItem : params.entrySet()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Setting EnvironmentConfig key " + configItem.getKey() + " to '" + configItem.getValue() + "'"); } envConfig.setConfigParam(configItem.getKey(), configItem.getValue()); } envConfig.setExceptionListener(new LoggingAsyncExceptionListener()); DbInternal.setLoadPropertyFile(envConfig, false); File propsFile = new File(_environmentPath, "je.properties"); if(propsFile.exists()) { LOGGER.warn("The BDB configuration file at '" + _environmentPath + File.separator + "je.properties' will NOT be loaded. Configure BDB using Qpid context variables instead."); } EnvHomeRegistry.getInstance().registerHome(_environmentPath); boolean success = false; try { _environment = new AtomicReference<>(new Environment(_environmentPath, envConfig)); success = true; } finally { if (!success) { EnvHomeRegistry.getInstance().deregisterHome(_environmentPath); } } _committer = new CoalescingCommiter(name, this); _committer.start(); }
Example 13
Source File: OrphanConfigurationRecordPurger.java From qpid-broker-j with Apache License 2.0 | 4 votes |
private void purge() throws Exception { EnvironmentConfig config = EnvironmentConfig.DEFAULT; config.setAllowCreate(false); config.setTransactional(true); try (Environment env = createEnvironment(config)) { final int version = getVersion(env, READ_ONLY_DB_CONFIG); if (!ALLOWED_VERSIONS.contains(version)) { throw new IllegalStateException(String.format("Store has unexpected version. Found %d expected %s", version, ALLOWED_VERSIONS)); } final Transaction tx = env.beginTransaction(null, TransactionConfig.DEFAULT); boolean success = false; try { purgeOrphans(env, tx); success = true; } finally { if (!success) { System.out.println("No config or config hierarchy records purged."); tx.abort(); } else if (_dryRun) { System.out.println("No config or config hierarchy records purged - -dryRun flag specified."); tx.abort(); } else { tx.commit(); System.out.format("Config records(s) and associated hierarchy records purged."); } } } }
Example 14
Source File: OSMBDBNodeStore.java From bboxdb with Apache License 2.0 | 4 votes |
public OSMBDBNodeStore(final List<String> baseDir, final long inputLength) { if(baseDir.size() == 1) { this.instances = 4; } else { this.instances = baseDir.size(); } // Prepare DB_Instances for (int i = 0; i < this.instances; i++) { final String workfolder = baseDir.get(i % baseDir.size()); final String folderName = workfolder + "/osm_" + i; final File folder = new File(folderName); if(folder.exists()) { System.err.println("Folder already exists, exiting: " + folderName); System.exit(-1); } folder.mkdirs(); pendingWriteQueues.add(new LinkedList<SerializableNode>()); final EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(USE_TRANSACTIONS); envConfig.setAllowCreate(true); envConfig.setSharedCache(true); // envConfig.setCachePercent(80); /* envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_CLEANER, "false"); envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_CHECKPOINTER, "false"); envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_IN_COMPRESSOR, "false"); */ initNewBDBEnvironment(folder, envConfig); final BDBWriterRunnable bdbWriter = new BDBWriterRunnable(pendingWriteQueues.get(i), environments.get(i), databases.get(i)); threadPool.submit(bdbWriter); } }
Example 15
Source File: BerkeleyDBWiktionaryEdition.java From dkpro-jwktl with Apache License 2.0 | 4 votes |
protected void connect(boolean isReadOnly, boolean allowCreateNew, boolean overwriteExisting, final Long cacheSize) throws DatabaseException { // Configure DB environment. EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setAllowCreate(allowCreateNew); envConfig.setReadOnly(isReadOnly); envConfig.setTransactional(false); if (cacheSize != null) envConfig.setCacheSize(cacheSize); env = new Environment(dbPath, envConfig); // Configure store. StoreConfig storeConfig = new StoreConfig(); storeConfig.setAllowCreate(allowCreateNew); storeConfig.setTransactional(false); storeConfig.setReadOnly(isReadOnly); store = new EntityStore(env, DATABASE_NAME, storeConfig); // Load properties. properties = new Properties(); File propFile = new File(dbPath, PROPERTY_FILE_NAME); if (propFile.exists()) { try { try (Reader reader = new InputStreamReader(new FileInputStream(propFile), "UTF-8")) { properties.load(reader); } } catch (IOException e) { throw new DatabaseException("Unable to load property file", e){}; } String lang = properties.getProperty("wiktionary.language"); if (lang == null) lang = properties.getProperty("entry_language"); language = Language.get(lang); } // Load index. pageById = store.getPrimaryIndex(Long.class, WiktionaryPage.class); pageByTitle = store.getSecondaryIndex(pageById, String.class, "title"); pageByNormalizedTitle = store.getSecondaryIndex(pageById, String.class, "normalizedTitle"); entryByKey = store.getPrimaryIndex(String.class, WiktionaryEntryProxy.class); entryById = store.getSecondaryIndex(entryByKey, Long.class, "entryId"); senseByKey = store.getPrimaryIndex(String.class, WiktionarySenseProxy.class); openCursors = new HashSet<>(); }