mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-12 16:44:05 -08:00
Add OpenMmapFileWithSize method (#6753)
Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
This commit is contained in:
parent
49f8850a3c
commit
56bf0ee4dc
|
@ -25,16 +25,23 @@ type MmapFile struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func OpenMmapFile(path string) (*MmapFile, error) {
|
func OpenMmapFile(path string) (*MmapFile, error) {
|
||||||
|
return OpenMmapFileWithSize(path, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func OpenMmapFileWithSize(path string, size int) (*MmapFile, error) {
|
||||||
f, err := os.Open(path)
|
f, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "try lock file")
|
return nil, errors.Wrap(err, "try lock file")
|
||||||
}
|
}
|
||||||
|
if size <= 0 {
|
||||||
info, err := f.Stat()
|
info, err := f.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "stat")
|
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 {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "mmap")
|
return nil, errors.Wrap(err, "mmap")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue