Browse Source

Add OpenMmapFileWithSize method (#6753)

Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
pull/6764/head
Ganesh Vernekar 5 years ago committed by GitHub
parent
commit
56bf0ee4dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      tsdb/fileutil/mmap.go

15
tsdb/fileutil/mmap.go

@ -25,16 +25,23 @@ type MmapFile struct {
}
func OpenMmapFile(path string) (*MmapFile, error) {
return OpenMmapFileWithSize(path, 0)
}
func OpenMmapFileWithSize(path string, size int) (*MmapFile, error) {
f, err := os.Open(path)
if err != nil {
return nil, errors.Wrap(err, "try lock file")
}
info, err := f.Stat()
if err != nil {
return nil, errors.Wrap(err, "stat")
if size <= 0 {
info, err := f.Stat()
if err != nil {
return nil, errors.Wrap(err, "stat")
}
size = int(info.Size())
}
b, err := mmap(f, int(info.Size()))
b, err := mmap(f, size)
if err != nil {
return nil, errors.Wrap(err, "mmap")
}

Loading…
Cancel
Save