Search in sources :

Example 41 with Database

use of com.sleepycat.je.Database 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 42 with Database

use of com.sleepycat.je.Database in project BIMserver by opensourceBIM.

the class BerkeleyKeyValueStore method openIndexTable.

public void openIndexTable(DatabaseSession databaseSession, String tableName, boolean transactional) throws BimserverDatabaseException {
    if (tables.containsKey(tableName)) {
        throw new BimserverDatabaseException("Table " + tableName + " already opened");
    }
    DatabaseConfig databaseConfig = new DatabaseConfig();
    databaseConfig.setKeyPrefixing(keyPrefixing);
    databaseConfig.setAllowCreate(false);
    boolean finalTransactional = transactional && useTransactions;
    // if (!transactional) {
    // databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
    // }
    databaseConfig.setDeferredWrite(!finalTransactional);
    databaseConfig.setTransactional(finalTransactional);
    databaseConfig.setSortedDuplicates(true);
    Database database = environment.openDatabase(null, tableName, databaseConfig);
    if (database == null) {
        throw new BimserverDatabaseException("Table " + tableName + " not found in database");
    }
    tables.put(tableName, new TableWrapper(database, finalTransactional));
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) Database(com.sleepycat.je.Database) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 43 with Database

use of com.sleepycat.je.Database in project BIMserver by opensourceBIM.

the class BerkeleyKeyValueStore method createIndexTable.

public boolean createIndexTable(String tableName, DatabaseSession databaseSession, boolean transactional) throws BimserverDatabaseException {
    if (tables.containsKey(tableName)) {
        throw new BimserverDatabaseException("Table " + tableName + " already created");
    }
    DatabaseConfig databaseConfig = new DatabaseConfig();
    databaseConfig.setKeyPrefixing(keyPrefixing);
    databaseConfig.setAllowCreate(true);
    boolean finalTransactional = transactional && useTransactions;
    // if (!transactional) {
    // databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
    // }
    databaseConfig.setDeferredWrite(!finalTransactional);
    databaseConfig.setTransactional(finalTransactional);
    databaseConfig.setSortedDuplicates(true);
    Database database = environment.openDatabase(null, tableName, databaseConfig);
    if (database == null) {
        return false;
    }
    tables.put(tableName, new TableWrapper(database, finalTransactional));
    return true;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) Database(com.sleepycat.je.Database) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 44 with Database

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

the class BdbGrowth method main.

