2019-12-17 16:23:00 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
// +build race
|
|
|
|
|
|
|
|
package metainfo
|
|
|
|
|
|
|
|
import (
|
2020-09-03 14:54:56 +01:00
|
|
|
"bytes"
|
|
|
|
|
2019-12-17 16:23:00 +00:00
|
|
|
"storj.io/common/pb"
|
2020-09-03 14:54:56 +01:00
|
|
|
"storj.io/storj/satellite/metainfo/metabase"
|
2019-12-17 16:23:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// sanityCheckPointer implements sanity checking test data,
|
|
|
|
// we don't need this in production code.
|
2020-09-03 14:54:56 +01:00
|
|
|
func sanityCheckPointer(key metabase.SegmentKey, pointer *pb.Pointer) (err error) {
|
|
|
|
tokens := bytes.Split(key, []byte("/"))
|
2019-12-17 16:23:00 +00:00
|
|
|
if len(tokens) <= 3 {
|
2020-09-03 14:54:56 +01:00
|
|
|
return Error.New("invalid path %s", key)
|
2019-12-17 16:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if pointer.Type == pb.Pointer_REMOTE {
|
|
|
|
remote := pointer.Remote
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case remote.RootPieceId.IsZero():
|
|
|
|
return Error.New("piece id zero")
|
|
|
|
case remote == nil:
|
|
|
|
return Error.New("no remote segment specified")
|
|
|
|
case remote.RemotePieces == nil:
|
|
|
|
return Error.New("no remote segment pieces specified")
|
|
|
|
case remote.Redundancy == nil:
|
|
|
|
return Error.New("no redundancy scheme specified")
|
|
|
|
}
|
|
|
|
|
|
|
|
redundancy := remote.Redundancy
|
|
|
|
if redundancy.MinReq <= 0 || redundancy.Total <= 0 ||
|
|
|
|
redundancy.RepairThreshold <= 0 || redundancy.SuccessThreshold <= 0 ||
|
|
|
|
redundancy.ErasureShareSize <= 0 {
|
|
|
|
return Error.New("invalid redundancy: %+v", redundancy)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, piece := range remote.GetRemotePieces() {
|
|
|
|
if int(piece.PieceNum) >= int(redundancy.Total) {
|
|
|
|
return Error.New("invalid PieceNum=%v total=%v", piece.PieceNum, redundancy.Total)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|