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

chore: added extra logging in reserve worker for invalid batches #4384

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/storer/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type metrics struct {
LevelDBStats prometheus.HistogramVec
ExpiryTriggersCount prometheus.Counter
ExpiryRunsCount prometheus.Counter

Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary new line.

ReserveMissingBatch prometheus.Gauge
}

// newMetrics is a convenient constructor for creating new metrics.
Expand Down Expand Up @@ -64,6 +66,14 @@ func newMetrics() metrics {
Help: "Number of chunks in reserve.",
},
),
ReserveMissingBatch: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "reserve_missing_batch",
Help: "Number of chunks in reserve with missing batches.",
},
),
ReserveSizeWithinRadius: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: m.Namespace,
Expand Down
55 changes: 32 additions & 23 deletions pkg/storer/reserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,24 @@ func (db *DB) reserveSizeWithinRadiusWorker(ctx context.Context) {

for {
count := 0
err := db.reserve.IterateChunksItems(db.repo, db.StorageRadius(), func(ci reserve.ChunkItem) (bool, error) {
count++
missing := 0
radius := db.StorageRadius()
istae marked this conversation as resolved.
Show resolved Hide resolved
err := db.reserve.IterateChunksItems(db.repo, 0, func(ci reserve.ChunkItem) (bool, error) {
if ci.BinID >= uint64(radius) {
count++
}
if exists, _ := db.batchstore.Exists(ci.BatchID); !exists {
missing++
db.logger.Debug("reserve size worker, item with invalid batch id", "batch_id", hex.EncodeToString(ci.BatchID), "chunk_address", ci.ChunkAddress)
}
return false, nil
})
if err != nil {
db.logger.Error(err, "reserve count within radius")
}

db.metrics.ReserveSizeWithinRadius.Set(float64(count))
db.metrics.ReserveMissingBatch.Set(float64(missing))

select {
case <-ctx.Done():
Expand Down Expand Up @@ -237,27 +246,6 @@ func (db *DB) ReserveGet(ctx context.Context, addr swarm.Address, batchID []byte
return db.reserve.Get(ctx, db.repo, addr, batchID)
}

func (db *DB) StorageRadius() uint8 {
if db.reserve == nil {
return 0
}
return db.reserve.Radius()
}

func (db *DB) ReserveSize() int {
if db.reserve == nil {
return 0
}
return db.reserve.Size()
}

func (db *DB) IsWithinStorageRadius(addr swarm.Address) bool {
if db.reserve == nil {
return false
}
return swarm.Proximity(addr.Bytes(), db.baseAddr.Bytes()) >= db.reserve.Radius()
}

func (db *DB) ReserveHas(addr swarm.Address, batchID []byte) (has bool, err error) {
dur := captureDuration(time.Now())
defer func() {
Expand Down Expand Up @@ -445,6 +433,27 @@ func (db *DB) ReserveIterateChunks(cb func(swarm.Chunk) (bool, error)) error {
return db.reserve.IterateChunks(db.repo, 0, cb)
}

func (db *DB) StorageRadius() uint8 {
if db.reserve == nil {
return 0
}
return db.reserve.Radius()
}

func (db *DB) ReserveSize() int {
if db.reserve == nil {
return 0
}
return db.reserve.Size()
}

func (db *DB) IsWithinStorageRadius(addr swarm.Address) bool {
if db.reserve == nil {
return false
}
return swarm.Proximity(addr.Bytes(), db.baseAddr.Bytes()) >= db.reserve.Radius()
}

// BinC is the result returned from the SubscribeBin channel that contains the chunk address and the binID
type BinC struct {
Address swarm.Address
Expand Down