From 7d15d41e06afcc4dcc5a194379d38a2b7b89074b Mon Sep 17 00:00:00 2001 From: ZhaoShuai <202122280606@std.uestc.edu.cn> Date: Sun, 2 Jul 2023 18:17:18 +0800 Subject: [PATCH 1/3] fix io manager issue(especially mmap) --- config/options.go | 10 ++++++++++ data/data_file.go | 16 ++++++++-------- engine/db.go | 4 ++-- engine/merge.go | 8 ++++---- fio/file_io.go | 4 ---- fio/io_manager.go | 19 +++++++++++++++++++ fio/mmap_io.go | 36 ++++++++++++++++++++---------------- fio/mmap_io_test.go | 16 ++++++++-------- go.sum | 34 ++++++++++++++-------------------- http/http_server_test.go | 5 +++++ raft/raft.go | 1 + 11 files changed, 91 insertions(+), 62 deletions(-) diff --git a/config/options.go b/config/options.go index beafe9ea..54651768 100644 --- a/config/options.go +++ b/config/options.go @@ -7,6 +7,7 @@ type Options struct { DataFileSize int64 //数据文件的大小 SyncWrite bool // 每次写数据是否持久化 IndexType IndexerType + FIOType FIOType } // IteratorOptions 索引迭代器配置项 @@ -25,6 +26,14 @@ type WriteBatchOptions struct { SyncWrites bool } +type FIOType = int8 + +const ( + FileIOType = iota + 1 // Standard File IO + BufIOType // File IO with buffer + MmapIOType // Memory Mapping IO +) + type IndexerType = int8 const ( @@ -40,6 +49,7 @@ var DefaultOptions = Options{ DataFileSize: 256 * 1024 * 1024, // 256MB SyncWrite: false, IndexType: Btree, + FIOType: FileIOType, } var DefaultIteratorOptions = IteratorOptions{ diff --git a/data/data_file.go b/data/data_file.go index 204be527..375b95cc 100644 --- a/data/data_file.go +++ b/data/data_file.go @@ -22,9 +22,9 @@ type DataFile struct { } // OpenDataFile 打开新的数据文件 -func OpenDataFile(dirPath string, fildID uint32) (*DataFile, error) { +func OpenDataFile(dirPath string, fildID uint32, fileSize int64, fioType int8) (*DataFile, error) { fileName := GetDataFileName(dirPath, fildID) - return newDataFile(fileName, fildID) + return newDataFile(fileName, fildID, fileSize, fioType) } func GetDataFileName(dirPath string, fildID uint32) string { @@ -32,20 +32,20 @@ func GetDataFileName(dirPath string, fildID uint32) string { } // OpenHintFile 打开 Hint 索引文件 -func OpenHintFile(dirPath string) (*DataFile, error) { +func OpenHintFile(dirPath string, fileSize int64, fioType int8) (*DataFile, error) { fileName := filepath.Join(dirPath, HintFileSuffix) - return newDataFile(fileName, 0) + return newDataFile(fileName, 0, fileSize, fioType) } // OpenMergeFinaFile 打开标识 merge 完成的文件 -func OpenMergeFinaFile(dirPath string) (*DataFile, error) { +func OpenMergeFinaFile(dirPath string, fileSize int64, fioType int8) (*DataFile, error) { fileName := filepath.Join(dirPath, MergeFinaFileSuffix) - return newDataFile(fileName, 0) + return newDataFile(fileName, 0, fileSize, fioType) } -func newDataFile(dirPath string, fildID uint32) (*DataFile, error) { +func newDataFile(dirPath string, fildID uint32, fileSize int64, fioType int8) (*DataFile, error) { //初始化 IOManager 管理器接口 - ioManager, err := fio.NewIOManager(dirPath) + ioManager, err := fio.NewIOManager(dirPath, fileSize, fioType) if err != nil { return nil, err } diff --git a/engine/db.go b/engine/db.go index 92ddc4fa..cbbf6109 100644 --- a/engine/db.go +++ b/engine/db.go @@ -218,7 +218,7 @@ func (db *DB) setActiveDataFile() error { } // Open a new data file - dataFile, err := data.OpenDataFile(db.options.DirPath, initialFileID) + dataFile, err := data.OpenDataFile(db.options.DirPath, initialFileID, db.options.DataFileSize, db.options.FIOType) if err != nil { return err } @@ -368,7 +368,7 @@ func (db *DB) loadDataFiles() error { // Walk through each file id and open the corresponding data file for i, fid := range fileIds { - dataFile, err := data.OpenDataFile(db.options.DirPath, uint32(fid)) + dataFile, err := data.OpenDataFile(db.options.DirPath, uint32(fid), db.options.DataFileSize, db.options.FIOType) if err != nil { return err } diff --git a/engine/merge.go b/engine/merge.go index e8637875..4fff22e6 100755 --- a/engine/merge.go +++ b/engine/merge.go @@ -85,7 +85,7 @@ func (db *DB) Merge() error { } // 打开 hint 文件存储索引 - hintFile, err := data.OpenHintFile(mergePath) + hintFile, err := data.OpenHintFile(mergePath, db.options.DataFileSize, db.options.FIOType) if err != nil { return err } @@ -131,7 +131,7 @@ func (db *DB) Merge() error { } // 写标识 merge 完成的文件 - mergeFinaFile, err := data.OpenMergeFinaFile(mergePath) + mergeFinaFile, err := data.OpenMergeFinaFile(mergePath, db.options.DataFileSize, db.options.FIOType) if err != nil { return err } @@ -223,7 +223,7 @@ func (db *DB) loadMergeFiles() error { // 获取最近没有参与 merge 的文件 id func (db *DB) getRecentlyNonMergeFileId(dirPath string) (uint32, error) { - mergeFinaFile, err := data.OpenMergeFinaFile(dirPath) + mergeFinaFile, err := data.OpenMergeFinaFile(dirPath, db.options.DataFileSize, db.options.FIOType) if err != nil { return 0, err } @@ -247,7 +247,7 @@ func (db *DB) loadIndexFromHintFile() error { } // 打开 hint 文件 - hintFile, err := data.OpenHintFile(db.options.DirPath) + hintFile, err := data.OpenHintFile(db.options.DirPath, db.options.DataFileSize, db.options.FIOType) if err != nil { return err } diff --git a/fio/file_io.go b/fio/file_io.go index 28efcc50..50e7dcbc 100644 --- a/fio/file_io.go +++ b/fio/file_io.go @@ -45,7 +45,3 @@ func (fio *FileIO) Size() (int64, error) { } return stat.Size(), nil } - -func NewIOManager(filename string) (IOManager, error) { - return NewFileIOManager(filename) -} diff --git a/fio/io_manager.go b/fio/io_manager.go index 3f62b89c..144e4bd6 100644 --- a/fio/io_manager.go +++ b/fio/io_manager.go @@ -2,6 +2,12 @@ package fio const DataFilePerm = 0644 //0644 表示创建了一个文件,文件所有者可以读写,其他人只能读 +const ( + FileIOType = iota + 1 // Standard File IO + BufIOType // File IO with buffer + MmapIOType // Memory Mapping IO +) + // IOManager 抽象 IO 管理接口, 可以接入不同的 IO 类型, 目前支持标准文件 IO type IOManager interface { // Read 从文件的给定位置读取对应的数据 @@ -19,3 +25,16 @@ type IOManager interface { // Size get file size Size() (int64, error) } + +// NewIOManager get IOManager based on type +func NewIOManager(filename string, fileSize int64, fioType int8) (IOManager, error) { + switch fioType { + case FileIOType: + return NewFileIOManager(filename) + case BufIOType: + return NewBufIOManager(filename) + case MmapIOType: + return NewMMapIOManager(filename, fileSize) + } + return NewFileIOManager(filename) +} diff --git a/fio/mmap_io.go b/fio/mmap_io.go index 8bd885a7..5bc20cd0 100644 --- a/fio/mmap_io.go +++ b/fio/mmap_io.go @@ -7,20 +7,18 @@ import ( "unsafe" ) -// DefaultMemMapSize 最大映射内存大小 -const DefaultMemMapSize = 256 * 1024 * 1024 - -// MMapIO 标准系统文件IO type MMapIO struct { - fd *os.File // 系统文件描述符 - data []byte // 与文件对应的映射区 - dirty bool // 是否更改过 - offset int64 // 写入位置 + 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 } -// NewMMapIOManager 初始化标准文件 IO -func NewMMapIOManager(fileName string) (*MMapIO, error) { - mmapIO := &MMapIO{} +// NewMMapIOManager Initialize Mmap IO +func NewMMapIOManager(fileName string, fileSize int64) (*MMapIO, error) { + mmapIO := &MMapIO{fileSize: fileSize} + fd, err := os.OpenFile( fileName, os.O_CREATE|os.O_RDWR|os.O_APPEND, @@ -31,13 +29,13 @@ func NewMMapIOManager(fileName string) (*MMapIO, error) { } info, _ := fd.Stat() - // 将文件扩容到映射区大小, 保存时会裁剪 - if err := fd.Truncate(DefaultMemMapSize); err != nil { + // Expand files to maximum file size, crop when saving + if err := fd.Truncate(fileSize); err != nil { return nil, err } - // 构建映射 - b, err := syscall.Mmap(int(fd.Fd()), 0, DefaultMemMapSize, syscall.PROT_WRITE|syscall.PROT_READ, syscall.MAP_SHARED) + // 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) if err != nil { return nil, err } @@ -48,14 +46,16 @@ func NewMMapIOManager(fileName string) (*MMapIO, error) { return mmapIO, nil } +// Read Copy data from the mapping area to byte slice func (mio *MMapIO) Read(b []byte, offset int64) (int, error) { return copy(b, mio.data[offset:]), nil } +// Write Copy data from byte slice to the mapping area func (mio *MMapIO) Write(b []byte) (int, error) { oldOffset := mio.offset newOffset := mio.offset + int64(len(b)) - if newOffset > DefaultMemMapSize { + if newOffset > mio.fileSize { return 0, errors.New("exceed file max content length") } @@ -64,6 +64,7 @@ func (mio *MMapIO) Write(b []byte) (int, error) { return copy(mio.data[oldOffset:], b), nil } +// Sync Synchronize data from memory to disk func (mio *MMapIO) Sync() error { if !mio.dirty { return nil @@ -78,6 +79,7 @@ func (mio *MMapIO) Sync() error { return nil } +// Close file func (mio *MMapIO) Close() (err error) { if err = mio.fd.Truncate(mio.offset); err != nil { return err @@ -91,10 +93,12 @@ func (mio *MMapIO) Close() (err error) { return mio.fd.Close() } +// Size return the size of current file func (mio *MMapIO) Size() (int64, error) { return mio.offset, nil } +// UnMap Unmapping between memory and files func (mio *MMapIO) UnMap() error { if mio.data == nil { return nil diff --git a/fio/mmap_io_test.go b/fio/mmap_io_test.go index 4d8017ba..d450018b 100644 --- a/fio/mmap_io_test.go +++ b/fio/mmap_io_test.go @@ -8,7 +8,7 @@ import ( func TestNewMMapIOManager(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path) + mio, err := NewMMapIOManager(path, 256*1024*1024) defer destoryFile(path) assert.Nil(t, err) @@ -17,7 +17,7 @@ func TestNewMMapIOManager(t *testing.T) { func TestMMapIO_Write(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path) + mio, err := NewMMapIOManager(path, 256*1024*1024) defer destoryFile(path) assert.Nil(t, err) assert.NotNil(t, mio) @@ -36,7 +36,7 @@ func TestMMapIO_Write(t *testing.T) { func TestMMapIO_Read(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path) + mio, err := NewMMapIOManager(path, 256*1024*1024) defer destoryFile(path) assert.Nil(t, err) @@ -60,7 +60,7 @@ func TestMMapIO_Read(t *testing.T) { func TestMMapIO_Sync(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path) + mio, err := NewMMapIOManager(path, 256*1024*1024) defer destoryFile(path) assert.Nil(t, err) @@ -73,8 +73,8 @@ func TestMMapIO_Sync(t *testing.T) { func TestMMapIO_Close(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path) - defer destoryFile(path) + mio, err := NewMMapIOManager(path, 256*1024*1024) + //defer destoryFile(path) assert.Nil(t, err) assert.NotNil(t, mio) @@ -88,7 +88,7 @@ func TestMMapIO_Close(t *testing.T) { func TestMMapIO_Write_Speed(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path) + mio, err := NewMMapIOManager(path, 256*1024*1024) assert.Nil(t, err) assert.NotNil(t, mio) @@ -104,7 +104,7 @@ func TestMMapIO_Write_Speed(t *testing.T) { func TestMMapIO_Read_Speed(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path) + mio, err := NewMMapIOManager(path, 256*1024*1024) defer destoryFile(path) assert.Nil(t, err) assert.NotNil(t, mio) diff --git a/go.sum b/go.sum index e7c6033b..c8512fcb 100644 --- a/go.sum +++ b/go.sum @@ -23,8 +23,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWs github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -79,9 +79,8 @@ github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+ github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/raft v1.1.0/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM= github.com/hashicorp/raft v1.5.0 h1:uNs9EfJ4FwiArZRxxfd/dQ5d33nV31/CdCHArH89hT8= github.com/hashicorp/raft v1.5.0/go.mod h1:pKHB2mf/Y25u3AHNSXVRv+yT+WAnmeTX0BwVppVQV+M= @@ -89,6 +88,8 @@ github.com/hashicorp/raft-boltdb v0.0.0-20230125174641-2a8082862702 h1:RLKEcCuKc github.com/hashicorp/raft-boltdb v0.0.0-20230125174641-2a8082862702/go.mod h1:nTakvJ4XYq45UXtn0DbwR4aU9ZdjlnIenpbs6Cd+FM0= github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A= github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= @@ -99,15 +100,12 @@ github.com/klauspost/reedsolomon v1.11.7 h1:9uaHU0slncktTEEg4+7Vl7q7XUNMBUOK4R9g github.com/klauspost/reedsolomon v1.11.7/go.mod h1:4bXRN+cVzMdml6ti7qLouuYi32KHJ5MGv0Qd8a47h6A= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= @@ -115,9 +113,8 @@ github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZb github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -129,9 +126,8 @@ github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96d github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/plar/go-adaptive-radix-tree v1.0.5 h1:rHR89qy/6c24TBAHullFMrJsU9hGlKmPibdBGU6/gbM= github.com/plar/go-adaptive-radix-tree v1.0.5/go.mod h1:15VOUO7R9MhJL8HOJdpydR0rvanrtRE6fA6XSa/tqWE= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -150,11 +146,13 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= @@ -221,7 +219,6 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -239,11 +236,8 @@ google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw gopkg.in/AlecAivazis/survey.v1 v1.8.5/go.mod h1:iBNOmqKz/NUbZx3bA+4hAGLRC7fSK7tgtVDT4tB22XA= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/http/http_server_test.go b/http/http_server_test.go index c41cf9c6..5f746ab2 100644 --- a/http/http_server_test.go +++ b/http/http_server_test.go @@ -38,6 +38,7 @@ func TestNewHTTPServer(t *testing.T) { // 测试Put方法 func TestPut(t *testing.T) { handler, _ := newHttpHandler() + defer handler.Close() // 创建一个测试用的http server server := httptest.NewServer(http.HandlerFunc(handler.PutHandler)) defer server.Close() @@ -91,6 +92,7 @@ func TestPut(t *testing.T) { func TestDel(t *testing.T) { handler, _ := newHttpHandler() + defer handler.Close() // 创建一个测试用的http server server := httptest.NewServer(http.HandlerFunc(handler.DelHandler)) defer server.Close() @@ -138,6 +140,7 @@ func TestDel(t *testing.T) { func TestGet(t *testing.T) { handler, _ := newHttpHandler() + defer handler.Close() // 创建一个测试用的http server server := httptest.NewServer(http.HandlerFunc(handler.GetHandler)) defer server.Close() @@ -184,6 +187,7 @@ func TestGet(t *testing.T) { func TestPost(t *testing.T) { handler, _ := newHttpHandler() + defer handler.Close() // 创建一个测试用的 HTTP 服务器 server := httptest.NewServer(http.HandlerFunc(handler.PostHandler)) defer server.Close() @@ -238,6 +242,7 @@ func TestPost(t *testing.T) { func TestGetListKeysHandler(t *testing.T) { handler, _ := newHttpHandler() + defer handler.Close() // 创建一个测试用的http server server := httptest.NewServer(http.HandlerFunc(handler.GetListKeysHandler)) defer server.Close() diff --git a/raft/raft.go b/raft/raft.go index 5d0bf28b..8f31fc9d 100644 --- a/raft/raft.go +++ b/raft/raft.go @@ -23,6 +23,7 @@ var DefaultOptions = config.Options{ DataFileSize: 256 * 1024 * 1024, // 256MB SyncWrite: false, IndexType: Btree, + FIOType: config.FileIOType, } // Cluster define the cluster of db From 5f0098f6f17bbc76fe395f06220e093105bde322 Mon Sep 17 00:00:00 2001 From: ZhaoShuai <202122280606@std.uestc.edu.cn> Date: Sun, 2 Jul 2023 19:20:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?go=20sum=20error=C3=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.sum | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/go.sum b/go.sum index c8512fcb..e7c6033b 100644 --- a/go.sum +++ b/go.sum @@ -23,8 +23,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWs github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -79,8 +79,9 @@ github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+ github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/raft v1.1.0/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM= github.com/hashicorp/raft v1.5.0 h1:uNs9EfJ4FwiArZRxxfd/dQ5d33nV31/CdCHArH89hT8= github.com/hashicorp/raft v1.5.0/go.mod h1:pKHB2mf/Y25u3AHNSXVRv+yT+WAnmeTX0BwVppVQV+M= @@ -88,8 +89,6 @@ github.com/hashicorp/raft-boltdb v0.0.0-20230125174641-2a8082862702 h1:RLKEcCuKc github.com/hashicorp/raft-boltdb v0.0.0-20230125174641-2a8082862702/go.mod h1:nTakvJ4XYq45UXtn0DbwR4aU9ZdjlnIenpbs6Cd+FM0= github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A= github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A= -github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= -github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= @@ -100,12 +99,15 @@ github.com/klauspost/reedsolomon v1.11.7 h1:9uaHU0slncktTEEg4+7Vl7q7XUNMBUOK4R9g github.com/klauspost/reedsolomon v1.11.7/go.mod h1:4bXRN+cVzMdml6ti7qLouuYi32KHJ5MGv0Qd8a47h6A= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= @@ -113,8 +115,9 @@ github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZb github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -126,8 +129,9 @@ github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96d github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/plar/go-adaptive-radix-tree v1.0.5 h1:rHR89qy/6c24TBAHullFMrJsU9hGlKmPibdBGU6/gbM= github.com/plar/go-adaptive-radix-tree v1.0.5/go.mod h1:15VOUO7R9MhJL8HOJdpydR0rvanrtRE6fA6XSa/tqWE= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -146,13 +150,11 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= -github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= @@ -219,6 +221,7 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -236,8 +239,11 @@ google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw gopkg.in/AlecAivazis/survey.v1 v1.8.5/go.mod h1:iBNOmqKz/NUbZx3bA+4hAGLRC7fSK7tgtVDT4tB22XA= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 27c0db4100ebbcb9f270ee92123326d6aa29095e Mon Sep 17 00:00:00 2001 From: ZhaoShuai <202122280606@std.uestc.edu.cn> Date: Sun, 2 Jul 2023 20:35:57 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=C3=A2=C2=80=C3=A2=C2=80fix=20test=20functi?= =?UTF-8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/data_file_test.go | 17 ++++++++++------- fio/io_manager.go | 2 ++ fio/mmap_io_test.go | 16 ++++++++-------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/data/data_file_test.go b/data/data_file_test.go index 98b5a821..545ae58c 100644 --- a/data/data_file_test.go +++ b/data/data_file_test.go @@ -1,27 +1,30 @@ package data import ( + "github.com/ByteStorage/FlyDB/fio" "github.com/stretchr/testify/assert" "os" "testing" ) +const DefaultFileSize = 256 * 1024 * 1024 + func TestOpenDataFile(t *testing.T) { - dataFile1, err := OpenDataFile(os.TempDir(), 0) + dataFile1, err := OpenDataFile(os.TempDir(), 0, DefaultFileSize, fio.FileIOType) assert.Nil(t, err) assert.NotNil(t, dataFile1) - dataFile2, err := OpenDataFile(os.TempDir(), 1) + dataFile2, err := OpenDataFile(os.TempDir(), 1, DefaultFileSize, fio.FileIOType) assert.Nil(t, err) assert.NotNil(t, dataFile2) - dataFile3, err := OpenDataFile(os.TempDir(), 1) + dataFile3, err := OpenDataFile(os.TempDir(), 1, DefaultFileSize, fio.FileIOType) assert.Nil(t, err) assert.NotNil(t, dataFile3) } func TestDataFile_Write(t *testing.T) { - dataFile, err := OpenDataFile(os.TempDir(), 12312) + dataFile, err := OpenDataFile(os.TempDir(), 12312, DefaultFileSize, fio.FileIOType) assert.Nil(t, err) assert.NotNil(t, dataFile) @@ -36,7 +39,7 @@ func TestDataFile_Write(t *testing.T) { } func TestDataFile_Close(t *testing.T) { - dataFile, err := OpenDataFile(os.TempDir(), 1111111) + dataFile, err := OpenDataFile(os.TempDir(), 1111111, DefaultFileSize, fio.FileIOType) assert.Nil(t, err) assert.NotNil(t, dataFile) @@ -45,7 +48,7 @@ func TestDataFile_Close(t *testing.T) { } func TestDataFile_Sync(t *testing.T) { - dataFile, err := OpenDataFile(os.TempDir(), 2222222) + dataFile, err := OpenDataFile(os.TempDir(), 2222222, DefaultFileSize, fio.FileIOType) assert.Nil(t, err) assert.NotNil(t, dataFile) @@ -54,7 +57,7 @@ func TestDataFile_Sync(t *testing.T) { } func TestDataFile_ReadLogRecord(t *testing.T) { - dataFile, err := OpenDataFile(os.TempDir(), 123) + dataFile, err := OpenDataFile(os.TempDir(), 123, DefaultFileSize, fio.FileIOType) assert.Nil(t, err) assert.NotNil(t, dataFile) diff --git a/fio/io_manager.go b/fio/io_manager.go index 144e4bd6..f2898024 100644 --- a/fio/io_manager.go +++ b/fio/io_manager.go @@ -2,6 +2,8 @@ package fio const DataFilePerm = 0644 //0644 表示创建了一个文件,文件所有者可以读写,其他人只能读 +const DefaultFileSize = 256 * 1024 * 1024 + const ( FileIOType = iota + 1 // Standard File IO BufIOType // File IO with buffer diff --git a/fio/mmap_io_test.go b/fio/mmap_io_test.go index d450018b..82dc4bfd 100644 --- a/fio/mmap_io_test.go +++ b/fio/mmap_io_test.go @@ -8,7 +8,7 @@ import ( func TestNewMMapIOManager(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path, 256*1024*1024) + mio, err := NewMMapIOManager(path, DefaultFileSize) defer destoryFile(path) assert.Nil(t, err) @@ -17,7 +17,7 @@ func TestNewMMapIOManager(t *testing.T) { func TestMMapIO_Write(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path, 256*1024*1024) + mio, err := NewMMapIOManager(path, DefaultFileSize) defer destoryFile(path) assert.Nil(t, err) assert.NotNil(t, mio) @@ -36,7 +36,7 @@ func TestMMapIO_Write(t *testing.T) { func TestMMapIO_Read(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path, 256*1024*1024) + mio, err := NewMMapIOManager(path, DefaultFileSize) defer destoryFile(path) assert.Nil(t, err) @@ -60,7 +60,7 @@ func TestMMapIO_Read(t *testing.T) { func TestMMapIO_Sync(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path, 256*1024*1024) + mio, err := NewMMapIOManager(path, DefaultFileSize) defer destoryFile(path) assert.Nil(t, err) @@ -73,8 +73,8 @@ func TestMMapIO_Sync(t *testing.T) { func TestMMapIO_Close(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path, 256*1024*1024) - //defer destoryFile(path) + mio, err := NewMMapIOManager(path, DefaultFileSize) + defer destoryFile(path) assert.Nil(t, err) assert.NotNil(t, mio) @@ -88,7 +88,7 @@ func TestMMapIO_Close(t *testing.T) { func TestMMapIO_Write_Speed(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path, 256*1024*1024) + mio, err := NewMMapIOManager(path, DefaultFileSize) assert.Nil(t, err) assert.NotNil(t, mio) @@ -104,7 +104,7 @@ func TestMMapIO_Write_Speed(t *testing.T) { func TestMMapIO_Read_Speed(t *testing.T) { path := filepath.Join("/tmp", "a.data") - mio, err := NewMMapIOManager(path, 256*1024*1024) + mio, err := NewMMapIOManager(path, DefaultFileSize) defer destoryFile(path) assert.Nil(t, err) assert.NotNil(t, mio)