From c04705364663e7141d39764fce8fd1dc1a4633ab Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Thu, 24 Oct 2019 14:19:13 +0300 Subject: [PATCH] - querylog: writing to a file could stop randomly --- querylog/querylog_file.go | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/querylog/querylog_file.go b/querylog/querylog_file.go index 1a6c4481..46046852 100644 --- a/querylog/querylog_file.go +++ b/querylog/querylog_file.go @@ -4,13 +4,11 @@ import ( "bytes" "compress/gzip" "encoding/json" - "fmt" "io" "os" "time" "github.com/AdguardTeam/golibs/log" - "github.com/go-test/deep" ) const enableGzip = false @@ -61,12 +59,7 @@ func (l *queryLog) flushToFile(buffer []*logEntry) error { elapsed := time.Since(start) log.Debug("%d elements serialized via json in %v: %d kB, %v/entry, %v/entry", len(buffer), elapsed, b.Len()/1024, float64(b.Len())/float64(len(buffer)), elapsed/time.Duration(len(buffer))) - err := checkBuffer(buffer, b) - if err != nil { - log.Error("failed to check buffer: %s", err) - return err - } - + var err error var zb bytes.Buffer filename := l.logFile @@ -113,34 +106,6 @@ func (l *queryLog) flushToFile(buffer []*logEntry) error { return nil } -func checkBuffer(buffer []*logEntry, b bytes.Buffer) error { - l := len(buffer) - d := json.NewDecoder(&b) - - i := 0 - for d.More() { - entry := &logEntry{} - err := d.Decode(entry) - if err != nil { - log.Error("Failed to decode: %s", err) - return err - } - if diff := deep.Equal(entry, buffer[i]); diff != nil { - log.Error("decoded buffer differs: %s", diff) - return fmt.Errorf("decoded buffer differs: %s", diff) - } - i++ - } - if i != l { - err := fmt.Errorf("check fail: %d vs %d entries", l, i) - log.Error("%v", err) - return err - } - log.Debug("check ok: %d entries", i) - - return nil -} - func (l *queryLog) rotate() error { from := l.logFile to := l.logFile + ".1"