Skip to content

Commit 02a7c0a

Browse files
committed
save
1 parent 762c456 commit 02a7c0a

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

db/kv/kv_interface.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,6 @@ type DBGauges struct { // these gauges are shared by all MDBX instances, but nee
603603
GcLeafMetric *metrics.GaugeVec
604604
GcOverflowMetric *metrics.GaugeVec
605605
GcPagesMetric *metrics.GaugeVec
606-
607-
GCMaxRetainedPages *metrics.GaugeVec
608-
GCMaxReaderLag *metrics.GaugeVec
609606
}
610607

611608
type DBSummaries struct { // the summaries are particular to a DB instance
@@ -616,6 +613,11 @@ type DBSummaries struct { // the summaries are particular to a DB instance
616613
DbCommitTotal metrics.Summary
617614
}
618615

616+
type GCSummaries struct { // GC metric summaries for each DB instance
617+
GCMaxRetainedPages metrics.Summary
618+
GCMaxReaderLag metrics.Summary
619+
}
620+
619621
// InitMDBXMGauges this only needs to be called once during startup
620622
func InitMDBXMGauges() *DBGauges {
621623
return &DBGauges{
@@ -638,9 +640,6 @@ func InitMDBXMGauges() *DBGauges {
638640
GcLeafMetric: metrics.GetOrCreateGaugeVec(`db_gc_leaf`, []string{dbLabelName}),
639641
GcOverflowMetric: metrics.GetOrCreateGaugeVec(`db_gc_overflow`, []string{dbLabelName}),
640642
GcPagesMetric: metrics.GetOrCreateGaugeVec(`db_gc_pages`, []string{dbLabelName}),
641-
642-
GCMaxRetainedPages: metrics.GetOrCreateGaugeVec(`db_gc_max_retained_pages`, []string{dbLabelName}),
643-
GCMaxReaderLag: metrics.GetOrCreateGaugeVec(`db_gc_max_reader_lag`, []string{dbLabelName}),
644643
}
645644
}
646645

@@ -658,8 +657,20 @@ func InitSummaries(dbLabel Label) {
658657
}
659658
}
660659

660+
func InitGCSummaries(dbLabel Label) {
661+
_, ok := MDBXGCSummaries.Load(dbLabel)
662+
if !ok {
663+
dbName := string(dbLabel)
664+
MDBXGCSummaries.Store(dbName, &GCSummaries{
665+
GCMaxRetainedPages: metrics.GetOrCreateSummaryWithLabels(`db_gc_max_retained_pages`, []string{dbLabelName}, []string{dbName}),
666+
GCMaxReaderLag: metrics.GetOrCreateSummaryWithLabels(`db_gc_max_reader_lag`, []string{dbLabelName}, []string{dbName}),
667+
})
668+
}
669+
}
670+
661671
var MDBXGauges = InitMDBXMGauges() // global mdbx gauges. each gauge can be filtered by db name
662672
var MDBXSummaries sync.Map // dbName => Summaries mapping
673+
var MDBXGCSummaries sync.Map // dbName => GCSummaries mapping
663674

664675
var (
665676
ErrAttemptToDeleteNonDeprecatedBucket = errors.New("only buckets from dbutils.ChaindataDeprecatedTables can be deleted")

db/kv/mdbx/kv_mdbx.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func (opts MdbxOpts) Open(ctx context.Context) (kv.RwDB, error) {
192192

193193
if opts.metrics {
194194
kv.InitSummaries(opts.label)
195+
kv.InitGCSummaries(opts.label)
195196
}
196197
if opts.HasFlag(mdbx.Accede) || opts.HasFlag(mdbx.Readonly) {
197198
for retry := 0; ; retry++ {
@@ -1025,10 +1026,21 @@ func (tx *MdbxTx) Commit() error {
10251026
tx.db.opts.log.Error("failed to record mdbx summaries", "err", err)
10261027
}
10271028

1028-
kv.MDBXGauges.GCMaxRetainedPages.WithLabelValues(string(dbLabel)).SetUint64(uint64(latency.GCDetails.MaxRetainedPages))
1029-
kv.MDBXGauges.GCMaxReaderLag.WithLabelValues(string(dbLabel)).SetUint64(uint64(latency.GCDetails.MaxReaderLag))
1029+
// Record GC stats as Summary metrics to capture spike distribution
1030+
// Summary naturally aggregates all observations over time windows, showing when spikes happened
1031+
pages := float64(latency.GCDetails.MaxRetainedPages)
1032+
lag := float64(latency.GCDetails.MaxReaderLag)
1033+
1034+
// Get GC summaries for this DB instance
1035+
gcSummariesIface, ok := kv.MDBXGCSummaries.Load(string(dbLabel))
1036+
if ok {
1037+
gcSummaries := gcSummariesIface.(*kv.GCSummaries)
1038+
gcSummaries.GCMaxRetainedPages.Observe(pages)
1039+
gcSummaries.GCMaxReaderLag.Observe(lag)
1040+
}
1041+
10301042
if latency.GCDetails.MaxRetainedPages > 0 || latency.GCDetails.MaxReaderLag > 0 {
1031-
log.Warn("[dbg] latency.GCDetails", "MaxRetainedPages", latency.GCDetails.MaxRetainedPages, "MaxRetainedPages", latency.GCDetails.MaxRetainedPages)
1043+
log.Warn("[dbg] latency.GCDetails", "MaxRetainedPages", latency.GCDetails.MaxRetainedPages, "MaxReaderLag", latency.GCDetails.MaxReaderLag)
10321044
}
10331045

10341046
//kv.DbGcWorkPnlMergeTime.Update(latency.GCDetails.WorkPnlMergeTime.Seconds())

0 commit comments

Comments
 (0)