From df427b6822c843a233ec0cad48624d2b1de87843 Mon Sep 17 00:00:00 2001 From: Andrey Meshkov Date: Fri, 21 Feb 2020 16:50:20 +0300 Subject: [PATCH] *(dnsforward): fix reading in-memory entries --- querylog/qlog.go | 9 ++++++--- querylog/qlog_file.go | 6 +++++- querylog/querylog_file.go | 3 --- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/querylog/qlog.go b/querylog/qlog.go index fb49fa35..a0570011 100644 --- a/querylog/qlog.go +++ b/querylog/qlog.go @@ -208,14 +208,17 @@ func (l *queryLog) getData(params getDataParams) map[string]interface{} { memoryEntries := make([]*logEntry, 0) // go through the buffer in the reverse order + // from NEWER to OLDER for i := len(l.buffer) - 1; i >= 0; i-- { entry := l.buffer[i] - if !matchesGetDataParams(entry, params) { + + if entry.Time.UnixNano() >= params.OlderThan.UnixNano() { + // Ignore entries newer than what was requested continue } - if entry.Time.UnixNano() >= params.OlderThan.UnixNano() { - break + if !matchesGetDataParams(entry, params) { + continue } memoryEntries = append(memoryEntries, entry) diff --git a/querylog/qlog_file.go b/querylog/qlog_file.go index 54d1896c..c1eeefa2 100644 --- a/querylog/qlog_file.go +++ b/querylog/qlog_file.go @@ -15,7 +15,11 @@ import ( // if we failed to find the desired record var ErrSeekNotFound = errors.New("Seek not found the record") -const bufferSize = 256 * 1024 // 256 KB is the buffer size +// TODO: Find a way to grow buffer instead of relying on this value when reading strings +const maxEntrySize = 16 * 1024 + +// buffer should be enough for at least this number of entries +const bufferSize = 100 * maxEntrySize // QLogFile represents a single query log file // It allows reading from the file in the reverse order diff --git a/querylog/querylog_file.go b/querylog/querylog_file.go index 3b32b7a2..1eeeea7c 100644 --- a/querylog/querylog_file.go +++ b/querylog/querylog_file.go @@ -9,9 +9,6 @@ import ( "github.com/AdguardTeam/golibs/log" ) -// TODO: Check this when we append a new line -- we don't want to have a line longer than this -const maxEntrySize = 1024 - // flushLogBuffer flushes the current buffer to file and resets the current buffer func (l *queryLog) flushLogBuffer(fullFlush bool) error { l.fileFlushLock.Lock()