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

View File

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

View File

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