Skip to content

Commit

Permalink
Merge: -(dnsforward): fixing an issue with the querylog speed
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 7db062d
Author: Andrey Meshkov <[email protected]>
Date:   Thu Feb 27 12:08:58 2020 +0300

    *(dnsforward): added comment about oldest

commit dbec84d
Author: Simon Zolin <[email protected]>
Date:   Thu Feb 27 11:16:58 2020 +0300

    fix

commit d6df1ee
Author: Andrey Meshkov <[email protected]>
Date:   Wed Feb 26 20:42:11 2020 +0300

    -(dnsforward): fixing an issue with the querylog speed
  • Loading branch information
ameshkov committed Feb 27, 2020
1 parent d839136 commit f84331a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
10 changes: 7 additions & 3 deletions querylog/qlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ func (l *queryLog) getData(params getDataParams) map[string]interface{} {
// remove extra records
entries = entries[(len(entries) - getDataLimit):]
}
if len(entries) == getDataLimit {
// change the "oldest" value here.
// we cannot use the "oldest" we got from "searchFiles" anymore
// because after adding in-memory records and removing extra records
// the situation has changed
oldest = entries[len(entries)-1].Time
}

// init the response object
var data = []map[string]interface{}{}
Expand All @@ -246,9 +253,6 @@ func (l *queryLog) getData(params getDataParams) map[string]interface{} {
len(entries), total, params.OlderThan, time.Since(now))

var result = map[string]interface{}{}
if len(entries) == getDataLimit {
oldest = entries[0].Time
}
result["oldest"] = ""
if !oldest.IsZero() {
result["oldest"] = oldest.Format(time.RFC3339Nano)
Expand Down
18 changes: 14 additions & 4 deletions querylog/querylog_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ func (l *queryLog) searchFiles(params getDataParams) ([]*logEntry, time.Time, in
err = r.SeekStart()
} else {
err = r.Seek(params.OlderThan.UnixNano())
if err == nil {
// Read to the next record right away
// The one that was specified in the "oldest" param is not needed,
// we need only the one next to it
_, err = r.ReadNext()
}
}

if err != nil {
log.Error("Failed to Seek(): %v", err)
log.Debug("Cannot Seek() to %v: %v", params.OlderThan, err)
return entries, oldest, 0
}

Expand All @@ -54,12 +60,16 @@ func (l *queryLog) searchFiles(params getDataParams) ([]*logEntry, time.Time, in
break
}

oldestNano = ts
total++

if entry != nil {
entries = append(entries, entry)
if len(entries) == getDataLimit {
// Do not read more than "getDataLimit" records at once
break
}
}

oldestNano = ts
total++
}

oldest = time.Unix(0, oldestNano)
Expand Down

0 comments on commit f84331a

Please sign in to comment.