Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: common/gcloud/gs/writer.go

Issue 2951393002: [errors] de-specialize Transient in favor of Tags. (Closed)
Patch Set: copyright Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package gs 5 package gs
6 6
7 import ( 7 import (
8 "io" 8 "io"
9 "time" 9 "time"
10 10
11 gs "cloud.google.com/go/storage" 11 gs "cloud.google.com/go/storage"
12 "github.com/luci/luci-go/common/errors"
13 log "github.com/luci/luci-go/common/logging" 12 log "github.com/luci/luci-go/common/logging"
14 "github.com/luci/luci-go/common/retry" 13 "github.com/luci/luci-go/common/retry"
15 "golang.org/x/net/context" 14 "golang.org/x/net/context"
16 ) 15 )
17 16
18 // Writer is an augmented io.WriteCloser instance. 17 // Writer is an augmented io.WriteCloser instance.
19 type Writer interface { 18 type Writer interface {
20 io.WriteCloser 19 io.WriteCloser
21 20
22 // Count returns the number of bytes written by the object. 21 // Count returns the number of bytes written by the object.
(...skipping 16 matching lines...) Expand all
39 // Write writes data with exponenital backoff/retry. 38 // Write writes data with exponenital backoff/retry.
40 func (w *prodWriter) Write(d []byte) (a int, err error) { 39 func (w *prodWriter) Write(d []byte) (a int, err error) {
41 if w.Writer == nil { 40 if w.Writer == nil {
42 w.Writer = w.client.baseClient.Bucket(w.bucket).Object(w.relpath ).NewWriter(w) 41 w.Writer = w.client.baseClient.Bucket(w.bucket).Object(w.relpath ).NewWriter(w)
43 } 42 }
44 43
45 err = retry.Retry(w, retry.TransientOnly(retry.Default), func() (ierr er ror) { 44 err = retry.Retry(w, retry.TransientOnly(retry.Default), func() (ierr er ror) {
46 a, ierr = w.Writer.Write(d) 45 a, ierr = w.Writer.Write(d)
47 46
48 // Assume all Write errors are transient. 47 // Assume all Write errors are transient.
49 » » ierr = errors.WrapTransient(ierr) 48 » » ierr = retry.Tag.Apply(ierr)
50 return 49 return
51 }, func(err error, d time.Duration) { 50 }, func(err error, d time.Duration) {
52 log.Fields{ 51 log.Fields{
53 log.ErrorKey: err, 52 log.ErrorKey: err,
54 "delay": d, 53 "delay": d,
55 "bucket": w.bucket, 54 "bucket": w.bucket,
56 "path": w.relpath, 55 "path": w.relpath,
57 }.Warningf(w, "Transient error on GS write. Retrying...") 56 }.Warningf(w, "Transient error on GS write. Retrying...")
58 }) 57 })
59 58
(...skipping 14 matching lines...) Expand all
74 "delay": d, 73 "delay": d,
75 "bucket": w.bucket, 74 "bucket": w.bucket,
76 "path": w.relpath, 75 "path": w.relpath,
77 }.Warningf(w, "Transient error closing GS Writer. Retryi ng...") 76 }.Warningf(w, "Transient error closing GS Writer. Retryi ng...")
78 }) 77 })
79 } 78 }
80 79
81 func (w *prodWriter) Count() int64 { 80 func (w *prodWriter) Count() int64 {
82 return w.count 81 return w.count
83 } 82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698