use of org.iq80.leveldb.DB in project qi4j-sdk by Qi4j.
the class LevelDBEntityStoreMixin method activateService.
@Override
public void activateService() throws Exception {
charset = Charset.forName("UTF-8");
configuration.refresh();
LevelDBEntityStoreConfiguration config = configuration.get();
// Choose flavour
String flavour = config.flavour().get();
DBFactory factory;
if ("jni".equalsIgnoreCase(flavour)) {
factory = newJniDBFactory();
} else if ("java".equalsIgnoreCase(flavour)) {
factory = newJavaDBFactory();
} else {
factory = newDBFactory();
}
// Apply configuration
Options options = new Options();
options.createIfMissing(true);
if (config.blockRestartInterval().get() != null) {
options.blockRestartInterval(config.blockRestartInterval().get());
}
if (config.blockSize().get() != null) {
options.blockSize(config.blockSize().get());
}
if (config.cacheSize().get() != null) {
options.cacheSize(config.cacheSize().get());
}
if (config.compression().get() != null) {
options.compressionType(config.compression().get() ? CompressionType.SNAPPY : CompressionType.NONE);
}
if (config.maxOpenFiles().get() != null) {
options.maxOpenFiles(config.maxOpenFiles().get());
}
if (config.paranoidChecks().get() != null) {
options.paranoidChecks(config.paranoidChecks().get());
}
if (config.verifyChecksums().get() != null) {
options.verifyChecksums(config.verifyChecksums().get());
}
if (config.writeBufferSize().get() != null) {
options.writeBufferSize(config.writeBufferSize().get());
}
// Open/Create the database
File dbFile = new File(fileConfig.dataDirectory(), descriptor.identity());
db = factory.open(dbFile, options);
}
use of org.iq80.leveldb.DB 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);
}
}
}
}
use of org.iq80.leveldb.DB 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.DB in project cdap by caskdata.
the class LevelDBTableCore method deleteColumn.
public void deleteColumn(byte[] row, byte[] column) throws IOException {
DB db = getDB();
WriteBatch batch = db.createWriteBatch();
try (DBIterator iterator = db.iterator()) {
addToDeleteBatch(batch, iterator, row, column);
db.write(batch);
}
}
use of org.iq80.leveldb.DB in project cdap by caskdata.
the class LevelDBTableCore method deleteRows.
public void deleteRows(byte[] prefix) throws IOException {
Preconditions.checkNotNull(prefix, "prefix must not be null");
DB db = getDB();
WriteBatch batch = db.createWriteBatch();
try (DBIterator iterator = db.iterator()) {
iterator.seek(createStartKey(prefix));
while (iterator.hasNext()) {
Map.Entry<byte[], byte[]> entry = iterator.next();
if (!Bytes.startsWith(KeyValue.fromKey(entry.getKey()).getRow(), prefix)) {
// iterator is past prefix
break;
}
batch.delete(entry.getKey());
}
db.write(batch);
}
}
Aggregations