2019-02-26 15:17:51 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-04-01 14:42:17 +01:00
|
|
|
package accounting
|
2019-02-26 15:17:51 +00:00
|
|
|
|
|
|
|
import (
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2019-02-26 15:17:51 +00:00
|
|
|
)
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// BucketTally contains information about aggregate data stored in a bucket.
|
2019-04-01 14:42:17 +01:00
|
|
|
type BucketTally struct {
|
2020-08-31 11:14:20 +01:00
|
|
|
metabase.BucketLocation
|
2019-06-25 16:58:42 +01:00
|
|
|
|
2019-09-13 14:51:41 +01:00
|
|
|
ObjectCount int64
|
2019-04-09 14:48:35 +01:00
|
|
|
|
2021-06-30 10:58:26 +01:00
|
|
|
TotalSegments int64
|
2019-10-04 20:09:52 +01:00
|
|
|
InlineSegments int64
|
|
|
|
RemoteSegments int64
|
2019-02-26 15:17:51 +00:00
|
|
|
|
2021-06-30 10:58:26 +01:00
|
|
|
TotalBytes int64
|
2019-02-26 15:17:51 +00:00
|
|
|
InlineBytes int64
|
|
|
|
RemoteBytes int64
|
2019-04-01 14:42:17 +01:00
|
|
|
|
|
|
|
MetadataSize int64
|
2019-02-26 15:17:51 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Combine aggregates all the tallies.
|
2019-04-01 14:42:17 +01:00
|
|
|
func (s *BucketTally) Combine(o *BucketTally) {
|
2019-10-04 20:09:52 +01:00
|
|
|
s.ObjectCount += o.ObjectCount
|
|
|
|
|
2021-06-30 10:58:26 +01:00
|
|
|
s.TotalSegments += o.TotalSegments
|
2019-02-26 15:17:51 +00:00
|
|
|
s.InlineSegments += o.InlineSegments
|
|
|
|
s.RemoteSegments += o.RemoteSegments
|
|
|
|
|
2021-06-30 10:58:26 +01:00
|
|
|
s.TotalBytes += o.TotalBytes
|
2019-02-26 15:17:51 +00:00
|
|
|
s.InlineBytes += o.InlineBytes
|
|
|
|
s.RemoteBytes += o.RemoteBytes
|
|
|
|
}
|
|
|
|
|
2019-10-04 20:09:52 +01:00
|
|
|
// Segments returns total number of segments.
|
|
|
|
func (s *BucketTally) Segments() int64 {
|
2021-06-30 10:58:26 +01:00
|
|
|
if s.TotalSegments != 0 {
|
|
|
|
return s.TotalSegments
|
|
|
|
}
|
2019-10-04 20:09:52 +01:00
|
|
|
return s.InlineSegments + s.RemoteSegments
|
2019-02-26 15:17:51 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 20:09:52 +01:00
|
|
|
// Bytes returns total bytes.
|
|
|
|
func (s *BucketTally) Bytes() int64 {
|
2021-06-30 10:58:26 +01:00
|
|
|
if s.TotalBytes != 0 {
|
|
|
|
return s.TotalBytes
|
|
|
|
}
|
2019-10-04 20:09:52 +01:00
|
|
|
return s.InlineBytes + s.RemoteBytes
|
2019-02-26 15:17:51 +00:00
|
|
|
}
|