Skip to content

Commit

Permalink
Merge pull request #250 from ByteStorage/develop
Browse files Browse the repository at this point in the history
bug: modify library with mmap
  • Loading branch information
sjcsjc123 authored Jul 27, 2023
2 parents 528e4a4 + 780d283 commit 4eeb2d8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
4 changes: 3 additions & 1 deletion cluster/store/store_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package store

import "testing"
import (
"testing"
)

func TestStore_GetRegionByID(t *testing.T) {
}
20 changes: 9 additions & 11 deletions engine/fileio/mmap_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package fileio

import (
"errors"
"github.com/edsrzf/mmap-go"
"os"
"syscall"
"unsafe"
)

type MMapIO struct {
fd *os.File // system file descriptor
data []byte // the mapping area corresponding to the file
dirty bool // has changed
offset int64 // next write location
fileSize int64 // max file size
fd *os.File // system file descriptor
data mmap.MMap // the mapping area corresponding to the file
dirty bool // has changed
offset int64 // next write location
fileSize int64 // max file size
}

// NewMMapIOManager Initialize Mmap IO
Expand All @@ -35,7 +34,7 @@ func NewMMapIOManager(fileName string, fileSize int64) (*MMapIO, error) {
}

// Building mappings between memory and disk files
b, err := syscall.Mmap(int(fd.Fd()), 0, int(fileSize), syscall.PROT_WRITE|syscall.PROT_READ, syscall.MAP_SHARED)
b, err := mmap.Map(fd, mmap.RDWR, 0)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -70,8 +69,7 @@ func (mio *MMapIO) Sync() error {
return nil
}

_, _, err := syscall.Syscall(syscall.SYS_MSYNC, uintptr(unsafe.Pointer(&mio.data[0])), uintptr(mio.offset), uintptr(syscall.MS_SYNC))
if err != 0 {
if err := mio.data.Flush(); err != nil {
return err
}

Expand Down Expand Up @@ -103,7 +101,7 @@ func (mio *MMapIO) UnMap() error {
if mio.data == nil {
return nil
}
err := syscall.Munmap(mio.data)
err := mio.data.Unmap()
mio.data = nil
return err
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/desertbit/columnize v2.1.0+incompatible // indirect
github.com/desertbit/go-shlex v0.1.1 // indirect
github.com/desertbit/readline v1.5.1 // indirect
github.com/edsrzf/mmap-go v1.1.0 // indirect
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c // indirect
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ github.com/desertbit/grumble v1.1.3 h1:gbdgVGWsHmNraJ7Gn6Q4TiUEIHU/UHfbc1KUSbBlg
github.com/desertbit/grumble v1.1.3/go.mod h1:r7j3ShNy5EmOsegRD2DzTutIaGiLiA3M5yBTXXeLwcs=
github.com/desertbit/readline v1.5.1 h1:/wOIZkWYl1s+IvJm/5bOknfUgs6MhS9svRNZpFM53Os=
github.com/desertbit/readline v1.5.1/go.mod h1:pHQgTsCFs9Cpfh5mlSUFi9Xa5kkL4d8L1Jo4UVWzPw0=
github.com/edsrzf/mmap-go v1.1.0 h1:6EUwBLQ/Mcr1EYLE4Tn1VdW1A4ckqCQWZBw8Hr0kjpQ=
github.com/edsrzf/mmap-go v1.1.0/go.mod h1:19H/e8pUPLicwkyNgOykDXkJ9F0MHE+Z52B8EIth78Q=
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0=
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A=
Expand Down

0 comments on commit 4eeb2d8

Please sign in to comment.