Skip to content

Commit

Permalink
Acquire lock before incrementing orc.nextTxnTs (dgraph-io#806)
Browse files Browse the repository at this point in the history
* Acquire lock before incrementing orc.nextTxnTs

Incrementing the value of db.orc.nextTxnTs without acquiring lock causes race condition.
See https://teamcity.dgraph.io/viewLog.html?buildId=11417&buildTypeId=Badger_UnitTests logs
  • Loading branch information
Ibrahim Jarif authored May 9, 2019
1 parent 50bef1d commit 3374ec2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func Open(opt Options) (db *DB, err error) {
// In normal mode, we must update readMark so older versions of keys can be removed during
// compaction when run in offline mode via the flatten tool.
db.orc.readMark.Done(db.orc.nextTxnTs)
db.orc.nextTxnTs++
db.orc.incrementNextTs()

db.writeCh = make(chan *request, kvWriteChCapacity)
db.closers.writes = y.NewCloser(1)
Expand Down
6 changes: 6 additions & 0 deletions txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ func (o *oracle) nextTs() uint64 {
return o.nextTxnTs
}

func (o *oracle) incrementNextTs() {
o.Lock()
defer o.Unlock()
o.nextTxnTs++
}

// Any deleted or invalid versions at or below ts would be discarded during
// compaction to reclaim disk space in LSM tree and thence value log.
func (o *oracle) setDiscardTs(ts uint64) {
Expand Down

0 comments on commit 3374ec2

Please sign in to comment.