forked from TrueCloudLab/restic
retry: Do not retry Load() if file does not exist
This commit is contained in:
parent
495982232c
commit
d15ffd9c92
3 changed files with 41 additions and 1 deletions
8
changelog/unreleased/issue-4515
Normal file
8
changelog/unreleased/issue-4515
Normal file
|
@ -0,0 +1,8 @@
|
|||
Change: Don't retry to load files that don't exist
|
||||
|
||||
Restic used to always retry to load files. It now only retries to load
|
||||
files if they exist.
|
||||
|
||||
https://github.com/restic/restic/issues/4515
|
||||
https://github.com/restic/restic/issues/1523
|
||||
https://github.com/restic/restic/pull/4520
|
|
@ -128,7 +128,11 @@ func (be *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRe
|
|||
func (be *Backend) Load(ctx context.Context, h restic.Handle, length int, offset int64, consumer func(rd io.Reader) error) (err error) {
|
||||
return be.retry(ctx, fmt.Sprintf("Load(%v, %v, %v)", h, length, offset),
|
||||
func() error {
|
||||
return be.Backend.Load(ctx, h, length, offset, consumer)
|
||||
err := be.Backend.Load(ctx, h, length, offset, consumer)
|
||||
if be.Backend.IsNotExist(err) {
|
||||
return backoff.Permanent(err)
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -274,6 +274,34 @@ func TestBackendLoadRetry(t *testing.T) {
|
|||
test.Equals(t, 2, attempt)
|
||||
}
|
||||
|
||||
func TestBackendLoadNotExists(t *testing.T) {
|
||||
// load should not retry if the error matches IsNotExist
|
||||
notFound := errors.New("not found")
|
||||
attempt := 0
|
||||
|
||||
be := mock.NewBackend()
|
||||
be.OpenReaderFn = func(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
attempt++
|
||||
if attempt > 1 {
|
||||
t.Fail()
|
||||
return nil, errors.New("must not retry")
|
||||
}
|
||||
return nil, notFound
|
||||
}
|
||||
be.IsNotExistFn = func(err error) bool {
|
||||
return errors.Is(err, notFound)
|
||||
}
|
||||
|
||||
TestFastRetries(t)
|
||||
retryBackend := New(be, 10, nil, nil)
|
||||
|
||||
err := retryBackend.Load(context.TODO(), restic.Handle{}, 0, 0, func(rd io.Reader) (err error) {
|
||||
return nil
|
||||
})
|
||||
test.Assert(t, be.IsNotExistFn(err), "unexpected error %v", err)
|
||||
test.Equals(t, 1, attempt)
|
||||
}
|
||||
|
||||
func TestBackendStatNotExists(t *testing.T) {
|
||||
// stat should not retry if the error matches IsNotExist
|
||||
notFound := errors.New("not found")
|
||||
|
|
Loading…
Reference in a new issue