Search in sources :

Example 11 with Options

use of org.iq80.leveldb.Options in project cdap by caskdata.

the class LevelDBTableService method createTable.

private void createTable(String name) throws IOException {
    String dbPath = getDBPath(basePath, name);
    Options options = new Options();
    options.createIfMissing(true);
    options.errorIfExists(false);
    options.comparator(new KeyValueDBComparator());
    options.blockSize(blockSize);
    options.cacheSize(cacheSize);
    DB db = factory.open(new File(dbPath), options);
    tables.put(name, db);
}
Also used : WriteOptions(org.iq80.leveldb.WriteOptions) Options(org.iq80.leveldb.Options) File(java.io.File) DB(org.iq80.leveldb.DB)

Example 12 with Options

use of org.iq80.leveldb.Options in project Nukkit by Nukkit.

the class LevelDB method generate.

public static void generate(String path, String name, long seed, Class<? extends Generator> generator, Map<String, String> options) throws IOException {
    if (!new File(path + "/db").exists()) {
        new File(path + "/db").mkdirs();
    }
    CompoundTag levelData = new CompoundTag("").putLong("currentTick", 0).putInt("DayCycleStopTime", -1).putInt("GameType", 0).putInt("Generator", Generator.getGeneratorType(generator)).putBoolean("hasBeenLoadedInCreative", false).putLong("LastPlayed", System.currentTimeMillis() / 1000).putString("LevelName", name).putFloat("lightningLevel", 0).putInt("lightningTime", new Random().nextInt()).putInt("limitedWorldOriginX", 128).putInt("limitedWorldOriginY", 70).putInt("limitedWorldOriginZ", 128).putInt("Platform", 0).putFloat("rainLevel", 0).putInt("rainTime", new Random().nextInt()).putLong("RandomSeed", seed).putByte("spawnMobs", 0).putInt("SpawnX", 128).putInt("SpawnY", 70).putInt("SpawnZ", 128).putInt("storageVersion", 4).putLong("Time", 0).putLong("worldStartCount", ((long) Integer.MAX_VALUE) & 0xffffffffL);
    byte[] data = NBTIO.write(levelData, ByteOrder.LITTLE_ENDIAN);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    outputStream.write(Binary.writeLInt(3));
    outputStream.write(Binary.writeLInt(data.length));
    outputStream.write(data);
    Utils.writeFile(path + "level.dat", new ByteArrayInputStream(outputStream.toByteArray()));
    DB db = Iq80DBFactory.factory.open(new File(path + "/db"), new Options().createIfMissing(true));
    db.close();
}
Also used : Options(org.iq80.leveldb.Options) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) DB(org.iq80.leveldb.DB)

Example 13 with Options

use of org.iq80.leveldb.Options in project tez by apache.

the class ShuffleHandler method startStore.

private void startStore(Path recoveryRoot) throws IOException {
    Options options = new Options();
    options.createIfMissing(false);
    options.logger(new LevelDBLogger());
    Path dbPath = new Path(recoveryRoot, STATE_DB_NAME);
    LOG.info("Using state database at " + dbPath + " for recovery");
    File dbfile = new File(dbPath.toString());
    try {
        stateDb = JniDBFactory.factory.open(dbfile, options);
    } catch (NativeDB.DBException e) {
        if (e.isNotFound() || e.getMessage().contains(" does not exist ")) {
            LOG.info("Creating state database at " + dbfile);
            options.createIfMissing(true);
            try {
                stateDb = JniDBFactory.factory.open(dbfile, options);
                storeVersion();
            } catch (DBException dbExc) {
                throw new IOException("Unable to create state store", dbExc);
            }
        } else {
            throw e;
        }
    }
    checkVersion();
}
Also used : Path(org.apache.hadoop.fs.Path) Options(org.iq80.leveldb.Options) DBException(org.iq80.leveldb.DBException) IOException(java.io.IOException) NativeDB(org.fusesource.leveldbjni.internal.NativeDB) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 14 with Options

use of org.iq80.leveldb.Options in project EventHub by Codecademy.

the class DatedEventIndexModule method getDatedEventIndex.

@Provides
public DatedEventIndex getDatedEventIndex(@Named("eventhub.directory") String eventIndexDirectory) throws IOException {
    Options options = new Options();
    options.createIfMissing(true);
    DB db = new DB(JniDBFactory.factory.open(new File(eventIndexDirectory + "/dated_event_index.db"), options));
    return DatedEventIndex.create(db);
}
Also used : Options(org.iq80.leveldb.Options) File(java.io.File) DB(com.codecademy.eventhub.base.DB) Provides(com.google.inject.Provides)

Example 15 with Options

use of org.iq80.leveldb.Options in project EventHub by Codecademy.

the class MigrateIdMapToUseLevelDB method main.

public static void main(String[] args) throws Exception {
    String userStorageDirectory = args[0];
    String filename = userStorageDirectory + "/id_map.ser";
    File file = new File(filename);
    try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
        // noinspection unchecked
        Map<String, Integer> idMap = (Map<String, Integer>) ois.readObject();
        int currentId = ois.readInt();
        Options options = new Options();
        options.createIfMissing(true);
        try (DB idMapDb = JniDBFactory.factory.open(new File(userStorageDirectory + "/id_map.db"), options)) {
            try (WriteBatch batch = idMapDb.createWriteBatch()) {
                for (Map.Entry<String, Integer> entry : idMap.entrySet()) {
                    batch.put(bytes(entry.getKey()), bytes("" + entry.getValue()));
                }
                batch.put(bytes("__eventtracker__id"), bytes("" + currentId));
                idMapDb.write(batch);
            }
        }
    }
}
Also used : Options(org.iq80.leveldb.Options) File(java.io.File) Map(java.util.Map) WriteBatch(org.iq80.leveldb.WriteBatch) FileInputStream(java.io.FileInputStream) DB(org.iq80.leveldb.DB) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Options (org.iq80.leveldb.Options)26 File (java.io.File)21 IOException (java.io.IOException)14 DB (org.iq80.leveldb.DB)10 Path (org.apache.hadoop.fs.Path)8 NativeDB (org.fusesource.leveldbjni.internal.NativeDB)6 DBException (org.iq80.leveldb.DBException)6 WriteOptions (org.iq80.leveldb.WriteOptions)5 DB (com.codecademy.eventhub.base.DB)3 Provides (com.google.inject.Provides)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 JniDBFactory (org.fusesource.leveldbjni.JniDBFactory)3 RandomAccessFile (java.io.RandomAccessFile)2 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)1 DistributedLogNamespace (com.twitter.distributedlog.namespace.DistributedLogNamespace)1 FileInputStream (java.io.FileInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 URI (java.net.URI)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1