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

Make sure WAL Repair can handle wrapped errors #389

Merged
merged 1 commit into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,17 @@ Loop:

// Repair attempts to repair the WAL based on the error.
// It discards all data after the corruption.
func (w *WAL) Repair(err error) error {
func (w *WAL) Repair(origErr error) error {
// We could probably have a mode that only discards torn records right around
// the corruption to preserve as data much as possible.
// 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(origErr) // 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(origErr, "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
Original file line number Diff line number Diff line change
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