satellite/metabase: drop GetSegmentByOffset

Methods was never used in production and it's not sure that
it will be used at all. Let's drop it and restore if will be needed.

Fixes https://github.com/storj/storj/issues/4480

Change-Id: Ifd780d0096b67be7e72dff84bdcf1d957e0b48b5
This commit is contained in:
Michał Niewrzał 2022-03-30 10:33:01 +02:00
parent d8733ddd40
commit 18ab60dc92
4 changed files with 0 additions and 239 deletions

View File

@ -298,73 +298,6 @@ func (db *DB) updateWithAncestorSegment(ctx context.Context, segment *Segment) (
return nil
}
// GetSegmentByOffset contains arguments necessary for fetching a segment information.
type GetSegmentByOffset struct {
ObjectLocation
PlainOffset int64
}
// GetSegmentByOffset returns an object segment information.
func (db *DB) GetSegmentByOffset(ctx context.Context, opts GetSegmentByOffset) (segment Segment, err error) {
defer mon.Task()(&ctx)(&err)
if err := opts.Verify(); err != nil {
return Segment{}, err
}
if opts.PlainOffset < 0 {
return Segment{}, ErrInvalidRequest.New("Invalid PlainOffset: %d", opts.PlainOffset)
}
var aliasPieces AliasPieces
err = db.db.QueryRowContext(ctx, `
SELECT
stream_id, position,
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
FROM segments
WHERE
stream_id IN (SELECT stream_id FROM objects WHERE
project_id = $1 AND
bucket_name = $2 AND
object_key = $3 AND
status = `+committedStatus+`
ORDER BY version DESC
LIMIT 1
) AND
plain_offset <= $4 AND
(plain_size + plain_offset) > $4
ORDER BY plain_offset ASC
LIMIT 1
`, opts.ProjectID, []byte(opts.BucketName), opts.ObjectKey, opts.PlainOffset).
Scan(
&segment.StreamID, &segment.Position,
&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,
)
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)
}
return segment, nil
}
// BucketEmpty contains arguments necessary for checking if bucket is empty.
type BucketEmpty struct {
ProjectID uuid.UUID

View File

@ -1265,153 +1265,6 @@ func TestGetLatestObjectLastSegment(t *testing.T) {
})
}
func TestGetSegmentByOffset(t *testing.T) {
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
obj := metabasetest.RandObjectStream()
location := obj.Location()
now := time.Now()
for _, test := range metabasetest.InvalidObjectLocations(location) {
test := test
t.Run(test.Name, func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
metabasetest.GetSegmentByOffset{
Opts: metabase.GetSegmentByOffset{
ObjectLocation: test.ObjectLocation,
},
ErrClass: test.ErrClass,
ErrText: test.ErrText,
}.Check(ctx, t, db)
metabasetest.Verify{}.Check(ctx, t, db)
})
}
t.Run("Invalid PlainOffset", func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
metabasetest.GetSegmentByOffset{
Opts: metabase.GetSegmentByOffset{
ObjectLocation: location,
PlainOffset: -1,
},
ErrClass: &metabase.ErrInvalidRequest,
ErrText: "Invalid PlainOffset: -1",
}.Check(ctx, t, db)
metabasetest.Verify{}.Check(ctx, t, db)
})
t.Run("Object or segment missing", func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
metabasetest.GetSegmentByOffset{
Opts: metabase.GetSegmentByOffset{
ObjectLocation: 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)
metabasetest.CreateTestObject{}.Run(ctx, t, db, obj, 4)
segments := make([]metabase.Segment, 4)
for i := range segments {
segments[i] = metabase.Segment{
StreamID: obj.StreamID,
Position: metabase.SegmentPosition{
Index: uint32(i),
},
CreatedAt: now,
RootPieceID: storj.PieceID{1},
EncryptedKey: []byte{3},
EncryptedKeyNonce: []byte{4},
EncryptedETag: []byte{5},
EncryptedSize: 1060,
PlainSize: 512,
PlainOffset: int64(i * 512),
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
Redundancy: metabasetest.DefaultRedundancy,
}
}
var testCases = []struct {
Offset int64
ExpectedSegment metabase.Segment
}{
{0, segments[0]},
{100, segments[0]},
{1023, segments[1]},
{1024, segments[2]},
}
for _, tc := range testCases {
metabasetest.GetSegmentByOffset{
Opts: metabase.GetSegmentByOffset{
ObjectLocation: location,
PlainOffset: tc.Offset,
},
Result: tc.ExpectedSegment,
}.Check(ctx, t, db)
}
objExp := metabasetest.CreateExpiredObject(ctx, t, db, metabasetest.RandObjectStream(), 1, now.Add(8*time.Hour))
segmentExpiresAt := metabase.Segment(metabasetest.DefaultRawSegment(objExp.ObjectStream, metabase.SegmentPosition{
Index: 0,
}))
segmentExpiresAt.ExpiresAt = objExp.ExpiresAt
metabasetest.GetSegmentByOffset{
Opts: metabase.GetSegmentByOffset{
ObjectLocation: objExp.Location(),
PlainOffset: 0,
},
Result: segmentExpiresAt,
}.Check(ctx, t, db)
metabasetest.GetSegmentByOffset{
Opts: metabase.GetSegmentByOffset{
ObjectLocation: location,
PlainOffset: 2048,
},
ErrClass: &storj.ErrObjectNotFound,
ErrText: "metabase: object or segment missing",
}.Check(ctx, t, db)
metabasetest.Verify{
Objects: []metabase.RawObject{
{
ObjectStream: obj,
CreatedAt: now,
Status: metabase.Committed,
SegmentCount: 4,
TotalPlainSize: 2048,
TotalEncryptedSize: 4240,
FixedSegmentSize: 512,
Encryption: metabasetest.DefaultEncryption,
},
metabase.RawObject(objExp),
},
Segments: []metabase.RawSegment{
metabase.RawSegment(segments[0]),
metabase.RawSegment(segments[1]),
metabase.RawSegment(segments[2]),
metabase.RawSegment(segments[3]),
metabase.RawSegment(segmentExpiresAt),
},
}.Check(ctx, t, db)
})
})
}
func TestBucketEmpty(t *testing.T) {
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
obj := metabasetest.RandObjectStream()

View File

@ -231,23 +231,6 @@ func (step GetLatestObjectLastSegment) Check(ctx *testcontext.Context, t testing
require.Zero(t, diff)
}
// GetSegmentByOffset is for testing metabase.GetSegmentByOffset.
type GetSegmentByOffset struct {
Opts metabase.GetSegmentByOffset
Result metabase.Segment
ErrClass *errs.Class
ErrText string
}
// Check runs the test.
func (step GetSegmentByOffset) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
result, err := db.GetSegmentByOffset(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)
}
// BucketEmpty is for testing metabase.BucketEmpty.
type BucketEmpty struct {
Opts metabase.BucketEmpty

View File

@ -397,14 +397,6 @@ func TestUpdateSegmentPieces(t *testing.T) {
diff = cmp.Diff(expectedSegment, segment, cmpopts.EquateApproxTime(5*time.Second))
require.Zero(t, diff)
segment, err = db.GetSegmentByOffset(ctx, metabase.GetSegmentByOffset{
ObjectLocation: object.Location(),
PlainOffset: 0,
})
require.NoError(t, err)
diff = cmp.Diff(expectedSegment, segment, cmpopts.EquateApproxTime(5*time.Second))
require.Zero(t, diff)
metabasetest.Verify{
Objects: []metabase.RawObject{
{