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