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

Compact dbs manually #6595

Merged
merged 5 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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, DbSettings settings, IDbConfig dbConfig, ILogM
}
}

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