From aea3baf6a9369bc4f09d5511e3ae12b6869e5bc0 Mon Sep 17 00:00:00 2001 From: Michal Niewrzal Date: Tue, 23 May 2023 15:58:14 +0200 Subject: [PATCH] satellite/accounting/tally: calculate pending object count Change-Id: I4ee6072f4c60fafd809e8184ada9c1abf7edd8aa --- satellite/accounting/bucketstats.go | 8 +++++--- satellite/accounting/tally/tally.go | 2 ++ satellite/metabase/loop.go | 9 +++++++-- satellite/metabase/loop_test.go | 18 ++++++++++-------- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/satellite/accounting/bucketstats.go b/satellite/accounting/bucketstats.go index 2c5740e3e..70867bd0f 100644 --- a/satellite/accounting/bucketstats.go +++ b/satellite/accounting/bucketstats.go @@ -11,9 +11,10 @@ import ( type BucketTally struct { metabase.BucketLocation - ObjectCount int64 - TotalSegments int64 - TotalBytes int64 + ObjectCount int64 + PendingObjectCount int64 + TotalSegments int64 + TotalBytes int64 MetadataSize int64 } @@ -21,6 +22,7 @@ type BucketTally struct { // Combine aggregates all the tallies. func (s *BucketTally) Combine(o *BucketTally) { s.ObjectCount += o.ObjectCount + s.PendingObjectCount += o.PendingObjectCount s.TotalSegments += o.TotalSegments s.TotalBytes += o.TotalBytes } diff --git a/satellite/accounting/tally/tally.go b/satellite/accounting/tally/tally.go index 99d3c581d..07865119c 100644 --- a/satellite/accounting/tally/tally.go +++ b/satellite/accounting/tally/tally.go @@ -232,6 +232,7 @@ func (service *Service) Tally(ctx context.Context) (err error) { monAccounting.IntVal("total_objects").Observe(total.ObjectCount) //mon:locked monAccounting.IntVal("total_segments").Observe(total.Segments()) //mon:locked monAccounting.IntVal("total_bytes").Observe(total.Bytes()) //mon:locked + monAccounting.IntVal("total_pending_objects").Observe(total.PendingObjectCount) } // return errors if something went wrong. @@ -319,6 +320,7 @@ func (observer *BucketTallyCollector) fillBucketTallies(ctx context.Context, sta bucket.TotalBytes = tally.TotalBytes bucket.MetadataSize = tally.MetadataSize bucket.ObjectCount = tally.ObjectCount + bucket.PendingObjectCount = tally.PendingObjectCount } lastBucketLocation = bucketLocations[len(bucketLocations)-1] diff --git a/satellite/metabase/loop.go b/satellite/metabase/loop.go index 999d572f2..eae24a07b 100644 --- a/satellite/metabase/loop.go +++ b/satellite/metabase/loop.go @@ -411,7 +411,8 @@ func (it *loopSegmentIterator) scanItem(ctx context.Context, item *LoopSegmentEn type BucketTally struct { BucketLocation - ObjectCount int64 + ObjectCount int64 + PendingObjectCount int64 TotalSegments int64 TotalBytes int64 @@ -452,7 +453,10 @@ func (db *DB) CollectBucketTallies(ctx context.Context, opts CollectBucketTallie } err = withRows(db.db.QueryContext(ctx, ` - SELECT project_id, bucket_name, SUM(total_encrypted_size), SUM(segment_count), COALESCE(SUM(length(encrypted_metadata)), 0), count(*) + SELECT + project_id, bucket_name, + SUM(total_encrypted_size), SUM(segment_count), COALESCE(SUM(length(encrypted_metadata)), 0), + count(*), count(*) FILTER (WHERE status = 1) FROM objects `+db.asOfTime(opts.AsOfSystemTime, opts.AsOfSystemInterval)+` WHERE (project_id, bucket_name) BETWEEN ($1, $2) AND ($3, $4) AND @@ -467,6 +471,7 @@ func (db *DB) CollectBucketTallies(ctx context.Context, opts CollectBucketTallie &bucketTally.ProjectID, &bucketTally.BucketName, &bucketTally.TotalBytes, &bucketTally.TotalSegments, &bucketTally.MetadataSize, &bucketTally.ObjectCount, + &bucketTally.PendingObjectCount, ); err != nil { return Error.New("unable to query bucket tally: %w", err) } diff --git a/satellite/metabase/loop_test.go b/satellite/metabase/loop_test.go index 399fa343a..2a32fa09d 100644 --- a/satellite/metabase/loop_test.go +++ b/satellite/metabase/loop_test.go @@ -850,20 +850,22 @@ func TestCollectBucketTallies(t *testing.T) { ProjectID: pending.ProjectID, BucketName: pending.BucketName, }, - ObjectCount: 1, - TotalSegments: 0, - TotalBytes: 0, - MetadataSize: 1024, + ObjectCount: 1, + PendingObjectCount: 1, + TotalSegments: 0, + TotalBytes: 0, + MetadataSize: 1024, }, { BucketLocation: metabase.BucketLocation{ ProjectID: committed.ProjectID, BucketName: committed.BucketName, }, - ObjectCount: 1, - TotalSegments: 1, - TotalBytes: 1024, - MetadataSize: 0, + ObjectCount: 1, + PendingObjectCount: 0, + TotalSegments: 1, + TotalBytes: 1024, + MetadataSize: 0, }, }