This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
RocksDB Metrics #531
Merged
Merged
RocksDB Metrics #531
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,10 @@ | |
*/ | ||
package tech.pegasys.pantheon.services.kvstore; | ||
|
||
import tech.pegasys.pantheon.metrics.Counter; | ||
import tech.pegasys.pantheon.metrics.MetricCategory; | ||
import tech.pegasys.pantheon.metrics.MetricsSystem; | ||
import tech.pegasys.pantheon.metrics.OperationTimer; | ||
import tech.pegasys.pantheon.util.bytes.BytesValue; | ||
|
||
import java.io.Closeable; | ||
|
@@ -44,19 +48,45 @@ public class RocksDbKeyValueStorage implements KeyValueStorage, Closeable { | |
private final TransactionDB db; | ||
private final AtomicBoolean closed = new AtomicBoolean(false); | ||
|
||
private final OperationTimer readLatency; | ||
private final OperationTimer removeLatency; | ||
private final OperationTimer writeLatency; | ||
private final OperationTimer commitLatency; | ||
private final Counter rollbackCount; | ||
|
||
static { | ||
RocksDB.loadLibrary(); | ||
} | ||
|
||
public static KeyValueStorage create(final Path storageDirectory) throws StorageException { | ||
return new RocksDbKeyValueStorage(storageDirectory); | ||
public static KeyValueStorage create( | ||
final Path storageDirectory, final MetricsSystem metricsSystem) throws StorageException { | ||
return new RocksDbKeyValueStorage(storageDirectory, metricsSystem); | ||
} | ||
|
||
private RocksDbKeyValueStorage(final Path storageDirectory) { | ||
private RocksDbKeyValueStorage(final Path storageDirectory, final MetricsSystem metricsSystem) { | ||
try { | ||
options = new Options().setCreateIfMissing(true); | ||
txOptions = new TransactionDBOptions(); | ||
db = TransactionDB.open(options, txOptions, storageDirectory.toString()); | ||
|
||
readLatency = | ||
metricsSystem.createTimer( | ||
MetricCategory.ROCKSDB, "read_latency_seconds", "Latency for read from RocksDB."); | ||
removeLatency = | ||
metricsSystem.createTimer( | ||
MetricCategory.ROCKSDB, | ||
"remove_latency_seconds", | ||
"Latency of remove requests from RocksDB."); | ||
writeLatency = | ||
metricsSystem.createTimer( | ||
MetricCategory.ROCKSDB, "write_latency_seconds", "Latency for write to RocksDB."); | ||
commitLatency = | ||
metricsSystem.createTimer( | ||
MetricCategory.ROCKSDB, "commit_latency_seconds", "Latency for write to RocksDB."); | ||
|
||
rollbackCount = | ||
metricsSystem.createCounter( | ||
MetricCategory.ROCKSDB, "rollback_count", "Number of transactions rolled back."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make the description "Number of RocksDB transactions rolled back."? I know it will have rocksdb in the key as well but it would be easy to confuse this with number of EVM transactions rolled back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} catch (final RocksDBException e) { | ||
throw new StorageException(e); | ||
} | ||
|
@@ -65,7 +95,8 @@ private RocksDbKeyValueStorage(final Path storageDirectory) { | |
@Override | ||
public Optional<BytesValue> get(final BytesValue key) throws StorageException { | ||
throwIfClosed(); | ||
try { | ||
|
||
try (final OperationTimer.TimingContext ignored = readLatency.startTimer()) { | ||
return Optional.ofNullable(db.get(key.extractArray())).map(BytesValue::wrap); | ||
} catch (final RocksDBException e) { | ||
throw new StorageException(e); | ||
|
@@ -143,7 +174,7 @@ public Entry next() { | |
return entry; | ||
} | ||
|
||
public Stream<Entry> toStream() { | ||
Stream<Entry> toStream() { | ||
final Spliterator<Entry> split = | ||
Spliterators.spliteratorUnknownSize( | ||
this, Spliterator.IMMUTABLE | Spliterator.DISTINCT | Spliterator.NONNULL); | ||
|
@@ -158,7 +189,7 @@ public void close() { | |
} | ||
} | ||
|
||
private static class RocksDbTransaction extends AbstractTransaction { | ||
private class RocksDbTransaction extends AbstractTransaction { | ||
private final org.rocksdb.Transaction innerTx; | ||
private final WriteOptions options; | ||
|
||
|
@@ -169,7 +200,7 @@ private static class RocksDbTransaction extends AbstractTransaction { | |
|
||
@Override | ||
protected void doPut(final BytesValue key, final BytesValue value) { | ||
try { | ||
try (final OperationTimer.TimingContext ignored = writeLatency.startTimer()) { | ||
innerTx.put(key.extractArray(), value.extractArray()); | ||
} catch (final RocksDBException e) { | ||
throw new StorageException(e); | ||
|
@@ -178,7 +209,7 @@ protected void doPut(final BytesValue key, final BytesValue value) { | |
|
||
@Override | ||
protected void doRemove(final BytesValue key) { | ||
try { | ||
try (final OperationTimer.TimingContext ignored = removeLatency.startTimer()) { | ||
innerTx.delete(key.extractArray()); | ||
} catch (final RocksDBException e) { | ||
throw new StorageException(e); | ||
|
@@ -187,7 +218,7 @@ protected void doRemove(final BytesValue key) { | |
|
||
@Override | ||
protected void doCommit() throws StorageException { | ||
try { | ||
try (final OperationTimer.TimingContext ignored = commitLatency.startTimer()) { | ||
innerTx.commit(); | ||
} catch (final RocksDBException e) { | ||
throw new StorageException(e); | ||
|
@@ -200,6 +231,7 @@ protected void doCommit() throws StorageException { | |
protected void doRollback() { | ||
try { | ||
innerTx.rollback(); | ||
rollbackCount.inc(); | ||
} catch (final RocksDBException e) { | ||
throw new StorageException(e); | ||
} finally { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description is incorrect, should be "for commit" not "for write"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done