storj/satellite/accounting/bucketstats.go
Michał Niewrzał 0ca7583282 satellite/accounting: add total for bytes and segments to tallies
We want to calculate bucket tally only from iterating objects.
Object currently has an info about totals for bytes and segments.
We need to adjust tallies to keep those totals. Older entries will
be untouched and code will use totals only if available. Change
is adding columns for totals to bucket_storage_tally table and
is adding general handling for them.

Next step is to start using total columns instead of inline/remote.
This will be done with next change.

Change-Id: I37fed1b327789efcf1d0570318aee3045db17fad
2021-07-01 08:52:32 +00:00

55 lines
1.1 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package accounting
import (
"storj.io/storj/satellite/metabase"
)
// BucketTally contains information about aggregate data stored in a bucket.
type BucketTally struct {
metabase.BucketLocation
ObjectCount int64
TotalSegments int64
InlineSegments int64
RemoteSegments int64
TotalBytes int64
InlineBytes int64
RemoteBytes int64
MetadataSize int64
}
// Combine aggregates all the tallies.
func (s *BucketTally) Combine(o *BucketTally) {
s.ObjectCount += o.ObjectCount
s.TotalSegments += o.TotalSegments
s.InlineSegments += o.InlineSegments
s.RemoteSegments += o.RemoteSegments
s.TotalBytes += o.TotalBytes
s.InlineBytes += o.InlineBytes
s.RemoteBytes += o.RemoteBytes
}
// Segments returns total number of segments.
func (s *BucketTally) Segments() int64 {
if s.TotalSegments != 0 {
return s.TotalSegments
}
return s.InlineSegments + s.RemoteSegments
}
// Bytes returns total bytes.
func (s *BucketTally) Bytes() int64 {
if s.TotalBytes != 0 {
return s.TotalBytes
}
return s.InlineBytes + s.RemoteBytes
}