1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
23 "git.curoverse.com/arvados.git/sdk/go/arvados"
24 "github.com/AdRoll/goamz/aws"
25 "github.com/AdRoll/goamz/s3"
26 log "github.com/Sirupsen/logrus"
30 s3DefaultReadTimeout = arvados.Duration(10 * time.Minute)
31 s3DefaultConnectTimeout = arvados.Duration(time.Minute)
35 // ErrS3TrashDisabled is returned by Trash if that operation
36 // is impossible with the current config.
37 ErrS3TrashDisabled = fmt.Errorf("trash function is disabled because -trash-lifetime=0 and -s3-unsafe-delete=false")
39 s3AccessKeyFile string
40 s3SecretKeyFile string
45 s3RaceWindow time.Duration
51 maxClockSkew = 600 * time.Second
52 nearlyRFC1123 = "Mon, 2 Jan 2006 15:04:05 GMT"
55 type s3VolumeAdder struct {
59 // String implements flag.Value
60 func (s *s3VolumeAdder) String() string {
64 func (s *s3VolumeAdder) Set(bucketName string) error {
66 return fmt.Errorf("no container name given")
68 if s3AccessKeyFile == "" || s3SecretKeyFile == "" {
69 return fmt.Errorf("-s3-access-key-file and -s3-secret-key-file arguments must given before -s3-bucket-volume")
71 if deprecated.flagSerializeIO {
72 log.Print("Notice: -serialize is not supported by s3-bucket volumes.")
74 s.Config.Volumes = append(s.Config.Volumes, &S3Volume{
76 AccessKeyFile: s3AccessKeyFile,
77 SecretKeyFile: s3SecretKeyFile,
80 RaceWindow: arvados.Duration(s3RaceWindow),
81 S3Replication: s3Replication,
82 UnsafeDelete: s3UnsafeDelete,
83 ReadOnly: deprecated.flagReadonly,
89 func s3regions() (okList []string) {
90 for r := range aws.Regions {
91 okList = append(okList, r)
97 VolumeTypes = append(VolumeTypes, func() VolumeWithExamples { return &S3Volume{} })
99 flag.Var(&s3VolumeAdder{theConfig},
101 "Use the given bucket as a storage volume. Can be given multiple times.")
106 fmt.Sprintf("AWS region used for subsequent -s3-bucket-volume arguments. Allowed values are %+q.", s3regions()))
111 "Endpoint URL used for subsequent -s3-bucket-volume arguments. If blank, use the AWS endpoint corresponding to the -s3-region argument. For Google Storage, use \"https://storage.googleapis.com\".")
114 "s3-access-key-file",
116 "`File` containing the access key used for subsequent -s3-bucket-volume arguments.")
119 "s3-secret-key-file",
121 "`File` containing the secret key used for subsequent -s3-bucket-volume arguments.")
126 "Maximum eventual consistency latency for subsequent -s3-bucket-volume arguments.")
131 "Replication level reported to clients for subsequent -s3-bucket-volume arguments.")
136 "EXPERIMENTAL. Enable deletion (garbage collection), even though there are known race conditions that can cause data loss.")
139 // S3Volume implements Volume using an S3 bucket.
140 type S3Volume struct {
146 LocationConstraint bool
149 ConnectTimeout arvados.Duration
150 ReadTimeout arvados.Duration
151 RaceWindow arvados.Duration
160 // Examples implements VolumeWithExamples.
161 func (*S3Volume) Examples() []Volume {
164 AccessKeyFile: "/etc/aws_s3_access_key.txt",
165 SecretKeyFile: "/etc/aws_s3_secret_key.txt",
168 Bucket: "example-bucket-name",
171 RaceWindow: arvados.Duration(24 * time.Hour),
172 ConnectTimeout: arvados.Duration(time.Minute),
173 ReadTimeout: arvados.Duration(5 * time.Minute),
176 AccessKeyFile: "/etc/gce_s3_access_key.txt",
177 SecretKeyFile: "/etc/gce_s3_secret_key.txt",
178 Endpoint: "https://storage.googleapis.com",
180 Bucket: "example-bucket-name",
183 RaceWindow: arvados.Duration(24 * time.Hour),
184 ConnectTimeout: arvados.Duration(time.Minute),
185 ReadTimeout: arvados.Duration(5 * time.Minute),
190 // Type implements Volume.
191 func (*S3Volume) Type() string {
195 // Start populates private fields and verifies the configuration is
197 func (v *S3Volume) Start() error {
198 region, ok := aws.Regions[v.Region]
199 if v.Endpoint == "" {
201 return fmt.Errorf("unrecognized region %+q; try specifying -s3-endpoint instead", v.Region)
204 return fmt.Errorf("refusing to use AWS region name %+q with endpoint %+q; "+
205 "specify empty endpoint (\"-s3-endpoint=\") or use a different region name", v.Region, v.Endpoint)
209 S3Endpoint: v.Endpoint,
210 S3LocationConstraint: v.LocationConstraint,
216 auth.AccessKey, err = readKeyFromFile(v.AccessKeyFile)
220 auth.SecretKey, err = readKeyFromFile(v.SecretKeyFile)
225 // Zero timeouts mean "wait forever", which is a bad
226 // default. Default to long timeouts instead.
227 if v.ConnectTimeout == 0 {
228 v.ConnectTimeout = s3DefaultConnectTimeout
230 if v.ReadTimeout == 0 {
231 v.ReadTimeout = s3DefaultReadTimeout
234 client := s3.New(auth, region)
235 client.ConnectTimeout = time.Duration(v.ConnectTimeout)
236 client.ReadTimeout = time.Duration(v.ReadTimeout)
237 v.bucket = &s3bucket{
246 // DeviceID returns a globally unique ID for the storage bucket.
247 func (v *S3Volume) DeviceID() string {
248 return "s3://" + v.Endpoint + "/" + v.Bucket
251 func (v *S3Volume) getReaderWithContext(ctx context.Context, loc string) (rdr io.ReadCloser, err error) {
252 ready := make(chan bool)
254 rdr, err = v.getReader(loc)
261 theConfig.debugLogf("s3: abandoning getReader(): %s", ctx.Err())
268 return nil, ctx.Err()
272 // getReader wraps (Bucket)GetReader.
274 // In situations where (Bucket)GetReader would fail because the block
275 // disappeared in a Trash race, getReader calls fixRace to recover the
276 // data, and tries again.
277 func (v *S3Volume) getReader(loc string) (rdr io.ReadCloser, err error) {
278 rdr, err = v.bucket.GetReader(loc)
279 err = v.translateError(err)
280 if err == nil || !os.IsNotExist(err) {
284 _, err = v.bucket.Head("recent/"+loc, nil)
285 err = v.translateError(err)
287 // If we can't read recent/X, there's no point in
288 // trying fixRace. Give up.
296 rdr, err = v.bucket.GetReader(loc)
298 log.Printf("warning: reading %s after successful fixRace: %s", loc, err)
299 err = v.translateError(err)
304 // Get a block: copy the block data into buf, and return the number of
306 func (v *S3Volume) Get(ctx context.Context, loc string, buf []byte) (int, error) {
307 rdr, err := v.getReaderWithContext(ctx, loc)
313 ready := make(chan bool)
318 n, err = io.ReadFull(rdr, buf)
321 case nil, io.EOF, io.ErrUnexpectedEOF:
324 err = v.translateError(err)
329 theConfig.debugLogf("s3: interrupting ReadFull() with Close() because %s", ctx.Err())
331 // Must wait for ReadFull to return, to ensure it
332 // doesn't write to buf after we return.
333 theConfig.debugLogf("s3: waiting for ReadFull() to fail")
341 // Compare the given data with the stored data.
342 func (v *S3Volume) Compare(ctx context.Context, loc string, expect []byte) error {
343 rdr, err := v.getReaderWithContext(ctx, loc)
348 return v.translateError(compareReaderWithBuf(ctx, rdr, expect, loc[:32]))
351 // Put writes a block.
352 func (v *S3Volume) Put(ctx context.Context, loc string, block []byte) error {
354 return MethodDisabledError
359 md5, err := hex.DecodeString(loc)
363 opts.ContentMD5 = base64.StdEncoding.EncodeToString(md5)
366 // Send the block data through a pipe, so that (if we need to)
367 // we can close the pipe early and abandon our PutReader()
368 // goroutine, without worrying about PutReader() accessing our
369 // block buffer after we release it.
370 bufr, bufw := io.Pipe()
372 io.Copy(bufw, bytes.NewReader(block))
377 ready := make(chan bool)
380 if ctx.Err() != nil {
381 theConfig.debugLogf("%s: abandoned PutReader goroutine finished with err: %s", v, err)
385 err = v.bucket.PutReader(loc, bufr, int64(size), "application/octet-stream", s3ACL, opts)
389 err = v.bucket.Put("recent/"+loc, nil, "application/octet-stream", s3ACL, s3.Options{})
393 theConfig.debugLogf("%s: taking PutReader's input away: %s", v, ctx.Err())
394 // Our pipe might be stuck in Write(), waiting for
395 // io.Copy() to read. If so, un-stick it. This means
396 // PutReader will get corrupt data, but that's OK: the
397 // size and MD5 won't match, so the write will fail.
398 go io.Copy(ioutil.Discard, bufr)
399 // CloseWithError() will return once pending I/O is done.
400 bufw.CloseWithError(ctx.Err())
401 theConfig.debugLogf("%s: abandoning PutReader goroutine", v)
404 return v.translateError(err)
408 // Touch sets the timestamp for the given locator to the current time.
409 func (v *S3Volume) Touch(loc string) error {
411 return MethodDisabledError
413 _, err := v.bucket.Head(loc, nil)
414 err = v.translateError(err)
415 if os.IsNotExist(err) && v.fixRace(loc) {
416 // The data object got trashed in a race, but fixRace
418 } else if err != nil {
421 err = v.bucket.Put("recent/"+loc, nil, "application/octet-stream", s3ACL, s3.Options{})
422 return v.translateError(err)
425 // Mtime returns the stored timestamp for the given locator.
426 func (v *S3Volume) Mtime(loc string) (time.Time, error) {
427 _, err := v.bucket.Head(loc, nil)
429 return zeroTime, v.translateError(err)
431 resp, err := v.bucket.Head("recent/"+loc, nil)
432 err = v.translateError(err)
433 if os.IsNotExist(err) {
434 // The data object X exists, but recent/X is missing.
435 err = v.bucket.Put("recent/"+loc, nil, "application/octet-stream", s3ACL, s3.Options{})
437 log.Printf("error: creating %q: %s", "recent/"+loc, err)
438 return zeroTime, v.translateError(err)
440 log.Printf("info: created %q to migrate existing block to new storage scheme", "recent/"+loc)
441 resp, err = v.bucket.Head("recent/"+loc, nil)
443 log.Printf("error: created %q but HEAD failed: %s", "recent/"+loc, err)
444 return zeroTime, v.translateError(err)
446 } else if err != nil {
447 // HEAD recent/X failed for some other reason.
450 return v.lastModified(resp)
453 // IndexTo writes a complete list of locators with the given prefix
454 // for which Get() can retrieve data.
455 func (v *S3Volume) IndexTo(prefix string, writer io.Writer) error {
456 // Use a merge sort to find matching sets of X and recent/X.
458 Bucket: v.bucket.Bucket,
460 PageSize: v.IndexPageSize,
463 Bucket: v.bucket.Bucket,
464 Prefix: "recent/" + prefix,
465 PageSize: v.IndexPageSize,
467 v.bucket.stats.Tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps)
468 v.bucket.stats.Tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps)
469 for data, recent := dataL.First(), recentL.First(); data != nil; data = dataL.Next() {
470 v.bucket.stats.Tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps)
472 // Conveniently, "recent/*" and "trash/*" are
473 // lexically greater than all hex-encoded data
474 // hashes, so stopping here avoids iterating
475 // over all of them needlessly with dataL.
478 if !v.isKeepBlock(data.Key) {
482 // stamp is the list entry we should use to report the
483 // last-modified time for this data block: it will be
484 // the recent/X entry if one exists, otherwise the
485 // entry for the data block itself.
488 // Advance to the corresponding recent/X marker, if any
490 if cmp := strings.Compare(recent.Key[7:], data.Key); cmp < 0 {
491 recent = recentL.Next()
492 v.bucket.stats.Tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps)
496 recent = recentL.Next()
497 v.bucket.stats.Tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps)
500 // recent/X marker is missing: we'll
501 // use the timestamp on the data
506 t, err := time.Parse(time.RFC3339, stamp.LastModified)
510 fmt.Fprintf(writer, "%s+%d %d\n", data.Key, data.Size, t.UnixNano())
515 // Trash a Keep block.
516 func (v *S3Volume) Trash(loc string) error {
518 return MethodDisabledError
520 if t, err := v.Mtime(loc); err != nil {
522 } else if time.Since(t) < theConfig.BlobSignatureTTL.Duration() {
525 if theConfig.TrashLifetime == 0 {
527 return ErrS3TrashDisabled
529 return v.translateError(v.bucket.Del(loc))
531 err := v.checkRaceWindow(loc)
535 err = v.safeCopy("trash/"+loc, loc)
539 return v.translateError(v.bucket.Del(loc))
542 // checkRaceWindow returns a non-nil error if trash/loc is, or might
543 // be, in the race window (i.e., it's not safe to trash loc).
544 func (v *S3Volume) checkRaceWindow(loc string) error {
545 resp, err := v.bucket.Head("trash/"+loc, nil)
546 err = v.translateError(err)
547 if os.IsNotExist(err) {
548 // OK, trash/X doesn't exist so we're not in the race
551 } else if err != nil {
552 // Error looking up trash/X. We don't know whether
553 // we're in the race window
556 t, err := v.lastModified(resp)
558 // Can't parse timestamp
561 safeWindow := t.Add(theConfig.TrashLifetime.Duration()).Sub(time.Now().Add(time.Duration(v.RaceWindow)))
563 // We can't count on "touch trash/X" to prolong
564 // trash/X's lifetime. The new timestamp might not
565 // become visible until now+raceWindow, and EmptyTrash
566 // is allowed to delete trash/X before then.
567 return fmt.Errorf("same block is already in trash, and safe window ended %s ago", -safeWindow)
569 // trash/X exists, but it won't be eligible for deletion until
570 // after now+raceWindow, so it's safe to overwrite it.
574 // safeCopy calls PutCopy, and checks the response to make sure the
575 // copy succeeded and updated the timestamp on the destination object
576 // (PutCopy returns 200 OK if the request was received, even if the
578 func (v *S3Volume) safeCopy(dst, src string) error {
579 resp, err := v.bucket.PutCopy(dst, s3ACL, s3.CopyOptions{
580 ContentType: "application/octet-stream",
581 MetadataDirective: "REPLACE",
582 }, v.bucket.Name+"/"+src)
583 err = v.translateError(err)
587 if t, err := time.Parse(time.RFC3339Nano, resp.LastModified); err != nil {
588 return fmt.Errorf("PutCopy succeeded but did not return a timestamp: %q: %s", resp.LastModified, err)
589 } else if time.Now().Sub(t) > maxClockSkew {
590 return fmt.Errorf("PutCopy succeeded but returned an old timestamp: %q: %s", resp.LastModified, t)
595 // Get the LastModified header from resp, and parse it as RFC1123 or
596 // -- if it isn't valid RFC1123 -- as Amazon's variant of RFC1123.
597 func (v *S3Volume) lastModified(resp *http.Response) (t time.Time, err error) {
598 s := resp.Header.Get("Last-Modified")
599 t, err = time.Parse(time.RFC1123, s)
600 if err != nil && s != "" {
601 // AWS example is "Sun, 1 Jan 2006 12:00:00 GMT",
602 // which isn't quite "Sun, 01 Jan 2006 12:00:00 GMT"
603 // as required by HTTP spec. If it's not a valid HTTP
604 // header value, it's probably AWS (or s3test) giving
605 // us a nearly-RFC1123 timestamp.
606 t, err = time.Parse(nearlyRFC1123, s)
611 // Untrash moves block from trash back into store
612 func (v *S3Volume) Untrash(loc string) error {
613 err := v.safeCopy(loc, "trash/"+loc)
617 err = v.bucket.Put("recent/"+loc, nil, "application/octet-stream", s3ACL, s3.Options{})
618 return v.translateError(err)
621 // Status returns a *VolumeStatus representing the current in-use
622 // storage capacity and a fake available capacity that doesn't make
623 // the volume seem full or nearly-full.
624 func (v *S3Volume) Status() *VolumeStatus {
625 return &VolumeStatus{
627 BytesFree: BlockSize * 1000,
632 // InternalStats returns bucket I/O and API call counters.
633 func (v *S3Volume) InternalStats() interface{} {
634 return &v.bucket.stats
637 // String implements fmt.Stringer.
638 func (v *S3Volume) String() string {
639 return fmt.Sprintf("s3-bucket:%+q", v.Bucket)
642 // Writable returns false if all future Put, Mtime, and Delete calls
643 // are expected to fail.
644 func (v *S3Volume) Writable() bool {
648 // Replication returns the storage redundancy of the underlying
649 // device. Configured via command line flag.
650 func (v *S3Volume) Replication() int {
651 return v.S3Replication
654 var s3KeepBlockRegexp = regexp.MustCompile(`^[0-9a-f]{32}$`)
656 func (v *S3Volume) isKeepBlock(s string) bool {
657 return s3KeepBlockRegexp.MatchString(s)
660 // fixRace(X) is called when "recent/X" exists but "X" doesn't
661 // exist. If the timestamps on "recent/"+loc and "trash/"+loc indicate
662 // there was a race between Put and Trash, fixRace recovers from the
663 // race by Untrashing the block.
664 func (v *S3Volume) fixRace(loc string) bool {
665 trash, err := v.bucket.Head("trash/"+loc, nil)
667 if !os.IsNotExist(v.translateError(err)) {
668 log.Printf("error: fixRace: HEAD %q: %s", "trash/"+loc, err)
672 trashTime, err := v.lastModified(trash)
674 log.Printf("error: fixRace: parse %q: %s", trash.Header.Get("Last-Modified"), err)
678 recent, err := v.bucket.Head("recent/"+loc, nil)
680 log.Printf("error: fixRace: HEAD %q: %s", "recent/"+loc, err)
683 recentTime, err := v.lastModified(recent)
685 log.Printf("error: fixRace: parse %q: %s", recent.Header.Get("Last-Modified"), err)
689 ageWhenTrashed := trashTime.Sub(recentTime)
690 if ageWhenTrashed >= theConfig.BlobSignatureTTL.Duration() {
691 // No evidence of a race: block hasn't been written
692 // since it became eligible for Trash. No fix needed.
696 log.Printf("notice: fixRace: %q: trashed at %s but touched at %s (age when trashed = %s < %s)", loc, trashTime, recentTime, ageWhenTrashed, theConfig.BlobSignatureTTL)
697 log.Printf("notice: fixRace: copying %q to %q to recover from race between Put/Touch and Trash", "recent/"+loc, loc)
698 err = v.safeCopy(loc, "trash/"+loc)
700 log.Printf("error: fixRace: %s", err)
706 func (v *S3Volume) translateError(err error) error {
707 switch err := err.(type) {
709 if (err.StatusCode == http.StatusNotFound && err.Code == "NoSuchKey") ||
710 strings.Contains(err.Error(), "Not Found") {
711 return os.ErrNotExist
713 // Other 404 errors like NoSuchVersion and
714 // NoSuchBucket are different problems which should
715 // get called out downstream, so we don't convert them
716 // to os.ErrNotExist.
721 // EmptyTrash looks for trashed blocks that exceeded TrashLifetime
722 // and deletes them from the volume.
723 func (v *S3Volume) EmptyTrash() {
724 var bytesInTrash, blocksInTrash, bytesDeleted, blocksDeleted int64
726 // Use a merge sort to find matching sets of trash/X and recent/X.
728 Bucket: v.bucket.Bucket,
730 PageSize: v.IndexPageSize,
732 // Define "ready to delete" as "...when EmptyTrash started".
734 for trash := trashL.First(); trash != nil; trash = trashL.Next() {
736 if !v.isKeepBlock(loc) {
739 bytesInTrash += trash.Size
742 trashT, err := time.Parse(time.RFC3339, trash.LastModified)
744 log.Printf("warning: %s: EmptyTrash: %q: parse %q: %s", v, trash.Key, trash.LastModified, err)
747 recent, err := v.bucket.Head("recent/"+loc, nil)
748 if err != nil && os.IsNotExist(v.translateError(err)) {
749 log.Printf("warning: %s: EmptyTrash: found trash marker %q but no %q (%s); calling Untrash", v, trash.Key, "recent/"+loc, err)
752 log.Printf("error: %s: EmptyTrash: Untrash(%q): %s", v, loc, err)
755 } else if err != nil {
756 log.Printf("warning: %s: EmptyTrash: HEAD %q: %s", v, "recent/"+loc, err)
759 recentT, err := v.lastModified(recent)
761 log.Printf("warning: %s: EmptyTrash: %q: parse %q: %s", v, "recent/"+loc, recent.Header.Get("Last-Modified"), err)
764 if trashT.Sub(recentT) < theConfig.BlobSignatureTTL.Duration() {
765 if age := startT.Sub(recentT); age >= theConfig.BlobSignatureTTL.Duration()-time.Duration(v.RaceWindow) {
766 // recent/loc is too old to protect
767 // loc from being Trashed again during
768 // the raceWindow that starts if we
769 // delete trash/X now.
771 // Note this means (TrashCheckInterval
772 // < BlobSignatureTTL - raceWindow) is
773 // necessary to avoid starvation.
774 log.Printf("notice: %s: EmptyTrash: detected old race for %q, calling fixRace + Touch", v, loc)
779 _, err := v.bucket.Head(loc, nil)
780 if os.IsNotExist(err) {
781 log.Printf("notice: %s: EmptyTrash: detected recent race for %q, calling fixRace", v, loc)
784 } else if err != nil {
785 log.Printf("warning: %s: EmptyTrash: HEAD %q: %s", v, loc, err)
789 if startT.Sub(trashT) < theConfig.TrashLifetime.Duration() {
792 err = v.bucket.Del(trash.Key)
794 log.Printf("warning: %s: EmptyTrash: deleting %q: %s", v, trash.Key, err)
797 bytesDeleted += trash.Size
800 _, err = v.bucket.Head(loc, nil)
801 if os.IsNotExist(err) {
802 err = v.bucket.Del("recent/" + loc)
804 log.Printf("warning: %s: EmptyTrash: deleting %q: %s", v, "recent/"+loc, err)
806 } else if err != nil {
807 log.Printf("warning: %s: EmptyTrash: HEAD %q: %s", v, "recent/"+loc, err)
810 if err := trashL.Error(); err != nil {
811 log.Printf("error: %s: EmptyTrash: lister: %s", v, err)
813 log.Printf("EmptyTrash stats for %v: Deleted %v bytes in %v blocks. Remaining in trash: %v bytes in %v blocks.", v.String(), bytesDeleted, blocksDeleted, bytesInTrash-bytesDeleted, blocksInTrash-blocksDeleted)
816 type s3Lister struct {
825 // First fetches the first page and returns the first item. It returns
826 // nil if the response is the empty set or an error occurs.
827 func (lister *s3Lister) First() *s3.Key {
832 // Next returns the next item, fetching the next page if necessary. It
833 // returns nil if the last available item has already been fetched, or
835 func (lister *s3Lister) Next() *s3.Key {
836 if len(lister.buf) == 0 && lister.nextMarker != "" {
842 // Return the most recent error encountered by First or Next.
843 func (lister *s3Lister) Error() error {
847 func (lister *s3Lister) getPage() {
848 resp, err := lister.Bucket.List(lister.Prefix, "", lister.nextMarker, lister.PageSize)
849 lister.nextMarker = ""
854 if resp.IsTruncated {
855 lister.nextMarker = resp.NextMarker
857 lister.buf = make([]s3.Key, 0, len(resp.Contents))
858 for _, key := range resp.Contents {
859 if !strings.HasPrefix(key.Key, lister.Prefix) {
860 log.Printf("warning: s3Lister: S3 Bucket.List(prefix=%q) returned key %q", lister.Prefix, key.Key)
863 lister.buf = append(lister.buf, key)
867 func (lister *s3Lister) pop() (k *s3.Key) {
868 if len(lister.buf) > 0 {
870 lister.buf = lister.buf[1:]
875 // s3bucket wraps s3.bucket and counts I/O and API usage stats.
876 type s3bucket struct {
881 func (b *s3bucket) GetReader(path string) (io.ReadCloser, error) {
882 rdr, err := b.Bucket.GetReader(path)
883 b.stats.Tick(&b.stats.Ops, &b.stats.GetOps)
885 return NewCountingReader(rdr, b.stats.TickInBytes), err
888 func (b *s3bucket) Head(path string, headers map[string][]string) (*http.Response, error) {
889 resp, err := b.Bucket.Head(path, headers)
890 b.stats.Tick(&b.stats.Ops, &b.stats.HeadOps)
895 func (b *s3bucket) PutReader(path string, r io.Reader, length int64, contType string, perm s3.ACL, options s3.Options) error {
896 err := b.Bucket.PutReader(path, NewCountingReader(r, b.stats.TickOutBytes), length, contType, perm, options)
897 b.stats.Tick(&b.stats.Ops, &b.stats.PutOps)
902 func (b *s3bucket) Put(path string, data []byte, contType string, perm s3.ACL, options s3.Options) error {
903 err := b.Bucket.PutReader(path, NewCountingReader(bytes.NewBuffer(data), b.stats.TickOutBytes), int64(len(data)), contType, perm, options)
904 b.stats.Tick(&b.stats.Ops, &b.stats.PutOps)
909 func (b *s3bucket) Del(path string) error {
910 err := b.Bucket.Del(path)
911 b.stats.Tick(&b.stats.Ops, &b.stats.DelOps)
916 type s3bucketStats struct {
926 func (s *s3bucketStats) TickErr(err error) {
930 errType := fmt.Sprintf("%T", err)
931 if err, ok := err.(*s3.Error); ok {
932 errType = errType + fmt.Sprintf(" %d %s", err.StatusCode, err.Code)
934 s.statsTicker.TickErr(err, errType)