Browse Source

[Fix] disable mmap for current datafile from #239 (#240)

Fix issues related to #239

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

Co-authored-by: jason3gb <jason3gb@gmail.com>
Reviewed-on: #240
Reviewed-by: James Mills <james@mills.io>
Reviewed-by: Tai Groot <tai@taigrr.com>
Co-authored-by: jason3gb <jason3gb@noreply@mills.io>
Co-committed-by: jason3gb <jason3gb@noreply@mills.io>
master
jason3gb 3 weeks ago
committed by James Mills
parent
commit
2c57c950f8
  1. 1
      AUTHORS
  2. 14
      internal/data/datafile.go

1
AUTHORS

@ -18,3 +18,4 @@ Yury Fedorov orlangure
o2gy84 <o2gy84@gmail.com>
garsue <labs.garsue@gmail.com>
biozz <ielfimov@gmail.com>
jason3gb <jason3gb@gmail.com>

14
internal/data/datafile.go

@ -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()
@ -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()
}()
@ -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)

Loading…
Cancel
Save