Skip to content

Commit

Permalink
Compact dbs manually (#6595)
Browse files Browse the repository at this point in the history
(cherry picked from commit d0ed28b)
  • Loading branch information
flcl42 authored and MarekM25 committed Feb 6, 2024
1 parent dc1db75 commit 41a1593
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 8 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,14 @@ public ColumnsDb(string basePath, RocksDbSettings settings, IDbConfig dbConfig,
}
}

public override void Compact()
{
foreach (T key in ColumnKeys)
{
_columnDbs[key].Compact();
}
}

private static IReadOnlyList<T> GetEnumKeys(IReadOnlyList<T> keys)
{
if (typeof(T).IsEnum && keys.Count == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ public void Flush()
InnerFlush();
}

public void Compact()
public virtual void Compact()
{
_db.CompactRange(Keccak.Zero.BytesToArray(), Keccak.MaxValue.BytesToArray());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ProcessedTransactionsDbCleaner(IBlockFinalizationManager finalizationMana

private void OnBlocksFinalized(object? sender, FinalizeEventArgs e)
{
if (e.FinalizedBlocks.Count > 0 && e.FinalizedBlocks[0].Number > _lastFinalizedBlock)
if (e.FinalizedBlocks.Count > 0 && e.FinalizedBlocks[0].Number > _lastFinalizedBlock && CleaningTask.IsCompleted)
{
CleaningTask = Task.Run(() => CleanProcessedTransactionsDb(e.FinalizedBlocks[0].Number));
}
Expand All @@ -55,6 +55,10 @@ private void CleanProcessedTransactionsDb(long newlyFinalizedBlockNumber)

if (_logger.IsDebug) _logger.Debug($"Cleaned processed blob txs from block {_lastFinalizedBlock} to block {newlyFinalizedBlockNumber}");

_processedTxsDb.Compact();

if (_logger.IsDebug) _logger.Debug($"Blob transactions database columns have been compacted");

_lastFinalizedBlock = newlyFinalizedBlockNumber;
}
catch (Exception exception)
Expand Down

0 comments on commit 41a1593

Please sign in to comment.