Search in sources :

Example 11 with WriteOptions

use of org.rocksdb.WriteOptions in project jstorm by alibaba.

the class RocksDbHdfsState method putBatch.

@Override
public void putBatch(Map<K, V> batch) {
    try {
        WriteBatch writeBatch = new WriteBatch();
        for (Map.Entry<K, V> entry : batch.entrySet()) {
            writeBatch.put(serializer.serialize(entry.getKey()), serializer.serialize(entry.getValue()));
        }
        rocksDb.write(new WriteOptions(), writeBatch);
    } catch (RocksDBException e) {
        LOG.error("Failed to put batch={}", batch);
        throw new RuntimeException(e.getMessage());
    }
}
Also used : WriteOptions(org.rocksdb.WriteOptions) RocksDBException(org.rocksdb.RocksDBException) WriteBatch(org.rocksdb.WriteBatch) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with WriteOptions

use of org.rocksdb.WriteOptions in project jstorm by alibaba.

the class WindowedRocksDbHdfsState method putBatch.

@Override
public void putBatch(TimeWindow window, Map<K, V> batch) {
    try {
        ColumnFamilyHandle handler = getColumnFamilyHandle(window);
        WriteBatch writeBatch = new WriteBatch();
        for (Map.Entry<K, V> entry : batch.entrySet()) {
            writeBatch.put(handler, serializer.serialize(entry.getKey()), serializer.serialize(entry.getValue()));
        }
        rocksDb.write(new WriteOptions(), writeBatch);
    } catch (RocksDBException e) {
        LOG.error("Failed to put batch={} for window={}", batch, window);
        throw new RuntimeException(e.getMessage());
    }
}
Also used : WriteOptions(org.rocksdb.WriteOptions) RocksDBException(org.rocksdb.RocksDBException) WriteBatch(org.rocksdb.WriteBatch) HashMap(java.util.HashMap) Map(java.util.Map) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle)

Example 13 with WriteOptions

use of org.rocksdb.WriteOptions in project aion by aionnetwork.

the class RocksDBWrapper method setupWriteOptions.

private WriteOptions setupWriteOptions() {
    WriteOptions options = new WriteOptions();
    options.setLowPri(true);
    return options;
}
Also used : WriteOptions(org.rocksdb.WriteOptions)

Example 14 with WriteOptions

use of org.rocksdb.WriteOptions in project aion by aionnetwork.

the class RocksDBWrapper method open.

// IDatabase Functionality
@Override
public boolean open() {
    if (isOpen()) {
        return true;
    }
    LOG.debug("Initialising RockDB {}", this.toString());
    File f = new File(path);
    File dbRoot = f.getParentFile();
    // make the parent directory if not exists
    if (!dbRoot.exists()) {
        if (!f.getParentFile().mkdirs()) {
            LOG.error("Failed to initialize the database storage for " + this.toString() + ".");
            return false;
        }
    }
    writeOptions = setupWriteOptions();
    Options options = setupRocksDbOptions();
    try {
        db = RocksDB.open(options, f.getAbsolutePath());
    } catch (RocksDBException e) {
        if (e.getMessage().contains("lock")) {
            LOG.error("Failed to open the database " + this.toString() + "\nCheck if you have two instances running on the same database." + "\nFailure due to: ", e);
        } else {
            LOG.error("Failed to open the database " + this.toString() + " due to: ", e);
        }
        // close the connection and cleanup if needed
        close();
    }
    return isOpen();
}
Also used : ReadOptions(org.rocksdb.ReadOptions) WriteOptions(org.rocksdb.WriteOptions) Options(org.rocksdb.Options) RocksDBException(org.rocksdb.RocksDBException) File(java.io.File)

Example 15 with WriteOptions

use of org.rocksdb.WriteOptions in project flink by apache.

the class ListViaRangeSpeedMiniBenchmark method main.

