mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-23 12:44:05 -08:00
* tsdb: Replace fileutil.ReadDir with ioutil.ReadDir (#7029) Signed-off-by: Brad Walker <brad@bradmwalker.com> * tsdb: Remove fileutil.ReadDir (#7029) Signed-off-by: Brad Walker <brad@bradmwalker.com>
This commit is contained in:
parent
05442b31c8
commit
3348930df5
|
@ -601,14 +601,14 @@ func (s *Reader) Chunk(ref uint64) (chunkenc.Chunk, error) {
|
|||
}
|
||||
|
||||
func nextSequenceFile(dir string) (string, int, error) {
|
||||
names, err := fileutil.ReadDir(dir)
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
|
||||
i := uint64(0)
|
||||
for _, n := range names {
|
||||
j, err := strconv.ParseUint(n, 10, 64)
|
||||
for _, f := range files {
|
||||
j, err := strconv.ParseUint(f.Name(), 10, 64)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -1427,14 +1427,14 @@ func sequenceFiles(dir string) ([]string, error) {
|
|||
}
|
||||
|
||||
func nextSequenceFile(dir string) (string, int, error) {
|
||||
names, err := fileutil.ReadDir(dir)
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
|
||||
i := uint64(0)
|
||||
for _, n := range names {
|
||||
j, err := strconv.ParseUint(n, 10, 64)
|
||||
for _, f := range files {
|
||||
j, err := strconv.ParseUint(f.Name(), 10, 64)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -91,21 +90,6 @@ func readDirs(src string) ([]string, error) {
|
|||
return files, nil
|
||||
}
|
||||
|
||||
// ReadDir returns the filenames in the given directory in sorted order.
|
||||
func ReadDir(dirpath string) ([]string, error) {
|
||||
dir, err := os.Open(dirpath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer dir.Close()
|
||||
names, err := dir.Readdirnames(-1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sort.Strings(names)
|
||||
return names, nil
|
||||
}
|
||||
|
||||
// Rename safely renames a file.
|
||||
func Rename(from, to string) error {
|
||||
if err := os.Rename(from, to); err != nil {
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/prometheus/pkg/labels"
|
||||
"github.com/prometheus/prometheus/tsdb/fileutil"
|
||||
"github.com/prometheus/prometheus/tsdb/record"
|
||||
"github.com/prometheus/prometheus/util/testutil"
|
||||
)
|
||||
|
@ -92,9 +91,13 @@ func TestDeleteCheckpoints(t *testing.T) {
|
|||
|
||||
testutil.Ok(t, DeleteCheckpoints(dir, 2))
|
||||
|
||||
files, err := fileutil.ReadDir(dir)
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
testutil.Ok(t, err)
|
||||
testutil.Equals(t, []string{"checkpoint.02", "checkpoint.03"}, files)
|
||||
fns := []string{}
|
||||
for _, f := range files {
|
||||
fns = append(fns, f.Name())
|
||||
}
|
||||
testutil.Equals(t, []string{"checkpoint.02", "checkpoint.03"}, fns)
|
||||
|
||||
testutil.Ok(t, os.MkdirAll(filepath.Join(dir, "checkpoint.99999999"), 0777))
|
||||
testutil.Ok(t, os.MkdirAll(filepath.Join(dir, "checkpoint.100000000"), 0777))
|
||||
|
@ -102,9 +105,13 @@ func TestDeleteCheckpoints(t *testing.T) {
|
|||
|
||||
testutil.Ok(t, DeleteCheckpoints(dir, 100000000))
|
||||
|
||||
files, err = fileutil.ReadDir(dir)
|
||||
files, err = ioutil.ReadDir(dir)
|
||||
testutil.Ok(t, err)
|
||||
testutil.Equals(t, []string{"checkpoint.100000000", "checkpoint.100000001"}, files)
|
||||
fns = []string{}
|
||||
for _, f := range files {
|
||||
fns = append(fns, f.Name())
|
||||
}
|
||||
testutil.Equals(t, []string{"checkpoint.100000000", "checkpoint.100000001"}, fns)
|
||||
}
|
||||
|
||||
func TestCheckpoint(t *testing.T) {
|
||||
|
@ -178,10 +185,10 @@ func TestCheckpoint(t *testing.T) {
|
|||
testutil.Ok(t, DeleteCheckpoints(w.Dir(), 106))
|
||||
|
||||
// Only the new checkpoint should be left.
|
||||
files, err := fileutil.ReadDir(dir)
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
testutil.Ok(t, err)
|
||||
testutil.Equals(t, 1, len(files))
|
||||
testutil.Equals(t, "checkpoint.00000106", files[0])
|
||||
testutil.Equals(t, "checkpoint.00000106", files[0].Name())
|
||||
|
||||
sr, err := NewSegmentsReader(filepath.Join(dir, "checkpoint.00000106"))
|
||||
testutil.Ok(t, err)
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"fmt"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
@ -764,11 +765,12 @@ type segmentRef struct {
|
|||
}
|
||||
|
||||
func listSegments(dir string) (refs []segmentRef, err error) {
|
||||
files, err := fileutil.ReadDir(dir)
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, fn := range files {
|
||||
for _, f := range files {
|
||||
fn := f.Name()
|
||||
k, err := strconv.Atoi(fn)
|
||||
if err != nil {
|
||||
continue
|
||||
|
|
|
@ -16,6 +16,7 @@ package wal
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -29,7 +30,6 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/prometheus/pkg/timestamp"
|
||||
"github.com/prometheus/prometheus/tsdb/fileutil"
|
||||
"github.com/prometheus/prometheus/tsdb/record"
|
||||
)
|
||||
|
||||
|
@ -293,15 +293,15 @@ func (w *Watcher) firstAndLast() (int, int, error) {
|
|||
// Copied from tsdb/wal/wal.go so we do not have to open a WAL.
|
||||
// Plan is to move WAL watcher to TSDB and dedupe these implementations.
|
||||
func (w *Watcher) segments(dir string) ([]int, error) {
|
||||
files, err := fileutil.ReadDir(dir)
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var refs []int
|
||||
var last int
|
||||
for _, fn := range files {
|
||||
k, err := strconv.Atoi(fn)
|
||||
for _, f := range files {
|
||||
k, err := strconv.Atoi(f.Name())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
|
||||
"github.com/go-kit/kit/log"
|
||||
"github.com/prometheus/prometheus/pkg/labels"
|
||||
"github.com/prometheus/prometheus/tsdb/fileutil"
|
||||
"github.com/prometheus/prometheus/tsdb/record"
|
||||
"github.com/prometheus/prometheus/tsdb/tombstones"
|
||||
"github.com/prometheus/prometheus/tsdb/wal"
|
||||
|
@ -303,8 +302,12 @@ func TestWALRestoreCorrupted_invalidSegment(t *testing.T) {
|
|||
_, err = OpenSegmentWAL(dir, log.NewLogfmtLogger(os.Stderr), 0, nil)
|
||||
testutil.Ok(t, err)
|
||||
|
||||
fns, err := fileutil.ReadDir(dir)
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
testutil.Ok(t, err)
|
||||
fns := []string{}
|
||||
for _, f := range files {
|
||||
fns = append(fns, f.Name())
|
||||
}
|
||||
testutil.Equals(t, []string{"000000"}, fns)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue