mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
storage: resolve lost upload replies before bounded single-object retries
This commit is contained in:
1 parent
dfffdd8088
commit
a9d24e4256
3 files changed
+47
-4
No files matched your search
@@ -800,6 +800,11 @@ type stagedChunk struct {
|
||||
const chunkStageRounds = 3
|
||||
|
||||
func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res chunkCutResult, err error) {
|
||||
// Retries share one cut budget, shortened by the caller's own deadline.
|
||||
// As with every remote operation, an implementation ignoring cancellation
|
||||
// is still joined before buffers and intents are settled.
|
||||
ctx, deadlineCancel := context.WithTimeout(ctx, 5*time.Minute)
|
||||
defer deadlineCancel()
|
||||
done, err := l.register()
|
||||
if err != nil {
|
||||
return chunkCutResult{}, err
|
||||
@@ -1012,7 +1017,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch
|
||||
}
|
||||
if err := l.uploadBatch(ctx, len(uploads), func(ctx context.Context, i int) error {
|
||||
u := uploads[i]
|
||||
return l.remote.Put(ctx, u.key, u.c.data)
|
||||
return l.putCaptured(ctx, u.key, u.c.data)
|
||||
}); err != nil {
|
||||
l.abortCut(all)
|
||||
l.dropIntents(ctx, intents)
|
||||
@@ -1662,7 +1667,7 @@ func (l *chunkLayerImpl) stage(ctx context.Context, st *chunkCutStats) (map[uint
|
||||
intents = append(intents, id)
|
||||
if err := l.uploadBatch(ctx, len(uploads), func(ctx context.Context, i int) error {
|
||||
u := uploads[i]
|
||||
return l.remote.Put(ctx, u.key, u.data)
|
||||
return l.putCaptured(ctx, u.key, u.data)
|
||||
}); err != nil {
|
||||
return nil, intents, fmt.Errorf("storage: capture stage upload: %w: %w", errChunkRemoteUnavailable, err)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,44 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// putCaptured retries one immutable object, never a whole batch or HEAD CAS.
|
||||
// A lost binding reply can turn the next attempt into KeyExists: only exact
|
||||
// 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
|
||||
for {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
err := l.remote.Put(ctx, key, data)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
// Resolve a possibly committed binding before replaying the Put.
|
||||
got, readErr := l.remote.Get(ctx, key)
|
||||
if readErr == nil {
|
||||
if bytes.Equal(got, data) {
|
||||
return nil
|
||||
}
|
||||
return errChunkKeyExists
|
||||
}
|
||||
timer := time.NewTimer(backoff)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
timer.Stop()
|
||||
return ctx.Err()
|
||||
case <-timer.C:
|
||||
}
|
||||
backoff = min(2*time.Second, 2*backoff)
|
||||
}
|
||||
}
|
||||
|
||||
// uploadBatch owns and joins all Put calls before its caller settles intents.
|
||||
// No storage/publication lock is acquired by workers. Cancellation stops new
|
||||
// admission; a remote ignoring cancellation remains joined, never declared done.
|
||||
|
||||
@@ -65,8 +65,12 @@ func TestChunkCutRetriesOnlyTheFailedUpload(t *testing.T) {
|
||||
t.Fatalf("new key generated on retry: %v", r.calls)
|
||||
}
|
||||
for key, n := range r.calls {
|
||||
if n != 2 {
|
||||
t.Fatalf("key %s attempted %d times, want 2", key, n)
|
||||
want := 2
|
||||
if mode == "lost" {
|
||||
want = 1
|
||||
}
|
||||
if n != want {
|
||||
t.Fatalf("key %s attempted %d times, want %d", key, n, want)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user