Skip to content

Commit

Permalink
Tolerate remote put errors
Browse files Browse the repository at this point in the history
  • Loading branch information
or-shachar committed Nov 22, 2023
1 parent f09b126 commit a989099
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cachers/combined.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ func (l *CombinedCache) Get(ctx context.Context, actionID string) (outputID, dis
}
return outputID, diskPath, nil
}
func (l *CombinedCache) Put(ctx context.Context, actionID, outputID string, size int64, body io.Reader) (diskPath string, err error) {

func (l *CombinedCache) Put(ctx context.Context, actionID, outputID string, size int64, body io.Reader) (string, error) {
pr, pw := io.Pipe()
diskPutCh := make(chan any, 1)
go func() {
Expand All @@ -117,14 +118,12 @@ func (l *CombinedCache) Put(ctx context.Context, actionID, outputID string, size

putBody = io.TeeReader(body, pw)
}
_, err = l.putsMetrics.DoWithMeasure(size, func() (string, error) {
// tolerate remote write errors
_, _ = l.putsMetrics.DoWithMeasure(size, func() (string, error) {
e := l.remoteCache.Put(ctx, actionID, outputID, size, putBody)
return "", e
})
pw.Close()
if err != nil {
return "", err
}
v := <-diskPutCh
if err, ok := v.(error); ok {
log.Printf("HTTPCache.Put local disk error: %v", err)
Expand Down
5 changes: 5 additions & 0 deletions cachers/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ func (s *S3Cache) Put(ctx context.Context, actionID, outputID string, size int64
Metadata: map[string]string{
outputIDMetadataKey: outputID,
},
}, func(options *s3.Options) {
options.RetryMaxAttempts = 1 // We cannot perform seek in Body
})
if err != nil && s.verbose {
log.Printf("error S3 put for %s: %v", actionKey, err)
}
return
}

Expand Down

0 comments on commit a989099

Please sign in to comment.