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

Commit

Permalink
Make sure WAL Repair can handle wrapped errors
Browse files Browse the repository at this point in the history
Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>
  • Loading branch information
gouthamve committed Sep 19, 2018
1 parent d1a6eda commit 71a5d97
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion wal/wal.go
Expand Up @@ -261,9 +261,11 @@ func (w *WAL) Repair(err error) error {
// But that's not generally applicable if the records have any kind of causality.
// Maybe as an extra mode in the future if mid-WAL corruptions become
// a frequent concern.
err = errors.Cause(err) // So that we can pick up errors even if wrapped.

cerr, ok := err.(*CorruptionErr)
if !ok {
return errors.New("cannot handle error")
return errors.Wrap(err, "cannot handle error")
}
if cerr.Segment < 0 {
return errors.New("corruption error does not specify position")
Expand Down
3 changes: 2 additions & 1 deletion wal/wal_test.go
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"testing"

"github.com/pkg/errors"
"github.com/prometheus/tsdb/testutil"
)

Expand Down Expand Up @@ -286,8 +287,8 @@ func TestWAL_Repair(t *testing.T) {
for r.Next() {
}
testutil.NotOk(t, r.Err())

testutil.Ok(t, w.Repair(r.Err()))
testutil.Ok(t, w.Repair(errors.Wrap(r.Err(), "err"))) // See https://github.com/prometheus/prometheus/issues/4603

sr, err = NewSegmentsReader(dir)
testutil.Ok(t, err)
Expand Down

0 comments on commit 71a5d97

Please sign in to comment.