Skip to content

Commit

Permalink
Fix race condition in L0StallMs variable (#1605)
Browse files Browse the repository at this point in the history
This fixes two issues
- Atomic variable was not being accessed correctly
- Atomic variable should be the first member of the struct to ensure proper alignment.
   Failure to do so will cause a segmentation fault.

Fixes DGRAPH-2773
  • Loading branch information
Ibrahim Jarif authored Nov 25, 2020
1 parent f36daf5 commit 925e15b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func (db *DB) IsClosed() bool {

func (db *DB) close() (err error) {
db.opt.Debugf("Closing database")
db.opt.Infof("Lifetime L0 stalled for: %s\n", time.Duration(db.lc.l0stallsMs))
db.opt.Infof("Lifetime L0 stalled for: %s\n", time.Duration(atomic.LoadInt64(&db.lc.l0stallsMs)))

atomic.StoreInt32(&db.blockWrites, 1)

Expand Down
4 changes: 2 additions & 2 deletions levels.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ import (

type levelsController struct {
nextFileID uint64 // Atomic
l0stallsMs int64 // Atomic

// The following are initialized once and const.
levels []*levelHandler
kv *DB

cstatus compactStatus
l0stallsMs int64
cstatus compactStatus
}

// revertToManifest checks that all necessary table files exist and removes all table files not
Expand Down

0 comments on commit 925e15b

Please sign in to comment.