Skip to content

feat: add SkipMetricsTracking property to DbSettings#11515

Open
cbermudez97 wants to merge 1 commit intomasterfrom
fix/db-metrics
Open

feat: add SkipMetricsTracking property to DbSettings#11515
cbermudez97 wants to merge 1 commit intomasterfrom
fix/db-metrics

Conversation

@cbermudez97
Copy link
Copy Markdown
Contributor

Changes

  • Introduced SkipMetricsTracking property in DbSettings to control metrics tracking for specific databases.
  • Updated FullPruningInnerDbFactory to set SkipMetricsTracking to true for inner databases to prevent stale references after pruning.
  • Added unit tests to verify the behavior of metrics tracking based on the new property.
  • Enhanced DbMonitoringModule to respect the SkipMetricsTracking setting when adding databases to the tracker.

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

- Introduced SkipMetricsTracking property in DbSettings to control metrics tracking for specific databases.
- Updated FullPruningInnerDbFactory to set SkipMetricsTracking to true for inner databases to prevent stale references after pruning.
- Added unit tests to verify the behavior of metrics tracking based on the new property.
- Enhanced DbMonitoringModule to respect the SkipMetricsTracking setting when adding databases to the tracker.
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 7, 2026

Claude finished @cbermudez97's task in 3m 42s —— View job


PR Review: feat: add SkipMetricsTracking property to DbSettings

  • Gather context and read changed files
  • Load relevant AGENTS rules
  • Review all changed files
  • Post inline comments
  • Post final summary

Summary

The fix is correct and well-designed. The root cause is clear: FullPruningInnerDbFactory creates indexed sub-DBs that get registered into the DbTracker via the DbFactoryInterceptor. After a pruning cycle, the old inner DB is discarded but still held in the tracker — a stale reference. The solution is sound:

  1. FullPruningInnerDbFactory sets SkipMetricsTracking = true on all inner DB settings so the interceptor never registers them.
  2. WorldStateModule manually registers the outer FullPruningDb wrapper once with a stable name. Since FullPruningDb.GatherMetric() delegates to _currentDb.GatherMetric(), the tracker always reads from whatever inner DB is currently active — automatically correct across pruning cycles.
  3. The DbFactoryInterceptor correctly gates on !dbSettings.SkipMetricsTracking for both CreateDb and CreateColumnsDb.

The propagation through DbSettings.Clone() is safe: MemberwiseClone copies the field, then GetRocksDbSettings explicitly overwrites it to true after cloning.


Findings

Severity Count
Critical 0
High 0
Medium 0
Low 3

