Skip to content

Commit

Permalink
Cleanup rocksdb config and metrics (#6642)
Browse files Browse the repository at this point in the history
  • Loading branch information
asdacap authored Feb 2, 2024
1 parent a33a8b9 commit b6f593f
Show file tree
Hide file tree
Showing 30 changed files with 750 additions and 298 deletions.
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Blockchain/Blocks/BlockStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void SetMetadata(byte[] key, byte[] value)

private void TruncateToMaxSize()
{
int toDelete = (int)(_blockDb.GetSize() - _maxSize!);
int toDelete = (int)(_blockDb.GatherMetric().Size - _maxSize!);
if (toDelete > 0)
{
foreach (var blockToDelete in GetAll().Take(toDelete))
Expand Down
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.Core/Attributes/Metrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public sealed class GaugeMetricAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public sealed class KeyIsLabelAttribute : Attribute
{
public string LabelName { get; }
public string[] LabelNames { get; }

public KeyIsLabelAttribute(string labelName)
public KeyIsLabelAttribute(params string[] labelNames)
{
LabelName = labelName;
LabelNames = labelNames;
}
}
12 changes: 7 additions & 5 deletions src/Nethermind/Nethermind.Db.Rocks/ColumnDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ public void Remove(ReadOnlySpan<byte> key)
_rocksDb.Remove(key, _columnFamily, _mainDb.WriteOptions);
}

public bool KeyExists(ReadOnlySpan<byte> key) => _rocksDb.Get(key, _columnFamily) is not null;
public bool KeyExists(ReadOnlySpan<byte> key)
{
return _mainDb.KeyExistsWithColumn(key, _columnFamily);
}

public void Flush()
{
Expand All @@ -138,10 +141,9 @@ public void Compact()
/// </summary>
/// <exception cref="NotSupportedException"></exception>
public void Clear() { throw new NotSupportedException(); }
public long GetSize() => _mainDb.GetSize();
public long GetCacheSize() => _mainDb.GetCacheSize();
public long GetIndexSize() => _mainDb.GetIndexSize();
public long GetMemtableSize() => _mainDb.GetMemtableSize();

// Maybe it should be column specific metric?
public IDbMeta.DbMetric GatherMetric(bool includeSharedCache = false) => _mainDb.GatherMetric(includeSharedCache);

public void DangerousReleaseMemory(in ReadOnlySpan<byte> span)
{
Expand Down
15 changes: 15 additions & 0 deletions src/Nethermind/Nethermind.Db.Rocks/ColumnsDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ public ColumnsDb(string basePath, DbSettings settings, IDbConfig dbConfig, ILogM
}
}

protected override long FetchTotalPropertyValue(string propertyName)
{
long total = 0;
foreach (KeyValuePair<T, ColumnDb> kv in _columnDbs)
{
long value = long.TryParse(_db.GetProperty(propertyName, kv.Value._columnFamily), out long parsedValue)
? parsedValue
: 0;

total += value;
}

return total;
}

public override void Compact()
{
foreach (T key in ColumnKeys)
Expand Down
28 changes: 28 additions & 0 deletions src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ public class DbConfig : IDbConfig
public ulong? MaxBytesForLevelBase { get; set; } = (ulong)256.MiB();
public ulong TargetFileSizeBase { get; set; } = (ulong)64.MiB();
public int TargetFileSizeMultiplier { get; set; } = 1;
public bool UseTwoLevelIndex { get; set; } = true;
public bool UseHashIndex { get; set; } = false;
public ulong? PrefixExtractorLength { get; set; } = null;
public bool AllowMmapReads { get; set; } = false;
public bool VerifyChecksum { get; set; } = true;
public double MaxBytesForLevelMultiplier { get; set; } = 10;
public ulong? MaxCompactionBytes { get; set; } = null;
public int MinWriteBufferNumberToMerge { get; set; } = 1;
public ulong? RowCacheSize { get; set; } = null;
public bool OptimizeFiltersForHits { get; set; } = true;
public bool OnlyCompressLastLevel { get; set; } = false;
public long? MaxWriteBufferSizeToMaintain { get; set; } = null;
public bool UseHashSkipListMemtable { get; set; } = false;
public int BlockRestartInterval { get; set; } = 16;

public ulong ReceiptsDbWriteBufferSize { get; set; } = (ulong)8.MiB();
public uint ReceiptsDbWriteBufferNumber { get; set; } = 4;
Expand Down Expand Up @@ -174,6 +188,20 @@ public class DbConfig : IDbConfig
public ulong? StateDbCompactionReadAhead { get; set; }
public bool? StateDbDisableCompression { get; set; } = false;
public int StateDbTargetFileSizeMultiplier { get; set; } = 2;
public bool StateDbUseTwoLevelIndex { get; set; } = true;
public bool StateDbUseHashIndex { get; set; } = false;
public ulong? StateDbPrefixExtractorLength { get; set; } = null;
public bool StateDbAllowMmapReads { get; set; } = false;
public bool StateDbVerifyChecksum { get; set; } = true;
public double StateDbMaxBytesForLevelMultiplier { get; set; } = 10;
public ulong? StateDbMaxCompactionBytes { get; set; } = null;
public int StateDbMinWriteBufferNumberToMerge { get; set; } = 1;
public ulong? StateDbRowCacheSize { get; set; } = null;
public bool StateDbOptimizeFiltersForHits { get; set; } = true;
public bool StateDbOnlyCompressLastLevel { get; set; } = false;
public long? StateDbMaxWriteBufferSizeToMaintain { get; set; } = null;
public bool StateDbUseHashSkipListMemtable { get; set; } = false;
public int StateDbBlockRestartInterval { get; set; } = 16;
public IDictionary<string, string>? StateDbAdditionalRocksDbOptions { get; set; }

public uint RecycleLogFileNum { get; set; } = 0;
Expand Down
28 changes: 28 additions & 0 deletions src/Nethermind/Nethermind.Db.Rocks/Config/IDbConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ public interface IDbConfig : IConfig
ulong? MaxBytesForLevelBase { get; set; }
ulong TargetFileSizeBase { get; set; }
int TargetFileSizeMultiplier { get; set; }
bool UseTwoLevelIndex { get; set; }
bool UseHashIndex { get; set; }
ulong? PrefixExtractorLength { get; set; }
bool AllowMmapReads { get; set; }
bool VerifyChecksum { get; set; }
double MaxBytesForLevelMultiplier { get; set; }
ulong? MaxCompactionBytes { get; set; }
int MinWriteBufferNumberToMerge { get; set; }
ulong? RowCacheSize { get; set; }
bool OptimizeFiltersForHits { get; set; }
bool OnlyCompressLastLevel { get; set; }
long? MaxWriteBufferSizeToMaintain { get; set; }
bool UseHashSkipListMemtable { get; set; }
int BlockRestartInterval { get; set; }

ulong ReceiptsDbWriteBufferSize { get; set; }
uint ReceiptsDbWriteBufferNumber { get; set; }
Expand Down Expand Up @@ -174,6 +188,20 @@ public interface IDbConfig : IConfig
ulong? StateDbCompactionReadAhead { get; set; }
bool? StateDbDisableCompression { get; set; }
int StateDbTargetFileSizeMultiplier { get; set; }
bool StateDbUseTwoLevelIndex { get; set; }
bool StateDbUseHashIndex { get; set; }
ulong? StateDbPrefixExtractorLength { get; set; }
bool StateDbAllowMmapReads { get; set; }
bool StateDbVerifyChecksum { get; set; }
double StateDbMaxBytesForLevelMultiplier { get; set; }
ulong? StateDbMaxCompactionBytes { get; set; }
int StateDbMinWriteBufferNumberToMerge { get; set; }
ulong? StateDbRowCacheSize { get; set; }
bool StateDbOptimizeFiltersForHits { get; set; }
bool StateDbOnlyCompressLastLevel { get; set; }
long? StateDbMaxWriteBufferSizeToMaintain { get; set; }
bool StateDbUseHashSkipListMemtable { get; set; }
int StateDbBlockRestartInterval { get; set; }
IDictionary<string, string>? StateDbAdditionalRocksDbOptions { get; set; }

/// <summary>
Expand Down
14 changes: 14 additions & 0 deletions src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ public PerTableDbConfig(IDbConfig dbConfig, DbSettings dbSettings, string? colum
public ulong MaxBytesForLevelBase => ReadConfig<ulong>(nameof(MaxBytesForLevelBase));
public ulong TargetFileSizeBase => ReadConfig<ulong>(nameof(TargetFileSizeBase));
public int TargetFileSizeMultiplier => ReadConfig<int>(nameof(TargetFileSizeMultiplier));
public bool UseTwoLevelIndex => ReadConfig<bool>(nameof(UseTwoLevelIndex));
public bool UseHashIndex => ReadConfig<bool>(nameof(UseHashIndex));
public ulong? PrefixExtractorLength => ReadConfig<ulong?>(nameof(PrefixExtractorLength));
public bool AllowMmapReads => ReadConfig<bool>(nameof(AllowMmapReads));
public bool VerifyChecksum => ReadConfig<bool>(nameof(VerifyChecksum));
public double MaxBytesForLevelMultiplier => ReadConfig<double>(nameof(MaxBytesForLevelMultiplier));
public ulong? MaxCompactionBytes => ReadConfig<ulong?>(nameof(MaxCompactionBytes));
public int MinWriteBufferNumberToMerge => ReadConfig<int>(nameof(MinWriteBufferNumberToMerge));
public ulong? RowCacheSize => ReadConfig<ulong?>(nameof(RowCacheSize));
public bool OptimizeFiltersForHits => ReadConfig<bool>(nameof(OptimizeFiltersForHits));
public bool OnlyCompressLastLevel => ReadConfig<bool>(nameof(OnlyCompressLastLevel));
public long? MaxWriteBufferSizeToMaintain => ReadConfig<long?>(nameof(MaxWriteBufferSizeToMaintain));
public bool UseHashSkipListMemtable => ReadConfig<bool>(nameof(UseHashSkipListMemtable));
public int BlockRestartInterval => ReadConfig<int>(nameof(BlockRestartInterval));

private T? ReadConfig<T>(string propertyName)
{
Expand Down
Loading

0 comments on commit b6f593f

Please sign in to comment.