satellite/metainfo: drop GetSegmentByLocation

Method is not used anymore. We need it during transition
from metainfo loop into segment loop.

Change-Id: Id32590ff9b02e06025efce1c32869e2cf9cd0bc5
This commit is contained in:
Michał Niewrzał 2021-12-16 16:32:45 +01:00
parent 3f0babffe8
commit 60d03b9e42
4 changed files with 6 additions and 198 deletions

View File

@ -169,67 +169,6 @@ func (db *DB) GetObjectLatestVersion(ctx context.Context, opts GetObjectLatestVe
return object, nil
}
// GetSegmentByLocation contains arguments necessary for fetching a segment on specific segment location.
type GetSegmentByLocation struct {
SegmentLocation
}
// GetSegmentByLocation returns information about segment on the specified location.
func (db *DB) GetSegmentByLocation(ctx context.Context, opts GetSegmentByLocation) (segment Segment, err error) {
defer mon.Task()(&ctx)(&err)
if err := opts.Verify(); err != nil {
return Segment{}, err
}
var aliasPieces AliasPieces
err = db.db.QueryRowContext(ctx, `
SELECT
stream_id,
created_at, expires_at, repaired_at,
root_piece_id, encrypted_key_nonce, encrypted_key,
encrypted_size, plain_offset, plain_size,
encrypted_etag,
redundancy,
inline_data, remote_alias_pieces,
placement
FROM segments
WHERE
stream_id IN (SELECT stream_id FROM objects WHERE
project_id = $1 AND
bucket_name = $2 AND
object_key = $3
ORDER BY version DESC
LIMIT 1
) AND
position = $4
`, opts.ProjectID, []byte(opts.BucketName), opts.ObjectKey, opts.Position.Encode()).
Scan(
&segment.StreamID,
&segment.CreatedAt, &segment.ExpiresAt, &segment.RepairedAt,
&segment.RootPieceID, &segment.EncryptedKeyNonce, &segment.EncryptedKey,
&segment.EncryptedSize, &segment.PlainOffset, &segment.PlainSize,
&segment.EncryptedETag,
redundancyScheme{&segment.Redundancy},
&segment.InlineData, &aliasPieces,
&segment.Placement,
)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return Segment{}, storj.ErrObjectNotFound.Wrap(Error.New("object or segment missing"))
}
return Segment{}, Error.New("unable to query segment: %w", err)
}
segment.Pieces, err = db.aliasCache.ConvertAliasesToPieces(ctx, aliasPieces)
if err != nil {
return Segment{}, Error.New("unable to convert aliases to pieces: %w", err)
}
segment.Position = opts.Position
return segment, nil
}
// GetSegmentByPosition contains arguments necessary for fetching a segment on specific position.
type GetSegmentByPosition struct {
StreamID uuid.UUID

View File

@ -331,118 +331,6 @@ func TestGetObjectLatestVersion(t *testing.T) {
})
}
func TestGetSegmentByLocation(t *testing.T) {
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
obj := metabasetest.RandObjectStream()
now := time.Now()
location := metabase.SegmentLocation{
ProjectID: obj.ProjectID,
BucketName: obj.BucketName,
ObjectKey: obj.ObjectKey,
}
for _, test := range metabasetest.InvalidSegmentLocations(location) {
test := test
t.Run(test.Name, func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
metabasetest.GetSegmentByLocation{
Opts: metabase.GetSegmentByLocation{
SegmentLocation: test.SegmentLocation,
},
ErrClass: test.ErrClass,
ErrText: test.ErrText,
}.Check(ctx, t, db)
metabasetest.Verify{}.Check(ctx, t, db)
})
}
t.Run("Object missing", func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
metabasetest.GetSegmentByLocation{
Opts: metabase.GetSegmentByLocation{
SegmentLocation: location,
},
ErrClass: &storj.ErrObjectNotFound,
ErrText: "metabase: object or segment missing",
}.Check(ctx, t, db)
metabasetest.Verify{}.Check(ctx, t, db)
})
t.Run("Get segment", func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
expectedExpiresAt := now.Add(6 * time.Hour)
metabasetest.CreateExpiredObject(ctx, t, db, obj, 1, expectedExpiresAt)
expectedSegment := metabase.Segment{
StreamID: obj.StreamID,
Position: metabase.SegmentPosition{
Index: 0,
},
CreatedAt: now,
ExpiresAt: &expectedExpiresAt,
RootPieceID: storj.PieceID{1},
EncryptedKey: []byte{3},
EncryptedKeyNonce: []byte{4},
EncryptedETag: []byte{5},
EncryptedSize: 1024,
PlainSize: 512,
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
Redundancy: metabasetest.DefaultRedundancy,
}
metabasetest.GetSegmentByLocation{
Opts: metabase.GetSegmentByLocation{
SegmentLocation: location,
},
Result: expectedSegment,
}.Check(ctx, t, db)
// check non existing segment in existing object
metabasetest.GetSegmentByLocation{
Opts: metabase.GetSegmentByLocation{
SegmentLocation: metabase.SegmentLocation{
ProjectID: obj.ProjectID,
BucketName: obj.BucketName,
ObjectKey: obj.ObjectKey,
Position: metabase.SegmentPosition{
Index: 1,
},
},
},
ErrClass: &storj.ErrObjectNotFound,
ErrText: "metabase: object or segment missing",
}.Check(ctx, t, db)
metabasetest.Verify{
Objects: []metabase.RawObject{
{
ObjectStream: obj,
CreatedAt: now,
ExpiresAt: &expectedExpiresAt,
Status: metabase.Committed,
SegmentCount: 1,
TotalPlainSize: 512,
TotalEncryptedSize: 1024,
FixedSegmentSize: 512,
Encryption: metabasetest.DefaultEncryption,
},
},
Segments: []metabase.RawSegment{
metabase.RawSegment(expectedSegment),
},
}.Check(ctx, t, db)
})
})
}
func TestGetSegmentByPosition(t *testing.T) {
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
obj := metabasetest.RandObjectStream()

View File

@ -214,23 +214,6 @@ func (step GetObjectLatestVersion) Check(ctx *testcontext.Context, t testing.TB,
require.Zero(t, diff)
}
// GetSegmentByLocation is for testing metabase.GetSegmentByLocation.
type GetSegmentByLocation struct {
Opts metabase.GetSegmentByLocation
Result metabase.Segment
ErrClass *errs.Class
ErrText string
}
// Check runs the test.
func (step GetSegmentByLocation) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
result, err := db.GetSegmentByLocation(ctx, step.Opts)
checkError(t, err, step.ErrClass, step.ErrText)
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
require.Zero(t, diff)
}
// GetSegmentByPosition is for testing metabase.GetSegmentByPosition.
type GetSegmentByPosition struct {
Opts metabase.GetSegmentByPosition

View File

@ -379,14 +379,12 @@ func TestUpdateSegmentPieces(t *testing.T) {
expectedSegment.Pieces = expectedPieces
expectedSegment.RepairedAt = &repairedAt
segment, err = db.GetSegmentByLocation(ctx, metabase.GetSegmentByLocation{
SegmentLocation: metabase.SegmentLocation{
ProjectID: object.ProjectID,
BucketName: object.BucketName,
ObjectKey: object.ObjectKey,
Position: metabase.SegmentPosition{Index: 0},
},
})
segments, err := db.TestingAllSegments(ctx)
require.NoError(t, err)
require.Len(t, segments, 1)
segment = segments[0]
require.NoError(t, err)
diff := cmp.Diff(expectedSegment, segment, cmpopts.EquateApproxTime(5*time.Second))
require.Zero(t, diff)