Skip to content

Commit

Permalink
[Fix] disable mmap for current datafile from #239 (#240)
Browse files Browse the repository at this point in the history
Fix issues related to #239

Disable mmap reader for current datafile, which only read from the fd.

Co-authored-by: jason3gb <[email protected]>
Reviewed-on: https://git.mills.io/prologic/bitcask/pulls/240
Reviewed-by: James Mills <[email protected]>
Reviewed-by: Tai Groot <[email protected]>
Co-authored-by: jason3gb <jason3gb@[email protected]>
Co-committed-by: jason3gb <jason3gb@[email protected]>
  • Loading branch information
2 people authored and James Mills committed Sep 25, 2021
1 parent 21a824e commit 2c57c95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ Yury Fedorov orlangure
o2gy84 <[email protected]>
garsue <[email protected]>
biozz <[email protected]>
jason3gb <[email protected]>
14 changes: 9 additions & 5 deletions internal/data/datafile.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ func NewDatafile(path string, id int, readonly bool, maxKeySize uint32, maxValue
return nil, errors.Wrap(err, "error calling Stat()")
}

ra, err = mmap.Open(fn)
if err != nil {
return nil, err
if readonly {
ra, err = mmap.Open(fn)
if err != nil {
return nil, err
}
}

offset := stat.Size()
Expand Down Expand Up @@ -107,7 +109,9 @@ func (df *datafile) Name() string {

func (df *datafile) Close() error {
defer func() {
df.ra.Close()
if df.ra != nil {
df.ra.Close()
}
df.r.Close()
}()

Expand Down Expand Up @@ -155,7 +159,7 @@ func (df *datafile) ReadAt(index, size int64) (e internal.Entry, err error) {

b := make([]byte, size)

if df.w == nil {
if df.ra != nil {
n, err = df.ra.ReadAt(b, index)
} else {
n, err = df.r.ReadAt(b, index)
Expand Down

0 comments on commit 2c57c95

Please sign in to comment.