X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/81ccd9264d0742ba1bf0b9dfbc31ff4f15929f3e..6b30f7c9a223cc1d22974085f6df7aa62393cc55:/services/keepstore/s3_volume.go diff --git a/services/keepstore/s3_volume.go b/services/keepstore/s3_volume.go index ca5b1a2eb9..d34b8772c5 100644 --- a/services/keepstore/s3_volume.go +++ b/services/keepstore/s3_volume.go @@ -14,7 +14,6 @@ import ( "regexp" "strings" "sync" - "sync/atomic" "time" "git.curoverse.com/arvados.git/sdk/go/arvados" @@ -456,10 +455,10 @@ func (v *S3Volume) IndexTo(prefix string, writer io.Writer) error { Prefix: "recent/" + prefix, PageSize: v.IndexPageSize, } - v.bucket.stats.tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps) - v.bucket.stats.tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps) + v.bucket.stats.Tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps) + v.bucket.stats.Tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps) for data, recent := dataL.First(), recentL.First(); data != nil; data = dataL.Next() { - v.bucket.stats.tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps) + v.bucket.stats.Tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps) if data.Key >= "g" { // Conveniently, "recent/*" and "trash/*" are // lexically greater than all hex-encoded data @@ -481,12 +480,12 @@ func (v *S3Volume) IndexTo(prefix string, writer io.Writer) error { for recent != nil { if cmp := strings.Compare(recent.Key[7:], data.Key); cmp < 0 { recent = recentL.Next() - v.bucket.stats.tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps) + v.bucket.stats.Tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps) continue } else if cmp == 0 { stamp = recent recent = recentL.Next() - v.bucket.stats.tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps) + v.bucket.stats.Tick(&v.bucket.stats.Ops, &v.bucket.stats.ListOps) break } else { // recent/X marker is missing: we'll @@ -872,82 +871,56 @@ type s3bucket struct { func (b *s3bucket) GetReader(path string) (io.ReadCloser, error) { rdr, err := b.Bucket.GetReader(path) - b.stats.tick(&b.stats.Ops, &b.stats.GetOps) - b.stats.tickErr(err) - return NewCountingReader(rdr, b.stats.tickInBytes), err + b.stats.Tick(&b.stats.Ops, &b.stats.GetOps) + b.stats.TickErr(err) + return NewCountingReader(rdr, b.stats.TickInBytes), err } func (b *s3bucket) Head(path string, headers map[string][]string) (*http.Response, error) { resp, err := b.Bucket.Head(path, headers) - b.stats.tick(&b.stats.Ops, &b.stats.HeadOps) - b.stats.tickErr(err) + b.stats.Tick(&b.stats.Ops, &b.stats.HeadOps) + b.stats.TickErr(err) return resp, err } func (b *s3bucket) PutReader(path string, r io.Reader, length int64, contType string, perm s3.ACL, options s3.Options) error { - err := b.Bucket.PutReader(path, NewCountingReader(r, b.stats.tickOutBytes), length, contType, perm, options) - b.stats.tick(&b.stats.Ops, &b.stats.PutOps) - b.stats.tickErr(err) + err := b.Bucket.PutReader(path, NewCountingReader(r, b.stats.TickOutBytes), length, contType, perm, options) + b.stats.Tick(&b.stats.Ops, &b.stats.PutOps) + b.stats.TickErr(err) return err } func (b *s3bucket) Put(path string, data []byte, contType string, perm s3.ACL, options s3.Options) error { - err := b.Bucket.PutReader(path, NewCountingReader(bytes.NewBuffer(data), b.stats.tickOutBytes), int64(len(data)), contType, perm, options) - b.stats.tick(&b.stats.Ops, &b.stats.PutOps) - b.stats.tickErr(err) + err := b.Bucket.PutReader(path, NewCountingReader(bytes.NewBuffer(data), b.stats.TickOutBytes), int64(len(data)), contType, perm, options) + b.stats.Tick(&b.stats.Ops, &b.stats.PutOps) + b.stats.TickErr(err) return err } func (b *s3bucket) Del(path string) error { err := b.Bucket.Del(path) - b.stats.tick(&b.stats.Ops, &b.stats.DelOps) - b.stats.tickErr(err) + b.stats.Tick(&b.stats.Ops, &b.stats.DelOps) + b.stats.TickErr(err) return err } type s3bucketStats struct { - Errors uint64 - Ops uint64 - GetOps uint64 - PutOps uint64 - HeadOps uint64 - DelOps uint64 - ListOps uint64 - InBytes uint64 - OutBytes uint64 - - ErrorCodes map[string]uint64 `json:",omitempty"` - - lock sync.Mutex -} - -func (s *s3bucketStats) tickInBytes(n uint64) { - atomic.AddUint64(&s.InBytes, n) -} - -func (s *s3bucketStats) tickOutBytes(n uint64) { - atomic.AddUint64(&s.OutBytes, n) + statsTicker + Ops uint64 + GetOps uint64 + PutOps uint64 + HeadOps uint64 + DelOps uint64 + ListOps uint64 } -func (s *s3bucketStats) tick(counters ...*uint64) { - for _, counter := range counters { - atomic.AddUint64(counter, 1) - } -} - -func (s *s3bucketStats) tickErr(err error) { +func (s *s3bucketStats) TickErr(err error) { if err == nil { return } - atomic.AddUint64(&s.Errors, 1) - errStr := fmt.Sprintf("%T", err) + errType := fmt.Sprintf("%T", err) if err, ok := err.(*s3.Error); ok { - errStr = errStr + fmt.Sprintf(" %d %s", err.StatusCode, err.Code) - } - s.lock.Lock() - if s.ErrorCodes == nil { - s.ErrorCodes = make(map[string]uint64) + errType = errType + fmt.Sprintf(" %d %s", err.StatusCode, err.Code) } - s.ErrorCodes[errStr]++ - s.lock.Unlock() + s.statsTicker.TickErr(err, errType) }