satellite/metainfo/metabase: add PlainOffset to segment listing

Change-Id: I8bbb5fcebf9f171033938eaae9f415b3a4b5aaa0
This commit is contained in:
Egon Elbre 2021-03-29 18:31:17 +03:00
parent c4cb79ff1f
commit 794dc6d6d5
3 changed files with 15 additions and 10 deletions

View File

@ -116,6 +116,7 @@ type ListStreamPositionsResult struct {
type SegmentPositionInfo struct { type SegmentPositionInfo struct {
Position SegmentPosition Position SegmentPosition
PlainSize int32 PlainSize int32
PlainOffset int64
CreatedAt *time.Time // TODO: make it non-nilable after we migrate all existing segments to have creation time CreatedAt *time.Time // TODO: make it non-nilable after we migrate all existing segments to have creation time
EncryptedETag []byte EncryptedETag []byte
EncryptedKeyNonce []byte EncryptedKeyNonce []byte
@ -140,7 +141,7 @@ func (db *DB) ListStreamPositions(ctx context.Context, opts ListStreamPositions)
err = withRows(db.db.Query(ctx, ` err = withRows(db.db.Query(ctx, `
SELECT SELECT
position, plain_size, created_at, position, plain_size, plain_offset, created_at,
encrypted_etag, encrypted_key_nonce, encrypted_key encrypted_etag, encrypted_key_nonce, encrypted_key
FROM segments FROM segments
WHERE WHERE
@ -152,7 +153,7 @@ func (db *DB) ListStreamPositions(ctx context.Context, opts ListStreamPositions)
for rows.Next() { for rows.Next() {
var segment SegmentPositionInfo var segment SegmentPositionInfo
err = rows.Scan( err = rows.Scan(
&segment.Position, &segment.PlainSize, &segment.CreatedAt, &segment.Position, &segment.PlainSize, &segment.PlainOffset, &segment.CreatedAt,
&segment.EncryptedETag, &segment.EncryptedKeyNonce, &segment.EncryptedKey, &segment.EncryptedETag, &segment.EncryptedKeyNonce, &segment.EncryptedKey,
) )
if err != nil { if err != nil {

View File

@ -45,7 +45,7 @@ func TestListSegments(t *testing.T) {
Verify{}.Check(ctx, t, db) Verify{}.Check(ctx, t, db)
}) })
t.Run("List no segments", func(t *testing.T) { t.Run("no segments", func(t *testing.T) {
defer DeleteAll{}.Check(ctx, t, db) defer DeleteAll{}.Check(ctx, t, db)
ListSegments{ ListSegments{
@ -59,7 +59,7 @@ func TestListSegments(t *testing.T) {
Verify{}.Check(ctx, t, db) Verify{}.Check(ctx, t, db)
}) })
t.Run("List segments", func(t *testing.T) { t.Run("segments", func(t *testing.T) {
defer DeleteAll{}.Check(ctx, t, db) defer DeleteAll{}.Check(ctx, t, db)
expectedObject := createObject(ctx, t, db, obj, 10) expectedObject := createObject(ctx, t, db, obj, 10)
@ -159,7 +159,7 @@ func TestListSegments(t *testing.T) {
}.Check(ctx, t, db) }.Check(ctx, t, db)
}) })
t.Run("List segments from unordered parts", func(t *testing.T) { t.Run("unordered parts", func(t *testing.T) {
defer DeleteAll{}.Check(ctx, t, db) defer DeleteAll{}.Check(ctx, t, db)
var testCases = []struct { var testCases = []struct {
@ -303,7 +303,7 @@ func TestListStreamPositions(t *testing.T) {
Verify{}.Check(ctx, t, db) Verify{}.Check(ctx, t, db)
}) })
t.Run("List no segments", func(t *testing.T) { t.Run("no segments", func(t *testing.T) {
defer DeleteAll{}.Check(ctx, t, db) defer DeleteAll{}.Check(ctx, t, db)
ListStreamPositions{ ListStreamPositions{
@ -317,7 +317,7 @@ func TestListStreamPositions(t *testing.T) {
Verify{}.Check(ctx, t, db) Verify{}.Check(ctx, t, db)
}) })
t.Run("List segments", func(t *testing.T) { t.Run("segments", func(t *testing.T) {
defer DeleteAll{}.Check(ctx, t, db) defer DeleteAll{}.Check(ctx, t, db)
expectedObject := createObject(ctx, t, db, obj, 10) expectedObject := createObject(ctx, t, db, obj, 10)
@ -346,6 +346,7 @@ func TestListStreamPositions(t *testing.T) {
expectedSegments[i] = metabase.SegmentPositionInfo{ expectedSegments[i] = metabase.SegmentPositionInfo{
Position: expectedSegment.Position, Position: expectedSegment.Position,
PlainSize: expectedSegment.PlainSize, PlainSize: expectedSegment.PlainSize,
PlainOffset: expectedSegment.PlainOffset,
CreatedAt: &now, CreatedAt: &now,
EncryptedKey: expectedSegment.EncryptedKey, EncryptedKey: expectedSegment.EncryptedKey,
EncryptedKeyNonce: expectedSegment.EncryptedKeyNonce, EncryptedKeyNonce: expectedSegment.EncryptedKeyNonce,
@ -424,7 +425,7 @@ func TestListStreamPositions(t *testing.T) {
}.Check(ctx, t, db) }.Check(ctx, t, db)
}) })
t.Run("List segments from unordered parts", func(t *testing.T) { t.Run("unordered parts", func(t *testing.T) {
defer DeleteAll{}.Check(ctx, t, db) defer DeleteAll{}.Check(ctx, t, db)
var testCases = []struct { var testCases = []struct {
@ -512,18 +513,20 @@ func TestListStreamPositions(t *testing.T) {
}.Check(ctx, t, db) }.Check(ctx, t, db)
expectedSegments := make([]metabase.SegmentPositionInfo, 4) expectedSegments := make([]metabase.SegmentPositionInfo, 4)
expectedOffset := int64(0)
for i := range expectedSegments { for i := range expectedSegments {
pos := expectedSegment.Position pos := expectedSegment.Position
pos.Part = uint32(i) pos.Part = uint32(i)
expectedSegments[i] = metabase.SegmentPositionInfo{ expectedSegments[i] = metabase.SegmentPositionInfo{
Position: pos, Position: pos,
PlainSize: expectedSegment.PlainSize, PlainSize: expectedSegment.PlainSize,
PlainOffset: expectedOffset,
CreatedAt: &now, CreatedAt: &now,
EncryptedKey: expectedSegment.EncryptedKey, EncryptedKey: expectedSegment.EncryptedKey,
EncryptedKeyNonce: expectedSegment.EncryptedKeyNonce, EncryptedKeyNonce: expectedSegment.EncryptedKeyNonce,
EncryptedETag: expectedSegment.EncryptedETag, EncryptedETag: expectedSegment.EncryptedETag,
} }
expectedSegment.PlainOffset += int64(expectedSegment.PlainSize) expectedOffset += int64(expectedSegment.PlainSize)
} }
ListStreamPositions{ ListStreamPositions{

View File

@ -1686,6 +1686,7 @@ func (endpoint *Endpoint) ListSegments(ctx context.Context, req *pb.SegmentListR
Index: int32(item.Position.Index), Index: int32(item.Position.Index),
}, },
PlainSize: int64(item.PlainSize), PlainSize: int64(item.PlainSize),
PlainOffset: item.PlainOffset,
} }
if item.CreatedAt != nil { if item.CreatedAt != nil {
items[i].CreatedAt = *item.CreatedAt items[i].CreatedAt = *item.CreatedAt