Skip to content

Commit

Permalink
Fix race condition in updateDiscardStats (#973)
Browse files Browse the repository at this point in the history
The TestGetMore test fails with race condition in updateDiscardStats
function.
See https://teamcity.dgraph.io/viewLog.html?buildId=19032&buildTypeId=Badger_UnitTests
  • Loading branch information
Ibrahim Jarif authored Aug 9, 2019
1 parent 2efdc3b commit 0283a03
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion value.go
Original file line number Diff line number Diff line change
Expand Up @@ -1384,11 +1384,12 @@ func (vlog *valueLog) runGC(discardRatio float64, head valuePointer) error {

func (vlog *valueLog) updateDiscardStats(stats map[uint32]int64) error {
vlog.lfDiscardStats.Lock()
defer vlog.lfDiscardStats.Unlock()

for fid, sz := range stats {
vlog.lfDiscardStats.m[fid] += sz
vlog.lfDiscardStats.updatesSinceFlush++
}
vlog.lfDiscardStats.Unlock()
if vlog.lfDiscardStats.updatesSinceFlush > discardStatsFlushThreshold {
if err := vlog.flushDiscardStats(); err != nil {
return err
Expand Down

0 comments on commit 0283a03

Please sign in to comment.