storage: retain the remote cause when a retry budget ends

This commit is contained in:
pingqiu committed 2026-11-18 22:20:47 -08:00
1 parent 92f172006a
commit b47b40fadf
2 files changed
+15 -5

No files matched your search

+5 -2
View File
@@ -3,6 +3,7 @@ package storage
import (
"bytes"
"context"
"errors"
"sync"
"time"
)
@@ -12,14 +13,16 @@ import (
// bytes read from that binding prove completion; a collision is terminal.
func (l *chunkLayerImpl) putCaptured(ctx context.Context, key string, data []byte) error {
backoff := 100 * time.Millisecond
var lastErr error
for {
if err := ctx.Err(); err != nil {
return err
return errors.Join(lastErr, err)
}
err := l.remote.Put(ctx, key, data)
if err == nil {
return nil
}
lastErr = err
// Resolve a possibly committed binding before replaying the Put.
got, readErr := l.remote.Get(ctx, key)
if readErr == nil {
@@ -32,7 +35,7 @@ func (l *chunkLayerImpl) putCaptured(ctx context.Context, key string, data []byt
select {
case <-ctx.Done():
timer.Stop()
return ctx.Err()
return errors.Join(lastErr, ctx.Err())
case <-timer.C:
}
backoff = min(2*time.Second, 2*backoff)
@@ -108,12 +108,16 @@ type unjoinedUploadRemote struct {
}
func (r *unjoinedUploadRemote) Put(ctx context.Context, key string, data []byte) error {
if r.calls.Add(1) == 1 {
switch r.calls.Add(1) {
case 1:
<-r.second
close(r.failed)
return errFakeRemoteDown
case 2:
close(r.second)
default:
return errFakeRemoteDown
}
close(r.second)
<-r.release
return r.fakeChunkRemote.Put(context.Background(), key, data)
}
@@ -128,10 +132,13 @@ func TestChunkUploads_FailureJoinsBeforeIntentCleanup(t *testing.T) {
w := newWriteLog()
w.write(t, s, 0, 0x21)
w.write(t, s, ctChunkBlocks, 0x22)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
done := make(chan error, 1)
go func() { _, err := l.Cut(context.Background()); done <- err }()
go func() { _, err := l.Cut(ctx); done <- err }()
select {
case <-r.failed:
cancel() // retries are now allowed; terminate this cut explicitly
case <-time.After(time.Second):
close(r.release)
<-done