Skip to content

Commit

Permalink
Blobdb for static data (hyperledger#5475)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
fab-10 authored and elenduuche committed Aug 16, 2023
1 parent feaf597 commit 7c9dccd
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and in case a rollback is needed, before installing a previous version, the migr
- Unite the tx-pool CLI options under the same Tx Pool Options group in UX. [#5466](https://github.com/hyperledger/besu/issues/5466)
- Tidy DEBUG logs by moving engine API full logging to TRACE [#5529](https://github.com/hyperledger/besu/pull/5529)
- remove PoW validation if merge is enabled as it is not needed anymore [#5538](https://github.com/hyperledger/besu/pull/5538)
- Use BlobDB for blockchain storage to reduce initial sync time and write amplification [#5475](https://github.com/hyperledger/besu/pull/5475)

### Bug Fixes
- check to ensure storage and transactions are not closed prior to reading/writing [#5527](https://github.com/hyperledger/besu/pull/5527)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.bouncycastle.util.Arrays;

public enum KeyValueSegmentIdentifier implements SegmentIdentifier {
BLOCKCHAIN(new byte[] {1}),
BLOCKCHAIN(new byte[] {1}, true),
WORLD_STATE(new byte[] {2}, new int[] {0, 1}),
PRIVATE_TRANSACTIONS(new byte[] {3}),
PRIVATE_STATE(new byte[] {4}),
Expand All @@ -44,14 +44,25 @@ public enum KeyValueSegmentIdentifier implements SegmentIdentifier {

private final byte[] id;
private final int[] versionList;
private final boolean containsStaticData;

KeyValueSegmentIdentifier(final byte[] id) {
this(id, new int[] {0, 1, 2});
}

KeyValueSegmentIdentifier(final byte[] id, final boolean containsStaticData) {
this(id, new int[] {0, 1, 2}, containsStaticData);
}

KeyValueSegmentIdentifier(final byte[] id, final int[] versionList) {
this(id, versionList, false);
}

KeyValueSegmentIdentifier(
final byte[] id, final int[] versionList, final boolean containsStaticData) {
this.id = id;
this.versionList = versionList;
this.containsStaticData = containsStaticData;
}

@Override
Expand All @@ -64,6 +75,11 @@ public byte[] getId() {
return id;
}

@Override
public boolean containsStaticData() {
return containsStaticData;
}

@Override
public boolean includeInDatabaseVersion(final int version) {
return Arrays.contains(versionList, version);
Expand Down
2 changes: 1 addition & 1 deletion plugin-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files
knownHash = 'V3sh575rrexPv+Ywe8mURT4Z3fREDCDd79PpAISFx8A='
knownHash = '5qYaRONxsvjtA3/9OOX4B1GEaOVEXLyU2zBFU0Kpu0E='
}
check.dependsOn('checkAPIChanges')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,13 @@ public interface SegmentIdentifier {
default boolean includeInDatabaseVersion(final int version) {
return true;
}

/**
* Define if this segment contains data that is never updated, but only added and optionally
* deleted. Example is append only data like the blockchain. This information can be used by the
* underlying implementation to apply specific optimization for this use case.
*
* @return true if the segment contains only static data
*/
boolean containsStaticData();
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,7 @@ public RocksDBColumnarKeyValueStorage(
.noneMatch(existed -> Arrays.equals(existed, ignorableSegment.getId())))
.forEach(trimmedSegments::remove);
columnDescriptors =
trimmedSegments.stream()
.map(
segment ->
new ColumnFamilyDescriptor(
segment.getId(),
new ColumnFamilyOptions()
.setTtl(0)
.setCompressionType(CompressionType.LZ4_COMPRESSION)
.setTableFormatConfig(createBlockBasedTableConfig(configuration))))
.collect(Collectors.toList());
trimmedSegments.stream().map(this::createColumnDescriptor).collect(Collectors.toList());
columnDescriptors.add(
new ColumnFamilyDescriptor(
DEFAULT_COLUMN.getBytes(StandardCharsets.UTF_8),
Expand All @@ -180,6 +171,24 @@ public RocksDBColumnarKeyValueStorage(
}
}

private ColumnFamilyDescriptor createColumnDescriptor(final SegmentIdentifier segment) {
final var options =
new ColumnFamilyOptions()
.setTtl(0)
.setCompressionType(CompressionType.LZ4_COMPRESSION)
.setTableFormatConfig(createBlockBasedTableConfig(configuration));

if (segment.containsStaticData()) {
options
.setEnableBlobFiles(true)
.setEnableBlobGarbageCollection(false)
.setMinBlobSize(100)
.setBlobCompressionType(CompressionType.LZ4_COMPRESSION);
}

return new ColumnFamilyDescriptor(segment.getId(), options);
}

private void setGlobalOptions(final RocksDBConfiguration configuration, final Statistics stats) {
options = new DBOptions();
options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,22 @@ public void dbWillBeBackwardIncompatibleAfterExperimentalSegmentsAreAdded() thro
public enum TestSegment implements SegmentIdentifier {
FOO(new byte[] {1}),
BAR(new byte[] {2}),
EXPERIMENTAL(new byte[] {3});
EXPERIMENTAL(new byte[] {3}),

STATIC_DATA(new byte[] {4}, true);

private final byte[] id;
private final String nameAsUtf8;
private final boolean containsStaticData;

TestSegment(final byte[] id) {
this(id, false);
}

TestSegment(final byte[] id, final boolean containsStaticData) {
this.id = id;
this.nameAsUtf8 = new String(id, StandardCharsets.UTF_8);
this.containsStaticData = containsStaticData;
}

@Override
Expand All @@ -280,6 +288,11 @@ public String getName() {
public byte[] getId() {
return id;
}

@Override
public boolean containsStaticData() {
return containsStaticData;
}
}

protected abstract SegmentedKeyValueStorage<RocksDbSegmentIdentifier> createSegmentedStore()
Expand Down

0 comments on commit 7c9dccd

Please sign in to comment.