Skip to content

Commit

Permalink
stats: imp code, logging
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Aug 22, 2022
1 parent 09aa857 commit 34fc666
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ and this project adheres to
future release.
- Go 1.18 support. v0.109.0 will require at least Go 1.19 to build.

### Fixed

- Excessive logging of a non-critical statistics error ([#4850]).

[#2993]: https://github.com/AdguardTeam/AdGuardHome/issues/2993
[#4850]: https://github.com/AdguardTeam/AdGuardHome/issues/4850



Expand Down
27 changes: 15 additions & 12 deletions internal/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,35 +385,38 @@ func (s *StatsCtx) flush() (cont bool, sleepFor time.Duration) {
return true, 0
}

isCommitable := true
tx, err := db.Begin(true)
if err != nil {
log.Error("stats: opening transaction: %s", err)

return true, 0
}
defer func() {
if err = finishTxn(tx, isCommitable); err != nil {
log.Error("stats: warning: %s", err)
}
}()

s.curr = newUnit(id)
isCommitable := true

ferr := ptr.serialize().flushUnitToDB(tx, ptr.id)
if ferr != nil {
log.Error("stats: flushing unit: %s", ferr)
flushErr := ptr.serialize().flushUnitToDB(tx, ptr.id)
if flushErr != nil {
log.Error("stats: flushing unit: %s", flushErr)
isCommitable = false
}

derr := tx.DeleteBucket(idToUnitName(id - limit))
if derr != nil {
delErr := tx.DeleteBucket(idToUnitName(id - limit))
if delErr != nil {
logFunc := log.Error
if !errors.Is(derr, bbolt.ErrBucketNotFound) {
// TODO(e.burkov): Improve the algorithm of deleting the oldest bucket
// to avoid the error.
if !errors.Is(delErr, bbolt.ErrBucketNotFound) {
isCommitable = false
logFunc = log.Debug
}
logFunc("stats: deleting unit: %s", derr)
}

err = finishTxn(tx, isCommitable)
if err != nil {
log.Error("stats: %s", err)
logFunc("stats: warning: deleting unit: %s", delErr)
}

return true, 0
Expand Down

0 comments on commit 34fc666

Please sign in to comment.