Low — SkipMetricsTracking lacks XML docs (DbSettings.cs:15)
The coding style guide requires <summary> on all public APIs. The semantics here are non-obvious (callers don't know what it affects), so a one-liner doc would help. Other properties in the same class are also undocumented, so this is consistent with the existing pattern.

Low — TryAdd silently drops duplicate registrations (WorldStateModule.cs:45)
Not a production issue (singletons aren't recreated), but worth being aware of in test teardown/rebuild scenarios.

Low — No end-to-end regression test for the stale-reference bug (DbTrackerTests.cs:81)
TestSkipMetricsTracking validates the mechanism, but there's no test that exercises the full scenario: create FullPruningDb → trigger pruning cycle via TryStartPruning/Commit → assert tracker still reads from the new inner DB. The unit test is sufficient to merge, but an integration test would give stronger confidence.


Verdict: ready to merge. All findings are low-severity and none block correctness.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a SkipMetricsTracking flag to DbSettings and updates DB monitoring to avoid tracking ephemeral inner DB instances created during full pruning, preventing stale references and improving resilience when metric gathering fails.

Changes:

  • Add DbSettings.SkipMetricsTracking and honor it in DbMonitoringModule’s DB factory interceptor.
  • Mark full-pruning inner DB instances as skipped, and register the stable FullPruningDb wrapper with the tracker.
  • Add unit tests for skip-tracking behavior and for per-DB metric gather exception isolation.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Nethermind/Nethermind.Init/Modules/WorldStateModule.cs Registers the FullPruningDb wrapper in the tracker to keep metrics tied to the active inner DB across prune cycles.
src/Nethermind/Nethermind.Init/Modules/DbMonitoringModule.cs Skips tracking based on SkipMetricsTracking and makes metric updates resilient to per-DB exceptions.
src/Nethermind/Nethermind.Db/FullPruning/FullPruningInnerDbFactory.cs Sets SkipMetricsTracking = true for indexed inner DB instances.
src/Nethermind/Nethermind.Db/DbSettings.cs Introduces the SkipMetricsTracking property.
src/Nethermind/Nethermind.Db.Test/Nethermind.Db.Test.csproj Adds test dependency on Nethermind.Init to access DbMonitoringModule/tracker types.
src/Nethermind/Nethermind.Db.Test/DbTrackerTests.cs Adds tests for skip-tracking and exception isolation during metrics update.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +43 to +44
// inner DB, even across full-pruning cycles. Inner DBs are excluded from tracking
// via SkipMetricsTracking (set by FullPruningInnerDbFactory) to avoid stale entries.
Comment on lines +87 to +101
try
{
// Note: At the moment, the metric for a columns db is combined across column.
IDbMeta.DbMetric dbMetric = kv.Value.GatherMetric();
Db.Metrics.DbSize[kv.Key] = dbMetric.Size;
Db.Metrics.DbBlockCacheSize[kv.Key] = dbMetric.CacheSize;
Db.Metrics.DbMemtableSize[kv.Key] = dbMetric.MemtableSize;
Db.Metrics.DbIndexFilterSize[kv.Key] = dbMetric.IndexSize;
Db.Metrics.DbReads[kv.Key] = dbMetric.TotalReads;
Db.Metrics.DbWrites[kv.Key] = dbMetric.TotalWrites;
}
catch (Exception e)
{
if (_logger.IsWarn) _logger.Warn($"Failed to gather metrics for DB '{kv.Key}': {e}");
}
Comment on lines +139 to +144
Metrics.DbReads["GoodDb"] = 0;

updateAction!();

Assert.That(Metrics.DbReads.ContainsKey("GoodDb"), Is.True);
Assert.That(Metrics.DbReads["GoodDb"], Is.EqualTo(42));
Comment on lines +103 to +104
tracker.GetAllDbMeta().Count().Should().Be(1);
tracker.GetAllDbMeta().First().Key.Should().Be("TrackedDb");

public bool DeleteOnStart { get; set; }
public bool CanDeleteFolder { get; set; } = true;
public bool SkipMetricsTracking { get; set; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: Missing XML documentation on this public property. The coding style guide (coding-style.md) requires <summary> docs on all public APIs. Consider:

Suggested change
public bool SkipMetricsTracking { get; set; }
/// <summary>When true, this database will not be registered with the metrics tracker.</summary>
public bool SkipMetricsTracking { get; set; }

(Other properties in this file are also undocumented — consistent with the existing pattern, but worth fixing here since this one has non-obvious semantics.)

// Register the outer wrapper so GatherMetric() always reflects the currently active
// inner DB, even across full-pruning cycles. Inner DBs are excluded from tracking
// via SkipMetricsTracking (set by FullPruningInnerDbFactory) to avoid stale entries.
ctx.ResolveOptional<DbMonitoringModule.DbTracker>()?.AddDb(stateDbSettings.DbName, db);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: AddDb uses TryAdd internally, which silently discards duplicate names. If this lambda ever re-runs (unlikely for a singleton, but possible in test teardown/rebuild cycles), the stale FullPruningDb instance remains in the tracker. Not a problem in practice, but worth noting if the FullPruningDb instance is ever recreated under the same name.

}

[Test]
public void TestSkipMetricsTracking()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: This test verifies the SkipMetricsTracking flag mechanism, but there's no test for the actual bug scenario: create a FullPruningDb, trigger a pruning cycle (via TryStartPruningCommit), then assert that the tracker's GatherMetric() reads from the new inner DB and not the discarded one. The unit test is good, but an integration test would close the loop on correctness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants