Skip to content

Commit

Permalink
Pull request: 4850 stats: imp logging
Browse files Browse the repository at this point in the history
Merge in DNS/adguard-home from 4850-imp-stats-logging to master

Updates AdguardTeam#4850.

Squashed commit of the following:

commit 3c1ee8d
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Aug 22 14:17:56 2022 +0300

    all: imp chlog

commit 0c7adc7
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Aug 22 14:12:01 2022 +0300

    stats: fix err check

commit d14a5ca
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Aug 22 14:09:15 2022 +0300

    stats: imp logging again

commit 34fc666
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Aug 22 12:49:43 2022 +0300

    stats: imp code, logging

commit 09aa857
Merge: 09a732a eccfbf6
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Fri Aug 19 19:43:45 2022 +0300

    Merge branch 'master' into 4850-imp-stats-logging

commit 09a732a
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Fri Aug 19 19:38:51 2022 +0300

    stats: imp logging
  • Loading branch information
EugeneOne1 authored and heyxkhoa committed Mar 17, 2023
1 parent 801c05b commit 69f158e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 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

- Unnecessary logging of non-critical statistics errors ([#4850]).

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



Expand Down
30 changes: 17 additions & 13 deletions internal/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,35 +385,39 @@ 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: %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 {
log.Error("stats: deleting unit: %s", derr)
if !errors.Is(derr, bbolt.ErrBucketNotFound) {
delErr := tx.DeleteBucket(idToUnitName(id - limit))
if delErr != nil {
// TODO(e.burkov): Improve the algorithm of deleting the oldest bucket
// to avoid the error.
if errors.Is(delErr, bbolt.ErrBucketNotFound) {
log.Debug("stats: warning: deleting unit: %s", delErr)
} else {
isCommitable = false
log.Error("stats: deleting unit: %s", delErr)
}
}

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

return true, 0
}

Expand Down

0 comments on commit 69f158e

Please sign in to comment.