public static void main(String[] args) throws Exception {
    final File rocksDir = new File("/tmp/rdb");
    FileUtils.deleteDirectory(rocksDir);
    final Options options = new Options().setCompactionStyle(CompactionStyle.LEVEL).setLevelCompactionDynamicLevelBytes(true).setIncreaseParallelism(4).setUseFsync(false).setMaxOpenFiles(-1).setDisableDataSync(true).setCreateIfMissing(true).setMergeOperator(new StringAppendOperator());
    final WriteOptions write_options = new WriteOptions().setSync(false).setDisableWAL(true);
    final RocksDB rocksDB = RocksDB.open(options, rocksDir.getAbsolutePath());
    final String key = "key";
    final String value = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ7890654321";
    final byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
    final byte[] valueBytes = value.getBytes(StandardCharsets.UTF_8);
    final byte[] keyTemplate = Arrays.copyOf(keyBytes, keyBytes.length + 4);
    final Unsafe unsafe = MemoryUtils.UNSAFE;
    final long offset = unsafe.arrayBaseOffset(byte[].class) + keyTemplate.length - 4;
    final int num = 50000;
    System.out.println("begin insert");
    final long beginInsert = System.nanoTime();
    for (int i = 0; i < num; i++) {
        unsafe.putInt(keyTemplate, offset, i);
        rocksDB.put(write_options, keyTemplate, valueBytes);
    }
    final long endInsert = System.nanoTime();
    System.out.println("end insert - duration: " + ((endInsert - beginInsert) / 1_000_000) + " ms");
    final byte[] resultHolder = new byte[num * valueBytes.length];
    final long beginGet = System.nanoTime();
    final RocksIterator iterator = rocksDB.newIterator();
    int pos = 0;
    // seek to start
    unsafe.putInt(keyTemplate, offset, 0);
    iterator.seek(keyTemplate);
    // mark end
    unsafe.putInt(keyTemplate, offset, -1);
    // iterate
    while (iterator.isValid()) {
        byte[] currKey = iterator.key();
        if (samePrefix(keyBytes, currKey)) {
            byte[] currValue = iterator.value();
            System.arraycopy(currValue, 0, resultHolder, pos, currValue.length);
            pos += currValue.length;
            iterator.next();
        } else {
            break;
        }
    }
    final long endGet = System.nanoTime();
    System.out.println("end get - duration: " + ((endGet - beginGet) / 1_000_000) + " ms");
}
Also used : Options(org.rocksdb.Options) WriteOptions(org.rocksdb.WriteOptions) WriteOptions(org.rocksdb.WriteOptions) RocksDB(org.rocksdb.RocksDB) StringAppendOperator(org.rocksdb.StringAppendOperator) Unsafe(sun.misc.Unsafe) RocksIterator(org.rocksdb.RocksIterator) File(java.io.File)

Aggregations

WriteOptions (org.rocksdb.WriteOptions)23 File (java.io.File)11 FlushOptions (org.rocksdb.FlushOptions)9 Options (org.rocksdb.Options)9 Test (org.junit.Test)7 RocksDB (org.rocksdb.RocksDB)6 MapConfig (org.apache.samza.config.MapConfig)5 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)5 ColumnFamilyHandle (org.rocksdb.ColumnFamilyHandle)5 IOException (java.io.IOException)4 ColumnFamilyDescriptor (org.rocksdb.ColumnFamilyDescriptor)4 ColumnFamilyOptions (org.rocksdb.ColumnFamilyOptions)4 RocksDBException (org.rocksdb.RocksDBException)4 WriteBatch (org.rocksdb.WriteBatch)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 RocksDBConfigSetter (org.apache.kafka.streams.state.RocksDBConfigSetter)3 Config (org.apache.samza.config.Config)3 BlockBasedTableConfig (org.rocksdb.BlockBasedTableConfig)3 DBOptions (org.rocksdb.DBOptions)3 ReadOptions (org.rocksdb.ReadOptions)3