Skip to content

Commit

Permalink
binarylog: Use a simple boolean rather than a sync.Once (#4581)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jille committed Jul 14, 2021
1 parent ba41bba commit bfe1d0d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions internal/binarylog/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,24 @@ func (ws *writerSink) Write(e *pb.GrpcLogEntry) error {
func (ws *writerSink) Close() error { return nil }

type bufferedSink struct {
mu sync.Mutex
closer io.Closer
out Sink // out is built on buf.
buf *bufio.Writer // buf is kept for flush.

writeStartOnce sync.Once
writeTicker *time.Ticker
done chan struct{}
mu sync.Mutex
closer io.Closer
out Sink // out is built on buf.
buf *bufio.Writer // buf is kept for flush.
flusherStarted bool

writeTicker *time.Ticker
done chan struct{}
}

func (fs *bufferedSink) Write(e *pb.GrpcLogEntry) error {
// Start the write loop when Write is called.
fs.writeStartOnce.Do(fs.startFlushGoroutine)
fs.mu.Lock()
defer fs.mu.Unlock()
if !fs.flusherStarted {
// Start the write loop when Write is called.
fs.startFlushGoroutine()
fs.flusherStarted = true
}
if err := fs.out.Write(e); err != nil {
return err
}
Expand Down

0 comments on commit bfe1d0d

Please sign in to comment.