Skip to content

Commit

Permalink
satellite/accounting/tally: use AOST with GetNonEmptyTallyBucketsInRange
Browse files Browse the repository at this point in the history
Change-Id: Ibd68edb746df37f5db4feb35944ebe968de45a9a
  • Loading branch information
mniewrzal committed Feb 7, 2024
1 parent 815151d commit 3402732
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion satellite/accounting/db.go
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion satellite/accounting/tally/tally.go
Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions satellite/satellitedb/projectaccounting.go
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion satellite/satellitedb/projectaccounting_test.go
Expand Up @@ -579,7 +579,7 @@ func TestProjectaccounting_GetNonEmptyTallyBucketsInRange(t *testing.T) {
}, metabase.BucketLocation{
ProjectID: testrand.UUID(),
BucketName: "b\\",
})
}, 0)
require.NoError(t, err)
})
}

0 comments on commit 3402732

Please sign in to comment.