satellite/metainfo/metabase: pieces vs redundancy scheme validation while commiting segment

Additional validation for pieces based on RS.

Change-Id: Ib25bfc0e38ca78e2c3194a3223d59257489049fb
This commit is contained in:
Michał Niewrzał 2021-03-11 15:52:53 +01:00 committed by Michal Niewrzal
parent 018b0684b8
commit 887f3b04e1
2 changed files with 33 additions and 5 deletions

View File

@ -255,7 +255,9 @@ func (db *DB) CommitSegment(ctx context.Context, opts CommitSegment) (err error)
return ErrInvalidRequest.New("Redundancy zero")
}
// TODO: verify opts.Pieces is compatible with opts.Redundancy
if len(opts.Pieces) < int(opts.Redundancy.OptimalShares) {
return ErrInvalidRequest.New("number of pieces is less than redundancy optimal shares value")
}
aliasPieces, err := db.aliasCache.ConvertPiecesToAliases(ctx, opts.Pieces)
if err != nil {

View File

@ -20,10 +20,10 @@ import (
var defaultTestRedundancy = storj.RedundancyScheme{
Algorithm: storj.ReedSolomon,
ShareSize: 2048,
RequiredShares: 4,
RepairShares: 5,
OptimalShares: 6,
TotalShares: 7,
RequiredShares: 1,
RepairShares: 1,
OptimalShares: 1,
TotalShares: 1,
}
var defaultTestEncryption = storj.EncryptionParameters{
@ -1145,6 +1145,32 @@ func TestCommitSegment(t *testing.T) {
ErrText: "Redundancy zero",
}.Check(ctx, t, db)
redundancy := storj.RedundancyScheme{
OptimalShares: 2,
}
CommitSegment{
Opts: metabase.CommitSegment{
ObjectStream: obj,
Pieces: []metabase.Piece{
{
Number: 1,
StorageNode: testrand.NodeID(),
},
},
RootPieceID: testrand.PieceID(),
Redundancy: redundancy,
EncryptedKey: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Bytes(32),
EncryptedSize: 1024,
PlainSize: 512,
PlainOffset: 0,
},
ErrClass: &metabase.ErrInvalidRequest,
ErrText: "number of pieces is less than redundancy optimal shares value",
}.Check(ctx, t, db)
Verify{
Objects: []metabase.RawObject{
{