Merge pull request #19420 from influxdata/fix-unlocked-map-access

fix: lock map before writes
pull/19631/head
David Norton 2020-09-22 11:28:46 -04:00 committed by GitHub
commit fb98ce63ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 4 deletions

View File

@ -1073,10 +1073,9 @@ func (f *LogFile) seriesSketches() (sketch, tSketch estimator.Sketch, err error)
return sketch, tSketch, nil
}
func (f *LogFile) Writes(entries []LogEntry) error {
f.mu.RLock()
defer f.mu.RUnlock()
func (f *LogFile) ExecEntries(entries []LogEntry) error {
f.mu.Lock()
defer f.mu.Unlock()
for i := range entries {
entry := &entries[i]
if err := f.appendEntry(entry); err != nil {
@ -1084,6 +1083,14 @@ func (f *LogFile) Writes(entries []LogEntry) error {
}
f.execEntry(entry)
}
return nil
}
func (f *LogFile) Writes(entries []LogEntry) error {
if err := f.ExecEntries(entries); err != nil {
return err
}
// Flush buffer and sync to disk.
return f.FlushAndSync()
}