Skip to content

Commit

Permalink
Merge: - querylog: writing to a file could stop randomly
Browse files Browse the repository at this point in the history
Close #1115

* commit 'c04705364663e7141d39764fce8fd1dc1a4633ab':
  - querylog: writing to a file could stop randomly
  • Loading branch information
szolin committed Oct 24, 2019
2 parents 4164941 + c047053 commit b28582d
Showing 1 changed file with 1 addition and 36 deletions.
37 changes: 1 addition & 36 deletions querylog/querylog_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit b28582d

Please sign in to comment.