From 96c09bc5b1334c5c0270eb51898aa4a360399ca7 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Sun, 12 Nov 2023 13:52:44 +0100 Subject: [PATCH] Print badger4 levels information every minute (debug) --- go.mod | 2 +- go.sum | 4 ++-- setup.go | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index e7bd7c3..635463a 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/ipfs/boxo v0.15.0 github.com/ipfs/go-cid v0.4.1 github.com/ipfs/go-datastore v0.6.0 - github.com/ipfs/go-ds-badger4 v0.0.0-20231006150127-9137bcc6b981 + github.com/ipfs/go-ds-badger4 v0.0.0-20231112124819-05b485a62f58 github.com/ipfs/go-ipfs-delay v0.0.1 github.com/ipfs/go-log/v2 v2.5.1 github.com/ipfs/go-metrics-interface v0.0.1 diff --git a/go.sum b/go.sum index b569749..532b267 100644 --- a/go.sum +++ b/go.sum @@ -311,8 +311,8 @@ github.com/ipfs/go-datastore v0.6.0/go.mod h1:rt5M3nNbSO/8q1t4LNkLyUwRs8HupMeN/8 github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= github.com/ipfs/go-ds-badger v0.0.7/go.mod h1:qt0/fWzZDoPW6jpQeqUjR5kBfhDNB65jd9YlmAvpQBk= -github.com/ipfs/go-ds-badger4 v0.0.0-20231006150127-9137bcc6b981 h1:GOKV62VnjerKwO7mwOyeoArzlaVrDLyoC/YPNtxxGwg= -github.com/ipfs/go-ds-badger4 v0.0.0-20231006150127-9137bcc6b981/go.mod h1:LUU2FbhNdmhAbJmMeoahVRbe4GsduAODSJHWJJh2Vo4= +github.com/ipfs/go-ds-badger4 v0.0.0-20231112124819-05b485a62f58 h1:+bldY2lXKGbuKMc2x2WxNAA9PbAGsb5GF7MkJql2OzY= +github.com/ipfs/go-ds-badger4 v0.0.0-20231112124819-05b485a62f58/go.mod h1:LUU2FbhNdmhAbJmMeoahVRbe4GsduAODSJHWJJh2Vo4= github.com/ipfs/go-ds-leveldb v0.1.0/go.mod h1:hqAW8y4bwX5LWcCtku2rFNX3vjDZCy5LZCg+cSZvYb8= github.com/ipfs/go-ipfs-blockstore v1.3.0 h1:m2EXaWgwTzAfsmt5UdJ7Is6l4gJcaM/A12XwJyvYvMM= github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IWFJMcGIPQ= diff --git a/setup.go b/setup.go index 02c32c8..5f3ae66 100644 --- a/setup.go +++ b/setup.go @@ -407,7 +407,21 @@ func setupDatastore(cfg Config) (datastore.Batching, error) { Options: badgerOpts, } - return badger4.NewDatastore(filepath.Join(cfg.DataDir, "badger4"), &opts) + ds, err := badger4.NewDatastore(filepath.Join(cfg.DataDir, "badger4"), &opts) + if err != nil { + return nil, err + } + + // Print level information every minute on debug + go func() { + ticker := time.NewTicker(time.Minute) + defer ticker.Stop() + for { + <-ticker.C + ds.DiskUsage(context.Background()) + } + }() + return ds, nil } type bundledDHT struct {