From 34027328eb0d38043a57115557d75f720e9b284b Mon Sep 17 00:00:00 2001 From: Michal Niewrzal Date: Tue, 23 Jan 2024 13:54:16 +0100 Subject: [PATCH] satellite/accounting/tally: use AOST with GetNonEmptyTallyBucketsInRange Change-Id: Ibd68edb746df37f5db4feb35944ebe968de45a9a --- satellite/accounting/db.go | 2 +- satellite/accounting/tally/tally.go | 2 +- satellite/satellitedb/projectaccounting.go | 7 ++++--- satellite/satellitedb/projectaccounting_test.go | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/satellite/accounting/db.go b/satellite/accounting/db.go index 85c85c5598c1..d595a058aca3 100644 --- a/satellite/accounting/db.go +++ b/satellite/accounting/db.go @@ -251,7 +251,7 @@ type ProjectAccounting interface { CreateStorageTally(ctx context.Context, tally BucketStorageTally) error // GetNonEmptyTallyBucketsInRange returns a list of bucket locations within the given range // whose most recent tally does not represent empty usage. - GetNonEmptyTallyBucketsInRange(ctx context.Context, from, to metabase.BucketLocation) ([]metabase.BucketLocation, error) + GetNonEmptyTallyBucketsInRange(ctx context.Context, from, to metabase.BucketLocation, asOfSystemInterval time.Duration) ([]metabase.BucketLocation, error) // GetProjectSettledBandwidthTotal returns the sum of GET bandwidth usage settled for a projectID in the past time frame. GetProjectSettledBandwidthTotal(ctx context.Context, projectID uuid.UUID, from time.Time) (_ int64, err error) // GetProjectBandwidth returns project allocated bandwidth for the specified year, month and day. diff --git a/satellite/accounting/tally/tally.go b/satellite/accounting/tally/tally.go index a6fc17828538..26eedafe638e 100644 --- a/satellite/accounting/tally/tally.go +++ b/satellite/accounting/tally/tally.go @@ -313,7 +313,7 @@ func (observer *BucketTallyCollector) fillBucketTallies(ctx context.Context, sta // since they're not reached when iterating over objects in the metainfo DB. // We only do this for buckets whose last tally is non-empty because only one empty tally is // required for us to know that a bucket was empty the last time we checked. - locs, err := observer.projectAccountingDB.GetNonEmptyTallyBucketsInRange(ctx, fromBucket, toBucket) + locs, err := observer.projectAccountingDB.GetNonEmptyTallyBucketsInRange(ctx, fromBucket, toBucket, observer.config.AsOfSystemInterval) if err != nil { return err } diff --git a/satellite/satellitedb/projectaccounting.go b/satellite/satellitedb/projectaccounting.go index b2282d10aee7..dc535bd8747d 100644 --- a/satellite/satellitedb/projectaccounting.go +++ b/satellite/satellitedb/projectaccounting.go @@ -149,13 +149,14 @@ func (db *ProjectAccounting) CreateStorageTally(ctx context.Context, tally accou // GetNonEmptyTallyBucketsInRange returns a list of bucket locations within the given range // whose most recent tally does not represent empty usage. -func (db *ProjectAccounting) GetNonEmptyTallyBucketsInRange(ctx context.Context, from, to metabase.BucketLocation) (result []metabase.BucketLocation, err error) { +func (db *ProjectAccounting) GetNonEmptyTallyBucketsInRange(ctx context.Context, from, to metabase.BucketLocation, asOfSystemInterval time.Duration) (result []metabase.BucketLocation, err error) { defer mon.Task()(&ctx)(&err) err = withRows(db.db.QueryContext(ctx, ` SELECT project_id, name - FROM bucket_metainfos bm - WHERE (project_id, name) BETWEEN ($1, $2) AND ($3, $4) + FROM bucket_metainfos bm`+ + db.db.impl.AsOfSystemInterval(asOfSystemInterval)+ + ` WHERE (project_id, name) BETWEEN ($1, $2) AND ($3, $4) AND NOT 0 IN ( SELECT object_count FROM bucket_storage_tallies WHERE (project_id, bucket_name) = (bm.project_id, bm.name) diff --git a/satellite/satellitedb/projectaccounting_test.go b/satellite/satellitedb/projectaccounting_test.go index fdf9e8845675..656fa6966de5 100644 --- a/satellite/satellitedb/projectaccounting_test.go +++ b/satellite/satellitedb/projectaccounting_test.go @@ -579,7 +579,7 @@ func TestProjectaccounting_GetNonEmptyTallyBucketsInRange(t *testing.T) { }, metabase.BucketLocation{ ProjectID: testrand.UUID(), BucketName: "b\\", - }) + }, 0) require.NoError(t, err) }) }