Pull request: querylog: use better error signaling
Merge in DNS/adguard-home from 2325-querylog-suffering to master Closes #2325. Squashed commit of the following: commit 90388050ed495286cdfed6574dd438abd4a33baa Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Nov 19 12:37:00 2020 +0300 all: changelog commit bbdeabbb550c7e98f579e2a68c71de7a66624203 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Nov 19 12:33:21 2020 +0300 querylog: improve error reporting commit 807b23aa74d0e39f5ef51910e5b91c9b95a8c341 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Nov 18 19:39:22 2020 +0300 querylog: improve docs commit 65a8f4f3323192c872b3389d2b3420e072a01297 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Nov 18 19:36:28 2020 +0300 querylog: use better error signaling
This commit is contained in:
@@ -51,16 +51,26 @@ 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) (err error) {
|
||||
for i, q := range r.qFiles {
|
||||
for i := len(r.qFiles) - 1; i >= 0; i-- {
|
||||
q := r.qFiles[i]
|
||||
_, _, 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) {
|
||||
|
||||
return nil
|
||||
} else if errors.Is(err, ErrTSTooEarly) {
|
||||
// Look at the next file, since we've reached the end of
|
||||
// this one.
|
||||
continue
|
||||
} else if errors.Is(err, ErrTSTooLate) {
|
||||
// Just seek to the start then. timestamp is probably
|
||||
// between the end of the previous one and the start of
|
||||
// this one.
|
||||
return r.SeekStart()
|
||||
} else if errors.Is(err, ErrTSNotFound) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user