2020-12-11 12:09:59 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metabase_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-03-17 10:31:07 +00:00
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
"github.com/google/go-cmp/cmp/cmpopts"
|
2020-12-11 12:09:59 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-12-21 10:48:48 +00:00
|
|
|
"storj.io/common/storj"
|
2020-12-11 12:09:59 +00:00
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2021-04-26 10:35:44 +01:00
|
|
|
"storj.io/storj/satellite/metabase/metabasetest"
|
2020-12-11 12:09:59 +00:00
|
|
|
"storj.io/storj/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUpdateSegmentPieces(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-12-11 12:09:59 +00:00
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
2020-12-21 10:48:48 +00:00
|
|
|
validPieces := []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}}
|
|
|
|
|
2020-12-11 12:09:59 +00:00
|
|
|
t.Run("StreamID missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-11 12:09:59 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2020-12-11 12:09:59 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "StreamID missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2020-12-21 10:48:48 +00:00
|
|
|
t.Run("OldPieces missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-11 12:09:59 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2020-12-11 12:09:59 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
2020-12-21 10:48:48 +00:00
|
|
|
ErrText: "OldPieces: pieces missing",
|
2020-12-11 12:09:59 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2020-12-21 10:48:48 +00:00
|
|
|
t.Run("OldPieces: piece number 1 is missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-11 12:09:59 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2020-12-11 12:09:59 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{
|
|
|
|
StreamID: obj.StreamID,
|
2020-12-21 10:48:48 +00:00
|
|
|
OldPieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: storj.NodeID{},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "OldPieces: piece number 1 is missing storage node id",
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("OldPieces: duplicated piece number 1", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2020-12-21 10:48:48 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
OldPieces: []metabase.Piece{
|
|
|
|
{
|
2020-12-11 12:09:59 +00:00
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
2020-12-21 10:48:48 +00:00
|
|
|
{
|
2020-12-11 12:09:59 +00:00
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-12-21 10:48:48 +00:00
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "OldPieces: duplicated piece number 1",
|
2020-12-11 12:09:59 +00:00
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-11 12:09:59 +00:00
|
|
|
})
|
|
|
|
|
2020-12-21 10:48:48 +00:00
|
|
|
t.Run("OldPieces: pieces should be ordered", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-11 12:09:59 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2020-12-21 10:48:48 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
OldPieces: []metabase.Piece{
|
|
|
|
{
|
|
|
|
Number: 2,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "OldPieces: pieces should be ordered",
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
})
|
|
|
|
|
2021-03-12 11:23:44 +00:00
|
|
|
t.Run("NewRedundancy zero", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-11 12:09:59 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2020-12-11 12:09:59 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{
|
|
|
|
StreamID: obj.StreamID,
|
2020-12-21 10:48:48 +00:00
|
|
|
OldPieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
2021-03-12 11:23:44 +00:00
|
|
|
ErrText: "NewRedundancy zero",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("NewPieces vs NewRedundancy", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-03-12 11:23:44 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2021-03-12 11:23:44 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
OldPieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
2021-04-26 10:35:44 +01:00
|
|
|
NewRedundancy: metabasetest.DefaultRedundancy,
|
2021-03-12 11:23:44 +00:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "number of new pieces is less than new redundancy repair shares value",
|
2020-12-21 10:48:48 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("NewPieces: piece number 1 is missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2020-12-21 10:48:48 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{
|
2021-03-12 11:23:44 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
OldPieces: validPieces,
|
2021-04-26 10:35:44 +01:00
|
|
|
NewRedundancy: metabasetest.DefaultRedundancy,
|
2020-12-21 10:48:48 +00:00
|
|
|
NewPieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: storj.NodeID{},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "NewPieces: piece number 1 is missing storage node id",
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("NewPieces: duplicated piece number 1", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2020-12-21 10:48:48 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{
|
2021-03-12 11:23:44 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
OldPieces: validPieces,
|
2021-04-26 10:35:44 +01:00
|
|
|
NewRedundancy: metabasetest.DefaultRedundancy,
|
2020-12-21 10:48:48 +00:00
|
|
|
NewPieces: []metabase.Piece{
|
|
|
|
{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
{
|
2020-12-11 12:09:59 +00:00
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
},
|
2020-12-21 10:48:48 +00:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "NewPieces: duplicated piece number 1",
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("NewPieces: pieces should be ordered", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2020-12-21 10:48:48 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{
|
2021-03-12 11:23:44 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
OldPieces: validPieces,
|
2021-04-26 10:35:44 +01:00
|
|
|
NewRedundancy: metabasetest.DefaultRedundancy,
|
2020-12-21 10:48:48 +00:00
|
|
|
NewPieces: []metabase.Piece{
|
|
|
|
{
|
|
|
|
Number: 2,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "NewPieces: pieces should be ordered",
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("segment not found", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2020-12-21 10:48:48 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{
|
2021-03-12 11:23:44 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Index: 1},
|
|
|
|
OldPieces: validPieces,
|
2021-04-26 10:35:44 +01:00
|
|
|
NewRedundancy: metabasetest.DefaultRedundancy,
|
2021-03-12 11:23:44 +00:00
|
|
|
NewPieces: validPieces,
|
2020-12-21 10:48:48 +00:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrSegmentNotFound,
|
|
|
|
ErrText: "segment missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("segment pieces column was changed", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
obj := metabasetest.CreateObject(ctx, t, db, obj, 1)
|
2021-03-12 11:23:44 +00:00
|
|
|
|
|
|
|
newRedundancy := storj.RedundancyScheme{
|
|
|
|
RequiredShares: 1,
|
|
|
|
RepairShares: 1,
|
|
|
|
OptimalShares: 1,
|
|
|
|
TotalShares: 4,
|
|
|
|
}
|
2020-12-21 10:48:48 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2020-12-21 10:48:48 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{
|
2021-03-12 11:23:44 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Index: 0},
|
|
|
|
OldPieces: validPieces,
|
|
|
|
NewRedundancy: newRedundancy,
|
2020-12-11 12:09:59 +00:00
|
|
|
NewPieces: metabase.Pieces{
|
|
|
|
metabase.Piece{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ErrClass: &storage.ErrValueChanged,
|
2021-02-08 09:33:45 +00:00
|
|
|
ErrText: "segment remote_alias_pieces field was changed",
|
2020-12-11 12:09:59 +00:00
|
|
|
}.Check(ctx, t, db)
|
2021-03-12 11:23:44 +00:00
|
|
|
|
|
|
|
// verify that original pieces and redundancy did not change
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2021-03-12 11:23:44 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(obj),
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2021-03-12 11:23:44 +00:00
|
|
|
EncryptedKey: []byte{3},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: []byte{4},
|
2021-03-25 07:53:10 +00:00
|
|
|
EncryptedETag: []byte{5},
|
2021-03-12 11:23:44 +00:00
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainOffset: 0,
|
|
|
|
PlainSize: 512,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2021-03-12 11:23:44 +00:00
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
2020-12-11 12:09:59 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("update pieces", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-11 12:09:59 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object := metabasetest.CreateObject(ctx, t, db, obj, 1)
|
2020-12-11 12:09:59 +00:00
|
|
|
|
|
|
|
segment, err := db.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
|
|
|
StreamID: object.StreamID,
|
2021-01-25 11:23:43 +00:00
|
|
|
Position: metabase.SegmentPosition{Index: 0},
|
2020-12-11 12:09:59 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
expectedPieces := metabase.Pieces{
|
|
|
|
metabase.Piece{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
metabase.Piece{
|
|
|
|
Number: 2,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2020-12-11 12:09:59 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{
|
2021-03-12 11:23:44 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Index: 0},
|
|
|
|
OldPieces: segment.Pieces,
|
2021-04-26 10:35:44 +01:00
|
|
|
NewRedundancy: metabasetest.DefaultRedundancy,
|
2021-03-12 11:23:44 +00:00
|
|
|
NewPieces: expectedPieces,
|
2020-12-11 12:09:59 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
expectedSegment := segment
|
|
|
|
expectedSegment.Pieces = expectedPieces
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-12-11 12:09:59 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
TotalPlainSize: 512,
|
|
|
|
TotalEncryptedSize: 1024,
|
2021-01-14 11:47:29 +00:00
|
|
|
FixedSegmentSize: 512,
|
2020-12-11 12:09:59 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-12-11 12:09:59 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
metabase.RawSegment(expectedSegment),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2021-03-17 10:20:21 +00:00
|
|
|
|
|
|
|
t.Run("update pieces and repair at", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-03-17 10:20:21 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object := metabasetest.CreateObject(ctx, t, db, obj, 1)
|
2021-03-17 10:20:21 +00:00
|
|
|
|
|
|
|
segment, err := db.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
|
|
|
StreamID: object.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Index: 0},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
expectedPieces := metabase.Pieces{
|
|
|
|
metabase.Piece{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
metabase.Piece{
|
|
|
|
Number: 2,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
repairedAt := now.Add(time.Hour)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.UpdateSegmentPieces{
|
2021-03-17 10:20:21 +00:00
|
|
|
Opts: metabase.UpdateSegmentPieces{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Index: 0},
|
|
|
|
OldPieces: segment.Pieces,
|
2021-03-17 10:31:07 +00:00
|
|
|
NewRedundancy: segment.Redundancy,
|
2021-03-17 10:20:21 +00:00
|
|
|
NewPieces: expectedPieces,
|
|
|
|
NewRepairedAt: repairedAt,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
expectedSegment := segment
|
|
|
|
expectedSegment.Pieces = expectedPieces
|
|
|
|
expectedSegment.RepairedAt = &repairedAt
|
2021-03-17 10:31:07 +00:00
|
|
|
|
|
|
|
segment, err = db.GetSegmentByLocation(ctx, metabase.GetSegmentByLocation{
|
|
|
|
SegmentLocation: metabase.SegmentLocation{
|
|
|
|
ProjectID: object.ProjectID,
|
|
|
|
BucketName: object.BucketName,
|
|
|
|
ObjectKey: object.ObjectKey,
|
|
|
|
Position: metabase.SegmentPosition{Index: 0},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
diff := cmp.Diff(expectedSegment, segment, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
|
|
|
|
segment, err = db.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
|
|
|
StreamID: object.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Index: 0},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
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)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2021-03-17 10:20:21 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
TotalPlainSize: 512,
|
|
|
|
TotalEncryptedSize: 1024,
|
|
|
|
FixedSegmentSize: 512,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-03-17 10:20:21 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
metabase.RawSegment(expectedSegment),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2020-12-11 12:09:59 +00:00
|
|
|
})
|
|
|
|
}
|