satellite/metabase: drop GetProjectSegmentCount and related code

Resolves: https://github.com/storj/storj/issues/4744

Change-Id: I66b12e17de461242745e785dedd397fbe3b386fa
This commit is contained in:
Qweder93 2022-05-10 11:33:13 +03:00 committed by Michal Niewrzal
parent a447b27ffc
commit 50b826e582
4 changed files with 0 additions and 216 deletions

View File

@ -203,18 +203,6 @@ func (usage *Service) GetProjectBandwidth(ctx context.Context, projectID uuid.UU
return total, ErrProjectUsage.Wrap(err)
}
// GetProjectSegments returns project allocated segment usage.
func (usage *Service) GetProjectSegments(ctx context.Context, projectID uuid.UUID) (_ int64, err error) {
defer mon.Task()(&ctx, projectID)(&err)
total, err := usage.metabaseDB.GetProjectSegmentCount(ctx, metabase.GetProjectSegmentCount{
ProjectID: projectID,
AsOfSystemInterval: usage.asOfSystemInterval,
})
return total, ErrProjectUsage.Wrap(err)
}
// GetProjectStorageLimit returns current project storage limit.
func (usage *Service) GetProjectStorageLimit(ctx context.Context, projectID uuid.UUID) (_ memory.Size, err error) {
defer mon.Task()(&ctx, projectID)(&err)

View File

@ -676,18 +676,3 @@ func (step FinishCopyObject) Check(ctx *testcontext.Context, t testing.TB, db *m
require.Zero(t, diff)
return result
}
// GetProjectSegmentCount is for testing metabase.GetProjectSegmentCount.
type GetProjectSegmentCount struct {
Opts metabase.GetProjectSegmentCount
Result int64
ErrClass *errs.Class
ErrText string
}
// Check runs the test.
func (step GetProjectSegmentCount) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
result, err := db.GetProjectSegmentCount(ctx, step.Opts)
checkError(t, err, step.ErrClass, step.ErrText)
require.Equal(t, step.Result, result)
}

View File

@ -1,56 +0,0 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package metabase
import (
"context"
"time"
"storj.io/common/uuid"
)
// GetProjectSegmentCount contains arguments necessary for fetching an information
// about project segment count.
type GetProjectSegmentCount struct {
ProjectID uuid.UUID
AsOfSystemTime time.Time
AsOfSystemInterval time.Duration
}
// Verify verifies reqest fields.
func (g *GetProjectSegmentCount) Verify() error {
if g.ProjectID.IsZero() {
return ErrInvalidRequest.New("ProjectID missing")
}
return nil
}
// GetProjectSegmentCount returns number of segments that specified project has.
func (db *DB) GetProjectSegmentCount(ctx context.Context, opts GetProjectSegmentCount) (_ int64, err error) {
defer mon.Task()(&ctx)(&err)
if err := opts.Verify(); err != nil {
return 0, err
}
var segmentsCount *int64
err = db.db.QueryRowContext(ctx, `
SELECT
sum(segment_count)
FROM objects
`+db.asOfTime(opts.AsOfSystemTime, opts.AsOfSystemInterval)+`
WHERE
project_id = $1
`, opts.ProjectID).Scan(&segmentsCount)
if err != nil {
return 0, Error.New("unable to query project segment count: %w", err)
}
if segmentsCount == nil {
return 0, Error.New("project not found: %s", opts.ProjectID)
}
return *segmentsCount, nil
}

View File

@ -1,133 +0,0 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package metabase_test
import (
"testing"
"time"
"storj.io/common/testcontext"
"storj.io/common/testrand"
"storj.io/common/uuid"
"storj.io/storj/satellite/metabase"
"storj.io/storj/satellite/metabase/metabasetest"
)
func TestGetProjectSegmentsCount(t *testing.T) {
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
obj := metabasetest.RandObjectStream()
t.Run("ProjectID missing", func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
metabasetest.GetProjectSegmentCount{
Opts: metabase.GetProjectSegmentCount{},
ErrClass: &metabase.ErrInvalidRequest,
ErrText: "ProjectID missing",
}.Check(ctx, t, db)
metabasetest.Verify{}.Check(ctx, t, db)
})
t.Run("empty database", func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
metabasetest.GetProjectSegmentCount{
Opts: metabase.GetProjectSegmentCount{
ProjectID: obj.ProjectID,
},
ErrClass: &metabase.Error,
ErrText: "project not found: " + obj.ProjectID.String(),
}.Check(ctx, t, db)
})
t.Run("object without segments", func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
metabasetest.CreateObject(ctx, t, db, obj, 0)
metabasetest.GetProjectSegmentCount{
Opts: metabase.GetProjectSegmentCount{
ProjectID: obj.ProjectID,
},
Result: 0,
}.Check(ctx, t, db)
})
t.Run("object with segments", func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
metabasetest.CreateObject(ctx, t, db, obj, 1)
metabasetest.GetProjectSegmentCount{
Opts: metabase.GetProjectSegmentCount{
ProjectID: obj.ProjectID,
},
Result: 1,
}.Check(ctx, t, db)
})
t.Run("object with segments (as of system time)", func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
metabasetest.CreateObject(ctx, t, db, obj, 1)
metabasetest.GetProjectSegmentCount{
Opts: metabase.GetProjectSegmentCount{
ProjectID: obj.ProjectID,
AsOfSystemTime: time.Now(),
AsOfSystemInterval: time.Millisecond,
},
Result: 1,
}.Check(ctx, t, db)
})
t.Run("multiple projects", func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
project1 := testrand.UUID()
project2 := testrand.UUID()
project3 := testrand.UUID()
type Object struct {
ProjectID uuid.UUID
Segments byte
}
objects := []Object{
{project1, 1},
{project1, 4},
{project2, 5},
{project2, 3},
{project2, 1},
{project3, 2},
{project3, 0},
}
for _, object := range objects {
obj := metabasetest.RandObjectStream()
obj.ProjectID = object.ProjectID
metabasetest.CreateObject(ctx, t, db, obj, object.Segments)
}
// expected number of segments per project
projects := map[uuid.UUID]int{
project1: 5,
project2: 9,
project3: 2,
}
for project, segments := range projects {
metabasetest.GetProjectSegmentCount{
Opts: metabase.GetProjectSegmentCount{
ProjectID: project,
},
Result: int64(segments),
}.Check(ctx, t, db)
}
})
})
}