Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove v0 version of the database #5698

Merged
merged 5 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update tests
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
  • Loading branch information
matkt committed Jul 12, 2023
commit 0a8f8d2ae620f4c0415173ade702302c4048c5f0
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.hyperledger.besu.plugin.services.storage.rocksdb.segmented;

import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier;
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBMetricsFactory;
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDbSegmentIdentifier;
Expand All @@ -26,7 +27,10 @@
import java.util.List;

import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class OptimisticTransactionDBRocksDBColumnarKeyValueStorageTest
extends RocksDBColumnarKeyValueStorageTest {

Expand Down Expand Up @@ -55,4 +59,18 @@ protected SegmentedKeyValueStorage<RocksDbSegmentIdentifier> createSegmentedStor
new NoOpMetricsSystem(),
RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS);
}

@Override
protected SegmentedKeyValueStorage<RocksDbSegmentIdentifier> createSegmentedStore(
final Path path,
final MetricsSystem metricsSystem,
final List<SegmentIdentifier> segments,
final List<SegmentIdentifier> ignorableSegments) {
return new OptimisticRocksDBColumnarKeyValueStorage(
new RocksDBConfigurationBuilder().databaseDir(path).build(),
segments,
ignorableSegments,
metricsSystem,
RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,21 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.hyperledger.besu.kvstore.AbstractKeyValueStorageTest;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.exception.StorageException;
import org.hyperledger.besu.plugin.services.metrics.Counter;
import org.hyperledger.besu.plugin.services.metrics.LabelledMetric;
import org.hyperledger.besu.plugin.services.metrics.OperationTimer;
import org.hyperledger.besu.plugin.services.storage.KeyValueStorage;
import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier;
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDbSegmentIdentifier;
Expand All @@ -33,13 +45,21 @@
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.LongSupplier;

import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

public abstract class RocksDBColumnarKeyValueStorageTest extends AbstractKeyValueStorageTest {

@Mock private ObservableMetricsSystem metricsSystemMock;
@Mock private LabelledMetric<OperationTimer> labelledMetricOperationTimerMock;
@Mock private LabelledMetric<Counter> labelledMetricCounterMock;
@Mock private OperationTimer operationTimerMock;

@TempDir public Path folder;

@Test
Expand Down Expand Up @@ -257,6 +277,80 @@ public void dbWillBeBackwardIncompatibleAfterExperimentalSegmentsAreAdded(
}
}

@Test
public void createStoreMustCreateMetrics() throws Exception {
// Prepare mocks
when(labelledMetricOperationTimerMock.labels(any())).thenReturn(operationTimerMock);
when(metricsSystemMock.createLabelledTimer(
eq(BesuMetricCategory.KVSTORE_ROCKSDB), anyString(), anyString(), any()))
.thenReturn(labelledMetricOperationTimerMock);
when(metricsSystemMock.createLabelledCounter(
eq(BesuMetricCategory.KVSTORE_ROCKSDB), anyString(), anyString(), any()))
.thenReturn(labelledMetricCounterMock);
// Prepare argument captors
final ArgumentCaptor<String> labelledTimersMetricsNameArgs =
ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<String> labelledTimersHelpArgs = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<String> labelledCountersMetricsNameArgs =
ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<String> labelledCountersHelpArgs = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<String> longGaugesMetricsNameArgs = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<String> longGaugesHelpArgs = ArgumentCaptor.forClass(String.class);

// Actual call

final SegmentedKeyValueStorage<RocksDbSegmentIdentifier> store =
createSegmentedStore(
folder, metricsSystemMock, List.of(TestSegment.FOO), List.of(TestSegment.EXPERIMENTAL));

KeyValueStorage keyValueStorage =
new SnappableSegmentedKeyValueStorageAdapter<>(TestSegment.FOO, store);

// Assertions
assertThat(keyValueStorage).isNotNull();
verify(metricsSystemMock, times(4))
.createLabelledTimer(
eq(BesuMetricCategory.KVSTORE_ROCKSDB),
labelledTimersMetricsNameArgs.capture(),
labelledTimersHelpArgs.capture(),
any());
assertThat(labelledTimersMetricsNameArgs.getAllValues())
.containsExactly(
"read_latency_seconds",
"remove_latency_seconds",
"write_latency_seconds",
"commit_latency_seconds");
assertThat(labelledTimersHelpArgs.getAllValues())
.containsExactly(
"Latency for read from RocksDB.",
"Latency of remove requests from RocksDB.",
"Latency for write to RocksDB.",
"Latency for commits to RocksDB.");

verify(metricsSystemMock, times(2))
.createLongGauge(
eq(BesuMetricCategory.KVSTORE_ROCKSDB),
longGaugesMetricsNameArgs.capture(),
longGaugesHelpArgs.capture(),
any(LongSupplier.class));
assertThat(longGaugesMetricsNameArgs.getAllValues())
.containsExactly("rocks_db_table_readers_memory_bytes", "rocks_db_files_size_bytes");
assertThat(longGaugesHelpArgs.getAllValues())
.containsExactly(
"Estimated memory used for RocksDB index and filter blocks in bytes",
"Estimated database size in bytes");

verify(metricsSystemMock)
.createLabelledCounter(
eq(BesuMetricCategory.KVSTORE_ROCKSDB),
labelledCountersMetricsNameArgs.capture(),
labelledCountersHelpArgs.capture(),
any());
assertThat(labelledCountersMetricsNameArgs.getValue()).isEqualTo("rollback_count");
assertThat(labelledCountersHelpArgs.getValue())
.isEqualTo("Number of RocksDB transactions rolled back.");
}

public enum TestSegment implements SegmentIdentifier {
FOO(new byte[] {1}),
BAR(new byte[] {2}),
Expand Down Expand Up @@ -302,6 +396,12 @@ protected abstract SegmentedKeyValueStorage<RocksDbSegmentIdentifier> createSegm
final List<SegmentIdentifier> segments,
final List<SegmentIdentifier> ignorableSegments);

protected abstract SegmentedKeyValueStorage<RocksDbSegmentIdentifier> createSegmentedStore(
final Path path,
final MetricsSystem metricsSystem,
final List<SegmentIdentifier> segments,
final List<SegmentIdentifier> ignorableSegments);

@Override
protected KeyValueStorage createStore() throws Exception {
return new SnappableSegmentedKeyValueStorageAdapter<>(TestSegment.FOO, createSegmentedStore());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.hyperledger.besu.plugin.services.storage.rocksdb.segmented;

import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier;
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBMetricsFactory;
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDbSegmentIdentifier;
Expand All @@ -25,6 +26,10 @@
import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class TransactionDBRocksDBColumnarKeyValueStorageTest
extends RocksDBColumnarKeyValueStorageTest {

Expand All @@ -51,4 +56,18 @@ protected SegmentedKeyValueStorage<RocksDbSegmentIdentifier> createSegmentedStor
new NoOpMetricsSystem(),
RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS);
}

@Override
protected SegmentedKeyValueStorage<RocksDbSegmentIdentifier> createSegmentedStore(
final Path path,
final MetricsSystem metricsSystem,
final List<SegmentIdentifier> segments,
final List<SegmentIdentifier> ignorableSegments) {
return new TransactionDBRocksDBColumnarKeyValueStorage(
new RocksDBConfigurationBuilder().databaseDir(path).build(),
segments,
ignorableSegments,
metricsSystem,
RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS);
}
}