Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
Signed-off-by: Krasi Georgiev <kgeorgie@redhat.com>
  • Loading branch information
Krasi Georgiev committed Oct 25, 2018
1 parent cb99d89 commit 2f2af42
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ install:
script:
# `check_license` target is omitted due to some missing license headers
# `staticcheck` target is omitted due to linting errors
- make test
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then make test; else make style unused test; fi
22 changes: 17 additions & 5 deletions wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ func OpenSegmentWAL(dir string, logger log.Logger, flushInterval time.Duration,
w.files = append(w.files, newSegmentFile(f))
continue
}
f.Close()

level.Warn(logger).Log("msg", "invalid segment file detected, truncating WAL", "err", err, "file", fn)

for _, fn := range fns[i:] {
Expand Down Expand Up @@ -405,17 +407,27 @@ func (w *SegmentWAL) Truncate(mint int64, keep func(uint64) bool) error {
if err := csf.Truncate(off); err != nil {
return err
}
csf.Sync()
csf.Close()

candidates[0].Close() // need close before remove on platform windows
if err := csf.Sync(); err != nil {
return errors.Wrap(err, "persisting temporary segment file")
}

if err := csf.Close(); err != nil {
return errors.Wrap(err, "closing temporary segment file")
}

candidates[0].Close()

if err := renameFile(csf.Name(), candidates[0].Name()); err != nil {
return errors.Wrap(err, "rename compaction segment")
}
for _, f := range candidates[1:] {
f.Close() // need close before remove on platform windows
f.Close()

fmt.Println(f.Name())

if err := os.RemoveAll(f.Name()); err != nil {
return errors.Wrap(err, "delete WAL segment file")
return errors.Wrapf(err, "delete WAL segment file:%v", f.Name())
}
}
if err := w.dirFile.Sync(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func TestSegmentWAL_Truncate(t *testing.T) {
// The same again with a new WAL.
w, err = OpenSegmentWAL(dir, nil, 0, nil)
testutil.Ok(t, err)
defer w.Close()

var readSeries []RefSeries
r := w.Reader()
Expand Down

0 comments on commit 2f2af42

Please sign in to comment.