Skip to content

Commit

Permalink
Merge branch 'master' of github.com:shell909090/influx-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
shell909090 committed Feb 10, 2017
2 parents e9d7e80 + dfe0f42 commit b64e337
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions backend/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package backend

import (
"bytes"
"compress/gzip"
"io"
"log"
"time"
Expand All @@ -24,7 +23,6 @@ type Backends struct {
ticker *time.Ticker
ch_write chan []byte
buffer *bytes.Buffer
zip *gzip.Writer
ch_timer <-chan time.Time
write_counter int32
rewriter_running bool
Expand Down Expand Up @@ -97,10 +95,9 @@ func (bs *Backends) WriteBuffer(p []byte) {

if bs.buffer == nil {
bs.buffer = &bytes.Buffer{}
bs.zip = gzip.NewWriter(bs.buffer)
}

n, err := bs.zip.Write(p)
n, err := bs.buffer.Write(p)
if err != nil {
log.Printf("error: %s\n", err)
return
Expand All @@ -112,7 +109,7 @@ func (bs *Backends) WriteBuffer(p []byte) {
}

if p[len(p)-1] != '\n' {
_, err = bs.zip.Write([]byte{'\n'})
_, err = bs.buffer.Write([]byte{'\n'})
if err != nil {
log.Printf("error: %s\n", err)
return
Expand All @@ -131,16 +128,8 @@ func (bs *Backends) Flush() {
return
}

err := bs.zip.Close()
if err != nil {
log.Printf("zip close error: %s\n", err)
return
}

p := bs.buffer.Bytes()
bs.buffer.Reset()
bs.buffer = nil
bs.zip = nil
bs.ch_timer = nil

if len(p) == 0 {
Expand All @@ -149,6 +138,15 @@ func (bs *Backends) Flush() {

// TODO: limitation
go func() {
var buf bytes.Buffer
err := Compress(&buf, p)
if err != nil {
log.Printf("write file error: %s\n", err)
return
}

p = buf.Bytes()

// maybe blocked here, run in another goroutine
if bs.HttpBackend.IsActive() {
err = bs.HttpBackend.WriteCompressed(p)
Expand Down

0 comments on commit b64e337

Please sign in to comment.