Skip to content

Commit

Permalink
Fix race condition in flushDiscardStats function (#921)
Browse files Browse the repository at this point in the history
A couple of builds failed on teamcity with data race error.
See https://teamcity.dgraph.io/viewLog.html?buildId=16131

This PR fixes the data race in `flushDiscardStats` function.
  • Loading branch information
Ibrahim Jarif authored Jul 8, 2019
1 parent fc32e13 commit 5caab82
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -1396,9 +1396,13 @@ func (vlog *valueLog) updateDiscardStats(stats map[uint32]int64) error {

// flushDiscardStats inserts discard stats into badger. Returns error on failure.
func (vlog *valueLog) flushDiscardStats() error {
vlog.lfDiscardStats.Lock()
if len(vlog.lfDiscardStats.m) == 0 {
vlog.lfDiscardStats.Unlock()
return nil
}
vlog.lfDiscardStats.Unlock()

entries := []*Entry{{
Key: y.KeyWithTs(lfDiscardStatsKey, 1),
Value: vlog.encodedDiscardStats(),
Expand Down

0 comments on commit 5caab82

Please sign in to comment.