Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Update Rocksdb options to use a common cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Puneetha17 committed Apr 9, 2019
1 parent c87be06 commit 3ff6b04
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public String toString() {

public static class Builder {
private final String PRIVATE_DATABASE_PATH = "private";
private final String PRIVATE_STATE_DATABASE_PATH = "privateState";

private boolean enabled;
private URI enclaveUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,27 @@
*/
package tech.pegasys.pantheon.services.kvstore;

import tech.pegasys.pantheon.services.util.RocksDbUtil;

import java.nio.file.Path;

import org.rocksdb.BlockBasedTableConfig;
import org.rocksdb.LRUCache;
import picocli.CommandLine;

public class RocksDbConfiguration {

private final Path databaseDir;
private final int maxOpenFiles;
private final BlockBasedTableConfig blockBasedTableConfig;

public RocksDbConfiguration(final Path databaseDir, final int maxOpenFiles) {
public RocksDbConfiguration(
final Path databaseDir, final int maxOpenFiles, final long cacheCapacity) {
RocksDbUtil.loadNativeLibrary();
this.databaseDir = databaseDir;
this.maxOpenFiles = maxOpenFiles;
this.blockBasedTableConfig =
new BlockBasedTableConfig().setBlockCache(new LRUCache(cacheCapacity));
}

public Path getDatabaseDir() {
Expand All @@ -34,6 +43,10 @@ public int getMaxOpenFiles() {
return maxOpenFiles;
}

public BlockBasedTableConfig getBlockBasedTableConfig() {
return blockBasedTableConfig;
}

public static class Builder {

Path databaseDir;
Expand All @@ -46,6 +59,14 @@ public static class Builder {
description = "Max number of files RocksDB will open (default: ${DEFAULT-VALUE})")
int maxOpenFiles;

@CommandLine.Option(
names = {"--Xrocksdb-cache-capacity"},
hidden = true,
defaultValue = "8388608",
paramLabel = "<LONG>",
description = "Cache capacity of RocksDB (default: ${DEFAULT-VALUE})")
long cacheCapacity;

public Builder databaseDir(final Path databaseDir) {
this.databaseDir = databaseDir;
return this;
Expand All @@ -56,8 +77,13 @@ public Builder maxOpenFiles(final int maxOpenFiles) {
return this;
}

public Builder cacheCapacity(final int cacheCapacity) {
this.cacheCapacity = cacheCapacity;
return this;
}

public RocksDbConfiguration build() {
return new RocksDbConfiguration(databaseDir, maxOpenFiles);
return new RocksDbConfiguration(databaseDir, maxOpenFiles, cacheCapacity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ private RocksDbKeyValueStorage(
options =
new Options()
.setCreateIfMissing(true)
.setMaxOpenFiles(rocksDbConfiguration.getMaxOpenFiles());
.setMaxOpenFiles(rocksDbConfiguration.getMaxOpenFiles())
.setTableFormatConfig(rocksDbConfiguration.getBlockBasedTableConfig());

txOptions = new TransactionDBOptions();
db = TransactionDB.open(options, txOptions, rocksDbConfiguration.getDatabaseDir().toString());

Expand Down

0 comments on commit 3ff6b04

Please sign in to comment.