Pull request: querylog bug fix
Merge in DNS/adguard-home from 2324-querylog-bug-fix to master
Closes #2324.
Squashed commit of the following:
commit fdd584a218e1edc3e45ab5b00ceed0a3be681e32
Merge: 8103f9e42 f2eda6d19
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Wed Nov 18 15:35:42 2020 +0300
Merge branch 'master' into 2324-querylog-bug-fix
commit 8103f9e42a398f43682ee30d09b3afdab0e9e177
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Wed Nov 18 14:28:29 2020 +0300
querylog: fix the file ordering bug
commit 2c4e8fcc5b8593be1614480508dfd600fc676e64
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Nov 17 20:57:45 2020 +0300
querylog: wrap errors to clarify error trace
commit 3733062b494817696e4443f153774bb01cea1b06
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Nov 17 18:55:17 2020 +0300
querylog: fix logger output bug
This commit is contained in:
@@ -2,6 +2,7 @@ package querylog
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/agherr"
|
||||
@@ -49,22 +50,22 @@ func NewQLogReader(files []string) (*QLogReader, error) {
|
||||
//
|
||||
// Returns nil if the record is successfully found.
|
||||
// Returns an error if for some reason we could not find a record with the specified timestamp.
|
||||
func (r *QLogReader) Seek(timestamp int64) error {
|
||||
for i := len(r.qFiles) - 1; i >= 0; i-- {
|
||||
q := r.qFiles[i]
|
||||
_, _, err := q.Seek(timestamp)
|
||||
if err == nil || errors.Is(err, ErrEndOfLog) {
|
||||
// Our search is finished, and we either found the
|
||||
// element we were looking for or reached the end of the
|
||||
// log. Update currentFile only, position is already
|
||||
// set properly in QLogFile.
|
||||
func (r *QLogReader) Seek(timestamp int64) (err error) {
|
||||
for i, q := range r.qFiles {
|
||||
_, _, err = q.Seek(timestamp)
|
||||
if err == nil {
|
||||
// Search is finished, and the searched element have
|
||||
// been found. Update currentFile only, position is
|
||||
// already set properly in QLogFile.
|
||||
r.currentFile = i
|
||||
|
||||
return err
|
||||
}
|
||||
if errors.Is(err, ErrSeekNotFound) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return ErrSeekNotFound
|
||||
return fmt.Errorf("querylog: %w", err)
|
||||
}
|
||||
|
||||
// SeekStart changes the current position to the end of the newest file
|
||||
|
||||
Reference in New Issue
Block a user