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

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

Issue 1904503003: LogDog: Fix archived log stream read errors. (Closed) Base URL: https://github.com/luci/luci-go@hierarchy-check-first
Patch Set: Created 4 years, 8 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 Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package gs 5 package gs
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "io" 9 "io"
10 "net/http" 10 "net/http"
(...skipping 19 matching lines...) Expand all
30 ) 30 )
31 31
32 // Client abstracts funcitonality to connect with and use Google Storage from 32 // Client abstracts funcitonality to connect with and use Google Storage from
33 // the actual Google Storage client. 33 // the actual Google Storage client.
34 // 34 //
35 // Non-production implementations are used primarily for testing. 35 // Non-production implementations are used primarily for testing.
36 type Client interface { 36 type Client interface {
37 io.Closer 37 io.Closer
38 38
39 // NewReader instantiates a new Reader instance for the named bucket/pat h. 39 // NewReader instantiates a new Reader instance for the named bucket/pat h.
40 » NewReader(p Path, o Options) (io.ReadCloser, error) 40 » //
41 » // If the supplied offset is <0, it will default to 0. If the supplied l ength
42 » // is <0, no upper byte bound will be set.
nodir 2016/04/19 23:41:16 why not accept uint64 or panic? if someone passes
dnj 2016/04/20 00:45:07 We generally don't do uint64 in our code, even for
nodir 2016/04/20 16:42:57 ok, why not panic? If there is a negative value, i
dnj 2016/04/20 17:07:25 Sure, I'll panic if offset is <0.
43 » NewReader(p Path, offset int64, length int64) (io.ReadCloser, error)
nodir 2016/04/19 23:41:16 nit: offset, length int64
dnj 2016/04/20 00:45:07 Done.
41 44
42 // NewWriter instantiates a new Writer instance for the named bucket/pat h. 45 // NewWriter instantiates a new Writer instance for the named bucket/pat h.
43 NewWriter(p Path) (Writer, error) 46 NewWriter(p Path) (Writer, error)
44 47
45 // Delete deletes the object at the specified path. 48 // Delete deletes the object at the specified path.
46 // 49 //
47 // If the object does not exist, it is considered a success. 50 // If the object does not exist, it is considered a success.
48 Delete(p Path) error 51 Delete(p Path) error
49 52
50 // Rename renames an object from one path to another. 53 // Rename renames an object from one path to another.
51 // 54 //
52 // NOTE: The object should be removed from its original path, but curren t 55 // NOTE: The object should be removed from its original path, but curren t
53 // implementation uses two operations (Copy + Delete), so it may 56 // implementation uses two operations (Copy + Delete), so it may
54 // occasionally fail. 57 // occasionally fail.
55 Rename(src, dst Path) error 58 Rename(src, dst Path) error
56 } 59 }
57 60
58 // Options are the set of extra options to apply to the Google Storage request.
59 type Options struct {
60 // From is the range request starting index. If >0, the beginning of the
61 // range request will be set.
62 From int64
63 // To is the range request ending index. If >0, the end of the
64 // range request will be set.
65 //
66 // If no From index is set, this will result in a request indexed from t he end
67 // of the object.
68 To int64
69 }
70
71 // prodGSObject is an implementation of Client interface using the production 61 // prodGSObject is an implementation of Client interface using the production
72 // Google Storage client. 62 // Google Storage client.
73 type prodClient struct { 63 type prodClient struct {
74 context.Context 64 context.Context
75 65
76 // rt is the RoundTripper to use, or nil for the cloud service default. 66 // rt is the RoundTripper to use, or nil for the cloud service default.
77 rt http.RoundTripper 67 rt http.RoundTripper
78 // baseClient is a basic Google Storage client instance. It is used for 68 // baseClient is a basic Google Storage client instance. It is used for
79 // operations that don't need custom header injections. 69 // operations that don't need custom header injections.
80 baseClient *gs.Client 70 baseClient *gs.Client
(...skipping 28 matching lines...) Expand all
109 } 99 }
110 100
111 return &prodWriter{ 101 return &prodWriter{
112 Context: c, 102 Context: c,
113 client: c, 103 client: c,
114 bucket: bucket, 104 bucket: bucket,
115 relpath: filename, 105 relpath: filename,
116 }, nil 106 }, nil
117 } 107 }
118 108
119 func (c *prodClient) NewReader(p Path, o Options) (io.ReadCloser, error) { 109 func (c *prodClient) NewReader(p Path, offset int64, length int64) (io.ReadClose r, error) {
nodir 2016/04/19 23:41:16 nit: offset, length int64
dnj 2016/04/20 00:45:07 Done.
120 » if o.From < 0 { 110 » if offset < 0 {
121 » » o.From = 0 111 » » offset = 0
122 » }
123 » if o.To <= 0 {
124 » » o.To = -1
125 } 112 }
126 113
127 obj, err := c.handleForPath(p) 114 obj, err := c.handleForPath(p)
128 if err != nil { 115 if err != nil {
129 return nil, err 116 return nil, err
130 } 117 }
131 » return obj.NewRangeReader(c, o.From, o.To) 118 » return obj.NewRangeReader(c, offset, length)
132 } 119 }
133 120
134 func (c *prodClient) Rename(src, dst Path) error { 121 func (c *prodClient) Rename(src, dst Path) error {
135 srcObj, err := c.handleForPath(src) 122 srcObj, err := c.handleForPath(src)
136 if err != nil { 123 if err != nil {
137 return fmt.Errorf("invalid source path: %s", err) 124 return fmt.Errorf("invalid source path: %s", err)
138 } 125 }
139 126
140 dstObj, err := c.handleForPath(dst) 127 dstObj, err := c.handleForPath(dst)
141 if err != nil { 128 if err != nil {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // The storage library doesn't return gs.ErrObjectNotExist when Delete 229 // The storage library doesn't return gs.ErrObjectNotExist when Delete
243 // returns a 404. Catch that explicitly. 230 // returns a 404. Catch that explicitly.
244 if t, ok := err.(*googleapi.Error); ok { 231 if t, ok := err.(*googleapi.Error); ok {
245 switch t.Code { 232 switch t.Code {
246 case http.StatusNotFound: 233 case http.StatusNotFound:
247 return true 234 return true
248 } 235 }
249 } 236 }
250 return false 237 return false
251 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698