mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
tsdb/fileutil: use Go standard errors
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
parent
cf528bef03
commit
e3041740e4
|
@ -14,9 +14,8 @@
|
|||
package fileutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type MmapFile struct {
|
||||
|
@ -31,7 +30,7 @@ func OpenMmapFile(path string) (*MmapFile, error) {
|
|||
func OpenMmapFileWithSize(path string, size int) (mf *MmapFile, retErr error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "try lock file")
|
||||
return nil, fmt.Errorf("try lock file: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
|
@ -41,14 +40,14 @@ func OpenMmapFileWithSize(path string, size int) (mf *MmapFile, retErr error) {
|
|||
if size <= 0 {
|
||||
info, err := f.Stat()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "stat")
|
||||
return nil, fmt.Errorf("stat: %w", err)
|
||||
}
|
||||
size = int(info.Size())
|
||||
}
|
||||
|
||||
b, err := mmap(f, size)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "mmap, size %d", size)
|
||||
return nil, fmt.Errorf("mmap, size %d: %w", size, err)
|
||||
}
|
||||
|
||||
return &MmapFile{f: f, b: b}, nil
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package fileutil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
@ -23,10 +24,10 @@ func preallocExtend(f *os.File, sizeInBytes int64) error {
|
|||
// use mode = 0 to change size
|
||||
err := syscall.Fallocate(int(f.Fd()), 0, 0, sizeInBytes)
|
||||
if err != nil {
|
||||
errno, ok := err.(syscall.Errno)
|
||||
var errno syscall.Errno
|
||||
// not supported; fallback
|
||||
// fallocate EINTRs frequently in some environments; fallback
|
||||
if ok && (errno == syscall.ENOTSUP || errno == syscall.EINTR) {
|
||||
if errors.As(err, &errno) && (errno == syscall.ENOTSUP || errno == syscall.EINTR) {
|
||||
return preallocExtendTrunc(f, sizeInBytes)
|
||||
}
|
||||
}
|
||||
|
@ -37,9 +38,9 @@ func preallocFixed(f *os.File, sizeInBytes int64) error {
|
|||
// use mode = 1 to keep size; see FALLOC_FL_KEEP_SIZE
|
||||
err := syscall.Fallocate(int(f.Fd()), 1, 0, sizeInBytes)
|
||||
if err != nil {
|
||||
errno, ok := err.(syscall.Errno)
|
||||
var errno syscall.Errno
|
||||
// treat not supported as nil error
|
||||
if ok && errno == syscall.ENOTSUP {
|
||||
if errors.As(err, &errno) && errno == syscall.ENOTSUP {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue