Skip to content

Commit

Permalink
leveldb: fix data race
Browse files Browse the repository at this point in the history
  • Loading branch information
syndtr committed Aug 24, 2016
1 parent e2d6dc9 commit e5ce663
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions leveldb/db_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ func (db *DB) sampleSeek(ikey internalKey) {
}

func (db *DB) mpoolPut(mem *memdb.DB) {
defer func() {
recover()
}()
select {
case db.memPool <- mem:
default:
if !db.isClosed() {
select {
case db.memPool <- mem:
default:
}
}
}

Expand Down Expand Up @@ -101,6 +100,12 @@ func (db *DB) mpoolDrain() {
default:
}
case _, _ = <-db.closeC:
ticker.Stop()
// Make sure the pool is drained.
select {
case <-db.memPool:
case <-time.After(time.Second):
}
close(db.memPool)
return
}
Expand Down
2 changes: 1 addition & 1 deletion leveldb/table/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ func (r *Reader) Find(key []byte, filtered bool, ro *opt.ReadOptions) (rkey, val
return r.find(key, filtered, ro, false)
}

// Find finds key that is greater than or equal to the given key.
// FindKey finds key that is greater than or equal to the given key.
// It returns ErrNotFound if the table doesn't contain such key.
// If filtered is true then the nearest 'block' will be checked against
// 'filter data' (if present) and will immediately return ErrNotFound if
Expand Down

0 comments on commit e5ce663

Please sign in to comment.