Skip to content

Commit

Permalink
Making flc thread safe with mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
deniszh committed Jun 13, 2024
1 parent c98fd5d commit 8f6c91c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion carbonserver/flc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"os"
"strings"
"sync"
)

// file list cache
Expand Down Expand Up @@ -82,6 +83,7 @@ type fileListCacheCommon struct {
path string
mode byte
file *os.File
mutex sync.Mutex
reader *gzip.Reader
writer *gzip.Writer
}
Expand Down Expand Up @@ -237,6 +239,8 @@ func newFileListCacheV1ReadOnly(flcc *fileListCacheCommon) *fileListCacheV1 {
}

func (flc *fileListCacheV1) Write(entry *FLCEntry) error {
flc.mutex.Lock()
defer flc.mutex.Unlock()
_, err := flc.writer.Write([]byte(entry.Path + "\n"))
return err
}
Expand Down Expand Up @@ -299,7 +303,9 @@ func (flc *fileListCacheV2) Write(entry *FLCEntry) error {
offset += flcv2StatFieldSize

buf[offset] = '\n'


flc.mutex.Lock()
defer flc.mutex.Unlock()
_, err := flc.writer.Write(buf)

return err
Expand Down

0 comments on commit 8f6c91c

Please sign in to comment.