public static void main(String[] args) throws Exception {
    if (args.length != 5) {
        System.err.println("USAGE: java BdbGrowth directory cache_size total_size increment threads");
        System.exit(1);
    }
    final String dir = args[0];
    final long cacheSize = Long.parseLong(args[1]);
    final int totalSize = Integer.parseInt(args[2]);
    final int increment = Integer.parseInt(args[3]);
    final int threads = Integer.parseInt(args[4]);
    Environment environment;
    EnvironmentConfig environmentConfig;
    DatabaseConfig databaseConfig;
    environmentConfig = new EnvironmentConfig();
    environmentConfig.setCacheSize(cacheSize);
    environmentConfig.setDurability(Durability.COMMIT_NO_SYNC);
    environmentConfig.setConfigParam(EnvironmentConfig.LOG_FILE_MAX, "1000000000");
    environmentConfig.setConfigParam(EnvironmentConfig.CLEANER_MAX_BATCH_FILES, "100");
    environmentConfig.setConfigParam(EnvironmentConfig.CLEANER_READ_SIZE, "52428800");
    environmentConfig.setAllowCreate(true);
    environmentConfig.setTransactional(true);
    databaseConfig = new DatabaseConfig();
    databaseConfig.setAllowCreate(true);
    // databaseConfig.setDeferredWrite(true);
    databaseConfig.setTransactional(true);
    databaseConfig.setNodeMaxEntries(1024);
    File bdbDir = new File(dir);
    if (!bdbDir.exists()) {
        bdbDir.mkdir();
    } else {
        for (File f : bdbDir.listFiles()) f.delete();
    }
    environment = new Environment(bdbDir, environmentConfig);
    final Database db = environment.openDatabase(null, "test", databaseConfig);
    final Random rand = new Random();
    int iterations = totalSize / increment;
    long[] readTimes = new long[iterations];
    long[] writeTimes = new long[iterations];
    ExecutorService service = Executors.newFixedThreadPool(threads);
    for (int i = 0; i < iterations; i++) {
        System.out.println("Starting iteration " + i);
        List<Future<Object>> results = new ArrayList<Future<Object>>(increment);
        long startTime = System.currentTimeMillis();
        final int fi = i;
        for (int j = 0; j < increment; j++) {
            final int fj = j;
            results.add(service.submit(new Callable<Object>() {

                public Object call() throws Exception {
                    db.put(null, new DatabaseEntry(Integer.toString(fi * increment + fj).getBytes()), new DatabaseEntry(Integer.toString(fi * increment + fj).getBytes()));
                    return null;
                }
            }));
        }
        for (int j = 0; j < increment; j++) results.get(j).get();
        writeTimes[i] = System.currentTimeMillis() - startTime;
        System.out.println("write: " + (writeTimes[i] / (double) increment));
        results.clear();
        startTime = System.currentTimeMillis();
        for (int j = 0; j < increment; j++) {
            results.add(service.submit(new Callable<Object>() {

                public Object call() throws Exception {
                    int value = rand.nextInt((fi + 1) * increment);
                    return db.get(null, new DatabaseEntry(Integer.toString(value).getBytes()), new DatabaseEntry(Integer.toString(value).getBytes()), null);
                }
            }));
        }
        for (int j = 0; j < increment; j++) results.get(j).get();
        readTimes[i] = (System.currentTimeMillis() - startTime);
        System.out.println("read: " + (readTimes[i] / (double) increment));
        int cleaned = 0;
        do {
            cleaned += environment.cleanLog();
        } while (cleaned > 0);
        if (cleaned > 0)
            System.out.println("Cleaned " + cleaned + " files.");
        CheckpointConfig cp = new CheckpointConfig();
        cp.setForce(true);
        environment.checkpoint(null);
        environment.compress();
        environment.sync();
        System.out.println("Cleaning, Checkpointing and compression completed.");
    }
    System.out.println();
    System.out.println("iteration read write:");
    for (int i = 0; i < iterations; i++) {
        System.out.print(i);
        System.out.print(" " + readTimes[i] / (double) increment);
        System.out.println(" " + writeTimes[i] / (double) increment);
    }
    System.out.println(environment.getStats(null));
    System.exit(0);
}
Also used : CheckpointConfig(com.sleepycat.je.CheckpointConfig) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) ArrayList(java.util.ArrayList) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Callable(java.util.concurrent.Callable) Random(java.util.Random) Database(com.sleepycat.je.Database) ExecutorService(java.util.concurrent.ExecutorService) Environment(com.sleepycat.je.Environment) Future(java.util.concurrent.Future) File(java.io.File) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 45 with Database

use of com.sleepycat.je.Database in project janusgraph by JanusGraph.

the class BerkeleyJEStoreManager method openDatabase.

@Override
public BerkeleyJEKeyValueStore openDatabase(String name) throws BackendException {
    Preconditions.checkNotNull(name);
    if (stores.containsKey(name)) {
        return stores.get(name);
    }
    try {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setReadOnly(false);
        dbConfig.setAllowCreate(true);
        dbConfig.setTransactional(transactional);
        dbConfig.setKeyPrefixing(true);
        if (batchLoading) {
            dbConfig.setDeferredWrite(true);
        }
        Database db = environment.openDatabase(null, name, dbConfig);
        log.debug("Opened database {}", name);
        BerkeleyJEKeyValueStore store = new BerkeleyJEKeyValueStore(name, db, this);
        stores.put(name, store);
        return store;
    } catch (DatabaseException e) {
        throw new PermanentBackendException("Could not open BerkeleyJE data store", e);
    }
}
Also used : PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Database(com.sleepycat.je.Database) DatabaseException(com.sleepycat.je.DatabaseException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Aggregations

Database (com.sleepycat.je.Database)73 DatabaseEntry (com.sleepycat.je.DatabaseEntry)46 Transaction (com.sleepycat.je.Transaction)35 DatabaseConfig (com.sleepycat.je.DatabaseConfig)27 UUID (java.util.UUID)12 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)11 Environment (com.sleepycat.je.Environment)10 OperationStatus (com.sleepycat.je.OperationStatus)8 Cursor (com.sleepycat.je.Cursor)7 HashSet (java.util.HashSet)7 StoreException (org.apache.qpid.server.store.StoreException)7 HashMap (java.util.HashMap)6 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)5 File (java.io.File)5 ArrayList (java.util.ArrayList)5 FieldTable (org.apache.qpid.server.protocol.v0_8.FieldTable)5 NewPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction)5 OldPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction)5 Test (org.junit.Test)5 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)4