2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-12-13 07:12:36 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-07-29 12:24:56 +01:00
|
|
|
package repairer
|
2018-12-13 07:12:36 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-14 16:05:42 +01:00
|
|
|
"errors"
|
2020-02-24 20:13:12 +00:00
|
|
|
"fmt"
|
2022-02-13 04:19:29 +00:00
|
|
|
"io"
|
2019-07-11 23:44:47 +01:00
|
|
|
"math"
|
2022-09-19 22:16:48 +01:00
|
|
|
"strings"
|
2019-03-19 13:14:59 +00:00
|
|
|
"time"
|
2018-12-13 07:12:36 +00:00
|
|
|
|
2019-01-29 20:42:27 +00:00
|
|
|
"github.com/zeebo/errs"
|
2019-07-02 11:08:02 +01:00
|
|
|
"go.uber.org/zap"
|
2019-01-29 20:42:27 +00:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/pb"
|
|
|
|
"storj.io/common/storj"
|
2023-06-30 10:02:01 +01:00
|
|
|
"storj.io/common/storj/location"
|
2022-02-13 04:19:29 +00:00
|
|
|
"storj.io/common/sync2"
|
2021-08-03 14:21:27 +01:00
|
|
|
"storj.io/storj/satellite/audit"
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2019-03-28 20:09:23 +00:00
|
|
|
"storj.io/storj/satellite/orders"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
2022-12-13 20:40:15 +00:00
|
|
|
"storj.io/storj/satellite/repair"
|
2020-10-27 18:26:46 +00:00
|
|
|
"storj.io/storj/satellite/repair/checker"
|
2021-06-17 16:05:04 +01:00
|
|
|
"storj.io/storj/satellite/repair/queue"
|
2020-02-21 14:07:29 +00:00
|
|
|
"storj.io/uplink/private/eestream"
|
2022-02-13 04:19:29 +00:00
|
|
|
"storj.io/uplink/private/piecestore"
|
2018-12-13 07:12:36 +00:00
|
|
|
)
|
|
|
|
|
2020-02-24 20:13:12 +00:00
|
|
|
var (
|
2021-04-28 09:06:17 +01:00
|
|
|
metainfoGetError = errs.Class("metainfo db get")
|
|
|
|
metainfoPutError = errs.Class("metainfo db put")
|
2020-02-24 20:13:12 +00:00
|
|
|
invalidRepairError = errs.Class("invalid repair")
|
|
|
|
overlayQueryError = errs.Class("overlay query failure")
|
|
|
|
orderLimitFailureError = errs.Class("order limits failure")
|
|
|
|
repairReconstructError = errs.Class("repair reconstruction failure")
|
|
|
|
repairPutError = errs.Class("repair could not store repaired pieces")
|
2021-08-03 14:21:27 +01:00
|
|
|
// segmentVerificationError is the errs class when the repaired segment can not be verified during repair.
|
|
|
|
segmentVerificationError = errs.Class("segment verification failed")
|
|
|
|
// segmentDeletedError is the errs class when the repaired segment was deleted during the repair.
|
|
|
|
segmentDeletedError = errs.Class("segment deleted during repair")
|
|
|
|
// segmentModifiedError is the errs class used when a segment has been changed in any way.
|
|
|
|
segmentModifiedError = errs.Class("segment has been modified")
|
2020-02-24 20:13:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// irreparableError identifies situations where a segment could not be repaired due to reasons
|
|
|
|
// which are hopefully transient (e.g. too many pieces unavailable). The segment should be added
|
|
|
|
// to the irreparableDB.
|
|
|
|
type irreparableError struct {
|
|
|
|
piecesAvailable int32
|
|
|
|
piecesRequired int32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ie *irreparableError) Error() string {
|
|
|
|
return fmt.Sprintf("%d available pieces < %d required", ie.piecesAvailable, ie.piecesRequired)
|
|
|
|
}
|
2019-07-30 16:38:25 +01:00
|
|
|
|
2022-09-19 22:16:48 +01:00
|
|
|
// PieceFetchResult combines a piece pointer with the error we got when we tried
|
|
|
|
// to acquire that piece.
|
|
|
|
type PieceFetchResult struct {
|
|
|
|
Piece metabase.Piece
|
|
|
|
Err error
|
|
|
|
}
|
|
|
|
|
2022-09-19 22:13:43 +01:00
|
|
|
// FetchResultReport contains a categorization of a set of pieces based on the results of
|
|
|
|
// GET operations.
|
|
|
|
type FetchResultReport struct {
|
2022-09-19 22:16:48 +01:00
|
|
|
Successful []PieceFetchResult
|
|
|
|
Failed []PieceFetchResult
|
|
|
|
Offline []PieceFetchResult
|
|
|
|
Contained []PieceFetchResult
|
|
|
|
Unknown []PieceFetchResult
|
2022-09-19 22:13:43 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// SegmentRepairer for segments.
|
2019-07-29 12:24:56 +01:00
|
|
|
type SegmentRepairer struct {
|
2021-02-03 22:22:46 +00:00
|
|
|
log *zap.Logger
|
|
|
|
statsCollector *statsCollector
|
2021-05-13 09:14:18 +01:00
|
|
|
metabase *metabase.DB
|
2021-02-03 22:22:46 +00:00
|
|
|
orders *orders.Service
|
|
|
|
overlay *overlay.Service
|
|
|
|
ec *ECRepairer
|
|
|
|
timeout time.Duration
|
2022-04-11 17:47:14 +01:00
|
|
|
reporter audit.Reporter
|
2019-07-11 23:44:47 +01:00
|
|
|
|
2022-11-24 13:02:08 +00:00
|
|
|
reputationUpdateEnabled bool
|
2023-05-18 19:47:23 +01:00
|
|
|
doDeclumping bool
|
2023-05-26 13:22:15 +01:00
|
|
|
doPlacementCheck bool
|
2022-11-24 13:02:08 +00:00
|
|
|
|
2019-07-11 23:44:47 +01:00
|
|
|
// multiplierOptimalThreshold is the value that multiplied by the optimal
|
|
|
|
// threshold results in the maximum limit of number of nodes to upload
|
|
|
|
// repaired pieces
|
|
|
|
multiplierOptimalThreshold float64
|
2019-10-02 13:58:37 +01:00
|
|
|
|
2020-10-27 18:26:46 +00:00
|
|
|
// repairOverrides is the set of values configured by the checker to override the repair threshold for various RS schemes.
|
|
|
|
repairOverrides checker.RepairOverridesMap
|
2020-12-18 08:49:31 +00:00
|
|
|
|
2023-06-30 10:02:01 +01:00
|
|
|
excludedCountryCodes map[location.CountryCode]struct{}
|
|
|
|
|
2021-08-03 14:21:27 +01:00
|
|
|
nowFn func() time.Time
|
|
|
|
OnTestingCheckSegmentAlteredHook func()
|
2022-09-19 22:13:43 +01:00
|
|
|
OnTestingPiecesReportHook func(pieces FetchResultReport)
|
2023-07-06 13:35:26 +01:00
|
|
|
placementRules overlay.PlacementRules
|
2018-12-13 07:12:36 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 23:44:47 +01:00
|
|
|
// NewSegmentRepairer creates a new instance of SegmentRepairer.
|
|
|
|
//
|
|
|
|
// excessPercentageOptimalThreshold is the percentage to apply over the optimal
|
|
|
|
// threshould to determine the maximum limit of nodes to upload repaired pieces,
|
|
|
|
// when negative, 0 is applied.
|
|
|
|
func NewSegmentRepairer(
|
2021-08-03 14:21:27 +01:00
|
|
|
log *zap.Logger,
|
|
|
|
metabase *metabase.DB,
|
|
|
|
orders *orders.Service,
|
|
|
|
overlay *overlay.Service,
|
2022-04-11 17:47:14 +01:00
|
|
|
reporter audit.Reporter,
|
2021-08-03 14:21:27 +01:00
|
|
|
ecRepairer *ECRepairer,
|
2023-07-06 13:35:26 +01:00
|
|
|
placementRules overlay.PlacementRules,
|
2021-08-03 14:21:27 +01:00
|
|
|
repairOverrides checker.RepairOverrides,
|
2022-11-24 13:02:08 +00:00
|
|
|
config Config,
|
2019-07-29 12:24:56 +01:00
|
|
|
) *SegmentRepairer {
|
2019-07-11 23:44:47 +01:00
|
|
|
|
2022-11-24 13:02:08 +00:00
|
|
|
excessOptimalThreshold := config.MaxExcessRateOptimalThreshold
|
2019-07-11 23:44:47 +01:00
|
|
|
if excessOptimalThreshold < 0 {
|
|
|
|
excessOptimalThreshold = 0
|
|
|
|
}
|
|
|
|
|
2023-06-30 10:02:01 +01:00
|
|
|
excludedCountryCodes := make(map[location.CountryCode]struct{})
|
|
|
|
for _, countryCode := range config.RepairExcludedCountryCodes {
|
|
|
|
if cc := location.ToCountryCode(countryCode); cc != location.None {
|
|
|
|
excludedCountryCodes[cc] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-29 12:24:56 +01:00
|
|
|
return &SegmentRepairer{
|
2019-07-11 23:44:47 +01:00
|
|
|
log: log,
|
2021-02-03 22:22:46 +00:00
|
|
|
statsCollector: newStatsCollector(),
|
2020-12-14 14:29:48 +00:00
|
|
|
metabase: metabase,
|
2019-07-11 23:44:47 +01:00
|
|
|
orders: orders,
|
2019-08-06 17:35:59 +01:00
|
|
|
overlay: overlay,
|
2021-08-03 14:21:27 +01:00
|
|
|
ec: ecRepairer,
|
2022-11-24 13:02:08 +00:00
|
|
|
timeout: config.Timeout,
|
2019-07-11 23:44:47 +01:00
|
|
|
multiplierOptimalThreshold: 1 + excessOptimalThreshold,
|
2020-10-27 18:26:46 +00:00
|
|
|
repairOverrides: repairOverrides.GetMap(),
|
2023-06-30 10:02:01 +01:00
|
|
|
excludedCountryCodes: excludedCountryCodes,
|
2021-08-03 14:21:27 +01:00
|
|
|
reporter: reporter,
|
2022-11-24 13:02:08 +00:00
|
|
|
reputationUpdateEnabled: config.ReputationUpdateEnabled,
|
2023-05-18 19:47:23 +01:00
|
|
|
doDeclumping: config.DoDeclumping,
|
2023-05-26 13:22:15 +01:00
|
|
|
doPlacementCheck: config.DoPlacementCheck,
|
2023-07-06 13:35:26 +01:00
|
|
|
placementRules: placementRules,
|
2020-12-18 08:49:31 +00:00
|
|
|
|
|
|
|
nowFn: time.Now,
|
2019-03-18 10:55:06 +00:00
|
|
|
}
|
2018-12-13 07:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Repair retrieves an at-risk segment and repairs and stores lost pieces on new nodes
|
2019-08-05 16:09:16 +01:00
|
|
|
// note that shouldDelete is used even in the case where err is not null
|
2020-07-16 15:18:02 +01:00
|
|
|
// note that it will update audit status as failed for nodes that failed piece hash verification during repair downloading.
|
2021-06-17 16:05:04 +01:00
|
|
|
func (repairer *SegmentRepairer) Repair(ctx context.Context, queueSegment *queue.InjuredSegment) (shouldDelete bool, err error) {
|
|
|
|
defer mon.Task()(&ctx, queueSegment.StreamID.String(), queueSegment.Position.Encode())(&err)
|
2018-12-13 07:12:36 +00:00
|
|
|
|
2021-06-17 16:05:04 +01:00
|
|
|
segment, err := repairer.metabase.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
|
|
|
StreamID: queueSegment.StreamID,
|
|
|
|
Position: queueSegment.Position,
|
2020-12-14 14:29:48 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-06-17 16:05:04 +01:00
|
|
|
if metabase.ErrSegmentNotFound.Has(err) {
|
2020-12-14 14:29:48 +00:00
|
|
|
mon.Meter("repair_unnecessary").Mark(1) //mon:locked
|
|
|
|
mon.Meter("segment_deleted_before_repair").Mark(1) //mon:locked
|
|
|
|
repairer.log.Debug("segment was deleted")
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
return false, metainfoGetError.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if segment.Inline() {
|
2020-02-24 20:13:12 +00:00
|
|
|
return true, invalidRepairError.New("cannot repair inline segment")
|
2018-12-13 07:12:36 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 23:38:53 +01:00
|
|
|
// ignore segment if expired
|
|
|
|
if segment.Expired(repairer.nowFn()) {
|
2022-09-19 22:16:48 +01:00
|
|
|
mon.Meter("repair_unnecessary").Mark(1)
|
|
|
|
mon.Meter("segment_expired_before_repair").Mark(1)
|
2021-10-15 23:38:53 +01:00
|
|
|
repairer.log.Debug("segment has expired", zap.Stringer("Stream ID", segment.StreamID), zap.Uint64("Position", queueSegment.Position.Encode()))
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2020-12-14 14:29:48 +00:00
|
|
|
redundancy, err := eestream.NewRedundancyStrategyFromStorj(segment.Redundancy)
|
2018-12-13 07:12:36 +00:00
|
|
|
if err != nil {
|
2020-02-24 20:13:12 +00:00
|
|
|
return true, invalidRepairError.New("invalid redundancy strategy: %w", err)
|
2018-12-13 07:12:36 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 10:46:16 +00:00
|
|
|
stats := repairer.getStatsByRS(&pb.RedundancyScheme{
|
|
|
|
Type: pb.RedundancyScheme_SchemeType(segment.Redundancy.Algorithm),
|
|
|
|
ErasureShareSize: segment.Redundancy.ShareSize,
|
|
|
|
MinReq: int32(segment.Redundancy.RequiredShares),
|
|
|
|
RepairThreshold: int32(segment.Redundancy.RepairShares),
|
|
|
|
SuccessThreshold: int32(segment.Redundancy.OptimalShares),
|
|
|
|
Total: int32(segment.Redundancy.TotalShares),
|
|
|
|
})
|
2021-02-03 22:22:46 +00:00
|
|
|
|
|
|
|
mon.Meter("repair_attempts").Mark(1) //mon:locked
|
|
|
|
stats.repairAttempts.Mark(1)
|
2021-02-11 10:46:16 +00:00
|
|
|
mon.IntVal("repair_segment_size").Observe(int64(segment.EncryptedSize)) //mon:locked
|
|
|
|
stats.repairSegmentSize.Observe(int64(segment.EncryptedSize))
|
2021-02-03 22:22:46 +00:00
|
|
|
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
allNodeIDs := make([]storj.NodeID, len(segment.Pieces))
|
|
|
|
for i, p := range segment.Pieces {
|
|
|
|
allNodeIDs[i] = p.StorageNode
|
2023-05-26 13:22:15 +01:00
|
|
|
}
|
|
|
|
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
selectedNodes, err := repairer.overlay.GetNodes(ctx, allNodeIDs)
|
|
|
|
if err != nil {
|
|
|
|
return false, overlayQueryError.New("error identifying missing pieces: %w", err)
|
|
|
|
}
|
|
|
|
if len(selectedNodes) != len(segment.Pieces) {
|
|
|
|
repairer.log.Error("GetNodes returned an invalid result", zap.Any("pieces", segment.Pieces), zap.Any("selectedNodes", selectedNodes), zap.Error(err))
|
|
|
|
return false, overlayQueryError.New("GetNodes returned an invalid result")
|
|
|
|
}
|
2023-06-26 10:54:52 +01:00
|
|
|
pieces := segment.Pieces
|
2023-10-06 10:14:35 +01:00
|
|
|
piecesCheck := repair.ClassifySegmentPieces(pieces, selectedNodes, repairer.excludedCountryCodes, repairer.doPlacementCheck, repairer.doDeclumping, repairer.placementRules(segment.Placement), allNodeIDs)
|
2022-12-13 20:40:15 +00:00
|
|
|
|
2022-09-19 22:16:48 +01:00
|
|
|
// irreparable segment
|
2023-10-06 10:53:48 +01:00
|
|
|
if piecesCheck.Retrievable.Size() < int(segment.Redundancy.RequiredShares) {
|
2020-11-10 14:49:19 +00:00
|
|
|
mon.Counter("repairer_segments_below_min_req").Inc(1) //mon:locked
|
2021-02-03 22:22:46 +00:00
|
|
|
stats.repairerSegmentsBelowMinReq.Inc(1)
|
|
|
|
mon.Meter("repair_nodes_unavailable").Mark(1) //mon:locked
|
|
|
|
stats.repairerNodesUnavailable.Mark(1)
|
2021-06-15 22:45:31 +01:00
|
|
|
|
|
|
|
repairer.log.Warn("irreparable segment",
|
2021-06-17 16:05:04 +01:00
|
|
|
zap.String("StreamID", queueSegment.StreamID.String()),
|
|
|
|
zap.Uint64("Position", queueSegment.Position.Encode()),
|
2023-10-06 10:53:48 +01:00
|
|
|
zap.Int("piecesAvailable", piecesCheck.Retrievable.Size()),
|
2021-06-15 22:45:31 +01:00
|
|
|
zap.Int16("piecesRequired", segment.Redundancy.RequiredShares),
|
|
|
|
)
|
|
|
|
return false, nil
|
2019-05-16 14:49:10 +01:00
|
|
|
}
|
|
|
|
|
2020-11-10 14:49:19 +00:00
|
|
|
// ensure we get values, even if only zero values, so that redash can have an alert based on this
|
|
|
|
mon.Counter("repairer_segments_below_min_req").Inc(0) //mon:locked
|
2021-02-03 22:22:46 +00:00
|
|
|
stats.repairerSegmentsBelowMinReq.Inc(0)
|
2020-11-10 14:49:19 +00:00
|
|
|
|
2020-12-14 14:29:48 +00:00
|
|
|
repairThreshold := int32(segment.Redundancy.RepairShares)
|
|
|
|
|
|
|
|
pbRedundancy := &pb.RedundancyScheme{
|
|
|
|
MinReq: int32(segment.Redundancy.RequiredShares),
|
|
|
|
RepairThreshold: int32(segment.Redundancy.RepairShares),
|
|
|
|
SuccessThreshold: int32(segment.Redundancy.OptimalShares),
|
|
|
|
Total: int32(segment.Redundancy.TotalShares),
|
|
|
|
}
|
|
|
|
overrideValue := repairer.repairOverrides.GetOverrideValuePB(pbRedundancy)
|
2020-10-27 18:26:46 +00:00
|
|
|
if overrideValue != 0 {
|
|
|
|
repairThreshold = overrideValue
|
2019-10-02 13:58:37 +01:00
|
|
|
}
|
|
|
|
|
2023-10-06 10:53:48 +01:00
|
|
|
if piecesCheck.Healthy.Size() > int(repairThreshold) {
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
// No repair is needed (note Healthy does not include pieces in ForcingRepair).
|
2023-06-26 10:54:52 +01:00
|
|
|
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
var dropPieces metabase.Pieces
|
2023-10-06 10:53:48 +01:00
|
|
|
if piecesCheck.ForcingRepair.Size() > 0 {
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
// No repair is needed, but remove forcing-repair pieces without a repair operation,
|
|
|
|
// as we will still be above the repair threshold.
|
2023-06-26 10:54:52 +01:00
|
|
|
for _, piece := range pieces {
|
2023-10-06 10:53:48 +01:00
|
|
|
if piecesCheck.ForcingRepair.Contains(int(piece.Number)) {
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
dropPieces = append(dropPieces, piece)
|
2023-06-26 10:54:52 +01:00
|
|
|
}
|
|
|
|
}
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
if len(dropPieces) > 0 {
|
|
|
|
newPieces, err := segment.Pieces.Update(nil, dropPieces)
|
|
|
|
if err != nil {
|
|
|
|
return false, metainfoPutError.Wrap(err)
|
|
|
|
}
|
2023-06-26 10:54:52 +01:00
|
|
|
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
err = repairer.metabase.UpdateSegmentPieces(ctx, metabase.UpdateSegmentPieces{
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
2023-05-26 13:22:15 +01:00
|
|
|
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
OldPieces: segment.Pieces,
|
|
|
|
NewRedundancy: segment.Redundancy,
|
|
|
|
NewPieces: newPieces,
|
2023-05-26 13:22:15 +01:00
|
|
|
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
NewRepairedAt: time.Now(),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return false, metainfoPutError.Wrap(err)
|
|
|
|
}
|
2023-05-26 13:22:15 +01:00
|
|
|
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
mon.Meter("dropped_undesirable_pieces_without_repair").Mark(len(dropPieces))
|
2023-05-26 13:22:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-13 13:13:41 +01:00
|
|
|
mon.Meter("repair_unnecessary").Mark(1) //mon:locked
|
2021-02-03 22:22:46 +00:00
|
|
|
stats.repairUnnecessary.Mark(1)
|
2023-10-06 10:53:48 +01:00
|
|
|
repairer.log.Debug("segment above repair threshold", zap.Int("numHealthy", piecesCheck.Healthy.Size()), zap.Int32("repairThreshold", repairThreshold),
|
|
|
|
zap.Int("numClumped", piecesCheck.Clumped.Size()), zap.Int("numExiting", piecesCheck.Exiting.Size()), zap.Int("numOffPieces", piecesCheck.OutOfPlacement.Size()),
|
|
|
|
zap.Int("numExcluded", piecesCheck.InExcludedCountry.Size()), zap.Int("droppedPieces", len(dropPieces)))
|
2019-08-05 16:09:16 +01:00
|
|
|
return true, nil
|
2019-05-16 14:49:10 +01:00
|
|
|
}
|
|
|
|
|
2019-05-28 15:54:31 +01:00
|
|
|
healthyRatioBeforeRepair := 0.0
|
2020-12-14 14:29:48 +00:00
|
|
|
if segment.Redundancy.TotalShares != 0 {
|
2023-10-06 10:53:48 +01:00
|
|
|
healthyRatioBeforeRepair = float64(piecesCheck.Healthy.Size()) / float64(segment.Redundancy.TotalShares)
|
2019-05-28 15:54:31 +01:00
|
|
|
}
|
2020-10-13 13:13:41 +01:00
|
|
|
mon.FloatVal("healthy_ratio_before_repair").Observe(healthyRatioBeforeRepair) //mon:locked
|
2021-02-03 22:22:46 +00:00
|
|
|
stats.healthyRatioBeforeRepair.Observe(healthyRatioBeforeRepair)
|
2019-05-28 15:10:26 +01:00
|
|
|
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
// Create the order limits for the GET_REPAIR action
|
2023-10-06 10:53:48 +01:00
|
|
|
retrievablePieces := make(metabase.Pieces, 0, piecesCheck.Retrievable.Size())
|
2019-05-20 14:22:03 +01:00
|
|
|
for _, piece := range pieces {
|
2023-10-06 10:53:48 +01:00
|
|
|
if piecesCheck.Retrievable.Contains(int(piece.Number)) {
|
2022-12-13 20:40:15 +00:00
|
|
|
retrievablePieces = append(retrievablePieces, piece)
|
2019-03-18 10:55:06 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-22 13:35:23 +01:00
|
|
|
getOrderLimits, getPrivateKey, cachedNodesInfo, err := repairer.orders.CreateGetRepairOrderLimits(ctx, segment, retrievablePieces)
|
2019-03-28 20:09:23 +00:00
|
|
|
if err != nil {
|
2021-08-17 17:59:23 +01:00
|
|
|
if orders.ErrDownloadFailedNotEnoughPieces.Has(err) {
|
|
|
|
mon.Counter("repairer_segments_below_min_req").Inc(1) //mon:locked
|
|
|
|
stats.repairerSegmentsBelowMinReq.Inc(1)
|
|
|
|
mon.Meter("repair_nodes_unavailable").Mark(1) //mon:locked
|
|
|
|
stats.repairerNodesUnavailable.Mark(1)
|
|
|
|
|
2022-09-19 22:16:48 +01:00
|
|
|
repairer.log.Warn("irreparable segment: too many nodes offline",
|
2021-08-17 17:59:23 +01:00
|
|
|
zap.String("StreamID", queueSegment.StreamID.String()),
|
|
|
|
zap.Uint64("Position", queueSegment.Position.Encode()),
|
2022-12-13 20:40:15 +00:00
|
|
|
zap.Int("piecesAvailable", len(retrievablePieces)),
|
2022-09-19 22:16:48 +01:00
|
|
|
zap.Int16("piecesRequired", segment.Redundancy.RequiredShares),
|
2021-08-17 17:59:23 +01:00
|
|
|
zap.Error(err),
|
|
|
|
)
|
|
|
|
}
|
2020-02-24 20:13:12 +00:00
|
|
|
return false, orderLimitFailureError.New("could not create GET_REPAIR order limits: %w", err)
|
2018-12-13 07:12:36 +00:00
|
|
|
}
|
|
|
|
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
// Double check for retrievable pieces which were recognized as irretrievable during the
|
|
|
|
// call to CreateGetRepairOrderLimits. Add or remove them from the appropriate sets.
|
2022-12-13 20:40:15 +00:00
|
|
|
for _, piece := range retrievablePieces {
|
2020-12-14 14:29:48 +00:00
|
|
|
if getOrderLimits[piece.Number] == nil {
|
2023-10-06 10:53:48 +01:00
|
|
|
piecesCheck.Missing.Include(int(piece.Number))
|
|
|
|
piecesCheck.Unhealthy.Include(int(piece.Number))
|
|
|
|
|
|
|
|
piecesCheck.Healthy.Remove(int(piece.Number))
|
|
|
|
piecesCheck.Retrievable.Remove(int(piece.Number))
|
|
|
|
piecesCheck.UnhealthyRetrievable.Remove(int(piece.Number))
|
2020-07-17 22:30:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-11 23:44:47 +01:00
|
|
|
var requestCount int
|
|
|
|
{
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
totalNeeded := int(math.Ceil(float64(redundancy.OptimalThreshold()) * repairer.multiplierOptimalThreshold))
|
|
|
|
if totalNeeded > redundancy.TotalCount() {
|
|
|
|
totalNeeded = redundancy.TotalCount()
|
2022-12-13 20:40:15 +00:00
|
|
|
}
|
2023-10-06 10:53:48 +01:00
|
|
|
requestCount = totalNeeded - piecesCheck.Healthy.Size()
|
2019-07-11 23:44:47 +01:00
|
|
|
}
|
2023-10-06 10:53:48 +01:00
|
|
|
minSuccessfulNeeded := redundancy.OptimalThreshold() - piecesCheck.Healthy.Size()
|
2019-07-11 23:44:47 +01:00
|
|
|
|
2018-12-13 07:12:36 +00:00
|
|
|
// Request Overlay for n-h new storage nodes
|
2019-03-23 08:06:11 +00:00
|
|
|
request := overlay.FindStorageNodesRequest{
|
2019-07-11 23:44:47 +01:00
|
|
|
RequestedCount: requestCount,
|
2023-06-26 10:54:52 +01:00
|
|
|
ExcludedIDs: piecesCheck.ExcludeNodeIDs,
|
2023-06-10 19:50:03 +01:00
|
|
|
Placement: segment.Placement,
|
2019-03-18 10:55:06 +00:00
|
|
|
}
|
2020-08-04 17:50:12 +01:00
|
|
|
newNodes, err := repairer.overlay.FindStorageNodesForUpload(ctx, request)
|
2018-12-13 07:12:36 +00:00
|
|
|
if err != nil {
|
2020-02-24 20:13:12 +00:00
|
|
|
return false, overlayQueryError.Wrap(err)
|
2018-12-13 07:12:36 +00:00
|
|
|
}
|
|
|
|
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
// Create the order limits for the PUT_REPAIR action. We want to keep pieces in Healthy
|
|
|
|
// as well as pieces in InExcludedCountry (our policy is to let those nodes keep the
|
|
|
|
// pieces they have, as long as they are kept intact and retrievable).
|
|
|
|
maxToKeep := int(segment.Redundancy.TotalShares) - len(newNodes)
|
|
|
|
toKeep := map[uint16]struct{}{}
|
2023-10-06 10:53:48 +01:00
|
|
|
|
|
|
|
// TODO how to avoid this two loops
|
|
|
|
for _, piece := range pieces {
|
|
|
|
if piecesCheck.Healthy.Contains(int(piece.Number)) {
|
|
|
|
toKeep[piece.Number] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, piece := range pieces {
|
|
|
|
if piecesCheck.InExcludedCountry.Contains(int(piece.Number)) {
|
|
|
|
if len(toKeep) >= maxToKeep {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
toKeep[piece.Number] = struct{}{}
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
}
|
|
|
|
}
|
2023-10-06 10:53:48 +01:00
|
|
|
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
putLimits, putPrivateKey, err := repairer.orders.CreatePutRepairOrderLimits(ctx, segment, getOrderLimits, toKeep, newNodes)
|
2019-03-28 20:09:23 +00:00
|
|
|
if err != nil {
|
2020-02-24 20:13:12 +00:00
|
|
|
return false, orderLimitFailureError.New("could not create PUT_REPAIR order limits: %w", err)
|
2018-12-13 07:12:36 +00:00
|
|
|
}
|
|
|
|
|
2022-12-13 20:40:15 +00:00
|
|
|
// Download the segment using just the retrievable pieces
|
2023-03-31 18:52:27 +01:00
|
|
|
segmentReader, piecesReport, err := repairer.ec.Get(ctx, getOrderLimits, cachedNodesInfo, getPrivateKey, redundancy, int64(segment.EncryptedSize))
|
2020-12-14 14:29:48 +00:00
|
|
|
|
2021-08-17 14:27:09 +01:00
|
|
|
// ensure we get values, even if only zero values, so that redash can have an alert based on this
|
2022-09-19 22:16:48 +01:00
|
|
|
mon.Meter("repair_too_many_nodes_failed").Mark(0) //mon:locked
|
|
|
|
mon.Meter("repair_suspected_network_problem").Mark(0) //mon:locked
|
2021-08-17 14:27:09 +01:00
|
|
|
stats.repairTooManyNodesFailed.Mark(0)
|
|
|
|
|
2021-10-04 15:18:41 +01:00
|
|
|
if repairer.OnTestingPiecesReportHook != nil {
|
|
|
|
repairer.OnTestingPiecesReportHook(piecesReport)
|
|
|
|
}
|
|
|
|
|
2021-08-03 14:21:27 +01:00
|
|
|
// Check if segment has been altered
|
|
|
|
checkSegmentError := repairer.checkIfSegmentAltered(ctx, segment)
|
|
|
|
if checkSegmentError != nil {
|
|
|
|
if segmentDeletedError.Has(checkSegmentError) {
|
|
|
|
// mon.Meter("segment_deleted_during_repair").Mark(1) //mon:locked
|
|
|
|
repairer.log.Debug("segment deleted during Repair")
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
if segmentModifiedError.Has(checkSegmentError) {
|
|
|
|
// mon.Meter("segment_modified_during_repair").Mark(1) //mon:locked
|
|
|
|
repairer.log.Debug("segment modified during Repair")
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
return false, segmentVerificationError.Wrap(checkSegmentError)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(piecesReport.Contained) > 0 {
|
|
|
|
repairer.log.Debug("unexpected contained pieces during repair", zap.Int("count", len(piecesReport.Contained)))
|
|
|
|
}
|
|
|
|
|
2018-12-13 07:12:36 +00:00
|
|
|
if err != nil {
|
cmd/satellite: ignore Canceled in exit from repair worker
Firstly, this changes the repair functionality to return Canceled errors
when a repair is canceled during the Get phase. Previously, because we
do not track individual errors per piece, this would just show up as a
failure to download enough pieces to repair the segment, which would
cause the segment to be added to the IrreparableDB, which is entirely
unhelpful.
Then, ignore Canceled errors in the return value of the repair worker.
Apparently, when the worker returns an error, that makes Cobra exit the
program with a nonzero exit code, which causes some piece of our
deployment automation to freak out and page people. And when we ask the
repair worker to shut down, "canceled" errors are what we _expect_, not
an error case.
Change-Id: Ia3eb1c60a8d6ec5d09e7cef55dea523be28e8435
2020-05-15 03:39:22 +01:00
|
|
|
// If the context was closed during the Get phase, it will appear here as though
|
|
|
|
// we just failed to download enough pieces to reconstruct the segment. Check for
|
|
|
|
// a closed context before doing any further error processing.
|
|
|
|
if ctxErr := ctx.Err(); ctxErr != nil {
|
|
|
|
return false, ctxErr
|
|
|
|
}
|
2020-02-24 20:13:12 +00:00
|
|
|
// If Get failed because of input validation, then it will keep failing. But if it
|
|
|
|
// gave us irreparableError, then we failed to download enough pieces and must try
|
|
|
|
// to wait for nodes to come back online.
|
2021-05-14 16:05:42 +01:00
|
|
|
var irreparableErr *irreparableError
|
|
|
|
if errors.As(err, &irreparableErr) {
|
2022-09-19 22:16:48 +01:00
|
|
|
// piecesReport.Offline:
|
|
|
|
// Nodes which were online recently, but which we couldn't contact for
|
|
|
|
// this operation.
|
|
|
|
//
|
|
|
|
// piecesReport.Failed:
|
|
|
|
// Nodes which we contacted successfully but which indicated they
|
|
|
|
// didn't have the piece we wanted.
|
|
|
|
//
|
|
|
|
// piecesReport.Contained:
|
|
|
|
// Nodes which we contacted successfully but timed out after we asked
|
|
|
|
// for the piece.
|
|
|
|
//
|
|
|
|
// piecesReport.Unknown:
|
|
|
|
// Something else went wrong, and we don't know what.
|
|
|
|
//
|
|
|
|
// In a network failure scenario, we expect more than half of the outcomes
|
|
|
|
// will be in Offline or Contained.
|
|
|
|
if len(piecesReport.Offline)+len(piecesReport.Contained) > len(piecesReport.Successful)+len(piecesReport.Failed)+len(piecesReport.Unknown) {
|
|
|
|
mon.Meter("repair_suspected_network_problem").Mark(1) //mon:locked
|
|
|
|
} else {
|
|
|
|
mon.Meter("repair_too_many_nodes_failed").Mark(1) //mon:locked
|
|
|
|
}
|
2021-02-03 22:22:46 +00:00
|
|
|
stats.repairTooManyNodesFailed.Mark(1)
|
2021-06-15 22:45:31 +01:00
|
|
|
|
2022-09-19 22:16:48 +01:00
|
|
|
failedNodeIDs := make([]string, 0, len(piecesReport.Failed))
|
|
|
|
offlineNodeIDs := make([]string, 0, len(piecesReport.Offline))
|
|
|
|
timedOutNodeIDs := make([]string, 0, len(piecesReport.Contained))
|
|
|
|
unknownErrs := make([]string, 0, len(piecesReport.Unknown))
|
|
|
|
for _, outcome := range piecesReport.Failed {
|
|
|
|
failedNodeIDs = append(failedNodeIDs, outcome.Piece.StorageNode.String())
|
|
|
|
}
|
|
|
|
for _, outcome := range piecesReport.Offline {
|
|
|
|
offlineNodeIDs = append(offlineNodeIDs, outcome.Piece.StorageNode.String())
|
|
|
|
}
|
|
|
|
for _, outcome := range piecesReport.Contained {
|
|
|
|
timedOutNodeIDs = append(timedOutNodeIDs, outcome.Piece.StorageNode.String())
|
|
|
|
}
|
|
|
|
for _, outcome := range piecesReport.Unknown {
|
|
|
|
// We are purposefully using the error's string here, as opposed
|
|
|
|
// to wrapping the error. It is not likely that we need the local-side
|
|
|
|
// traceback of where this error was initially wrapped, and this will
|
|
|
|
// keep the logs more readable.
|
|
|
|
unknownErrs = append(unknownErrs, fmt.Sprintf("node ID [%s] err: %v", outcome.Piece.StorageNode, outcome.Err))
|
|
|
|
}
|
|
|
|
|
|
|
|
repairer.log.Warn("irreparable segment: could not acquire enough shares",
|
2021-06-17 16:05:04 +01:00
|
|
|
zap.String("StreamID", queueSegment.StreamID.String()),
|
|
|
|
zap.Uint64("Position", queueSegment.Position.Encode()),
|
2021-06-15 22:45:31 +01:00
|
|
|
zap.Int32("piecesAvailable", irreparableErr.piecesAvailable),
|
|
|
|
zap.Int32("piecesRequired", irreparableErr.piecesRequired),
|
2022-09-19 22:16:48 +01:00
|
|
|
zap.Int("numFailedNodes", len(failedNodeIDs)),
|
|
|
|
zap.Stringer("failedNodes", commaSeparatedArray(failedNodeIDs)),
|
|
|
|
zap.Int("numOfflineNodes", len(offlineNodeIDs)),
|
|
|
|
zap.Stringer("offlineNodes", commaSeparatedArray(offlineNodeIDs)),
|
|
|
|
zap.Int("numTimedOutNodes", len(timedOutNodeIDs)),
|
|
|
|
zap.Stringer("timedOutNodes", commaSeparatedArray(timedOutNodeIDs)),
|
|
|
|
zap.Stringer("unknownErrors", commaSeparatedArray(unknownErrs)),
|
2021-06-15 22:45:31 +01:00
|
|
|
)
|
2022-09-19 22:16:48 +01:00
|
|
|
// repair will be attempted again if the segment remains unhealthy.
|
2021-06-15 22:45:31 +01:00
|
|
|
return false, nil
|
2020-02-24 20:13:12 +00:00
|
|
|
}
|
|
|
|
// The segment's redundancy strategy is invalid, or else there was an internal error.
|
|
|
|
return true, repairReconstructError.New("segment could not be reconstructed: %w", err)
|
2018-12-13 07:12:36 +00:00
|
|
|
}
|
2019-09-06 20:20:36 +01:00
|
|
|
defer func() { err = errs.Combine(err, segmentReader.Close()) }()
|
2018-12-13 07:12:36 +00:00
|
|
|
|
2021-11-12 21:04:30 +00:00
|
|
|
// only report audit result when segment can be successfully downloaded
|
2021-11-08 20:51:04 +00:00
|
|
|
cachedNodesReputation := make(map[storj.NodeID]overlay.ReputationStatus, len(cachedNodesInfo))
|
|
|
|
for id, info := range cachedNodesInfo {
|
|
|
|
cachedNodesReputation[id] = info.Reputation
|
|
|
|
}
|
|
|
|
|
|
|
|
report := audit.Report{
|
2023-04-26 18:59:56 +01:00
|
|
|
Segment: &segment,
|
2021-11-08 20:51:04 +00:00
|
|
|
NodesReputation: cachedNodesReputation,
|
|
|
|
}
|
|
|
|
|
2022-09-19 22:16:48 +01:00
|
|
|
for _, outcome := range piecesReport.Successful {
|
|
|
|
report.Successes = append(report.Successes, outcome.Piece.StorageNode)
|
2021-11-12 21:04:30 +00:00
|
|
|
}
|
2022-09-19 22:16:48 +01:00
|
|
|
for _, outcome := range piecesReport.Failed {
|
2023-04-26 18:59:56 +01:00
|
|
|
report.Fails = append(report.Fails, metabase.Piece{
|
|
|
|
StorageNode: outcome.Piece.StorageNode,
|
|
|
|
Number: outcome.Piece.Number,
|
|
|
|
})
|
2021-11-12 21:04:30 +00:00
|
|
|
}
|
2022-09-19 22:16:48 +01:00
|
|
|
for _, outcome := range piecesReport.Offline {
|
|
|
|
report.Offlines = append(report.Offlines, outcome.Piece.StorageNode)
|
2021-11-12 21:04:30 +00:00
|
|
|
}
|
2022-09-19 22:16:48 +01:00
|
|
|
for _, outcome := range piecesReport.Unknown {
|
|
|
|
report.Unknown = append(report.Unknown, outcome.Piece.StorageNode)
|
2021-11-12 21:04:30 +00:00
|
|
|
}
|
2022-11-24 13:02:08 +00:00
|
|
|
if repairer.reputationUpdateEnabled {
|
2022-11-22 21:55:19 +00:00
|
|
|
repairer.reporter.RecordAudits(ctx, report)
|
2021-11-12 21:04:30 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
// Upload the repaired pieces
|
2021-06-17 16:05:04 +01:00
|
|
|
successfulNodes, _, err := repairer.ec.Repair(ctx, putLimits, putPrivateKey, redundancy, segmentReader, repairer.timeout, minSuccessfulNeeded)
|
2018-12-13 07:12:36 +00:00
|
|
|
if err != nil {
|
2020-02-24 20:13:12 +00:00
|
|
|
return false, repairPutError.Wrap(err)
|
2018-12-13 07:12:36 +00:00
|
|
|
}
|
|
|
|
|
2021-07-20 15:41:38 +01:00
|
|
|
pieceSize := eestream.CalcPieceSize(int64(segment.EncryptedSize), redundancy)
|
|
|
|
var bytesRepaired int64
|
|
|
|
|
2019-07-25 17:59:46 +01:00
|
|
|
// Add the successfully uploaded pieces to repairedPieces
|
2020-12-14 14:29:48 +00:00
|
|
|
var repairedPieces metabase.Pieces
|
|
|
|
repairedMap := make(map[uint16]bool)
|
2019-03-18 10:55:06 +00:00
|
|
|
for i, node := range successfulNodes {
|
|
|
|
if node == nil {
|
|
|
|
continue
|
2018-12-13 07:12:36 +00:00
|
|
|
}
|
2021-07-20 15:41:38 +01:00
|
|
|
bytesRepaired += pieceSize
|
2020-12-14 14:29:48 +00:00
|
|
|
piece := metabase.Piece{
|
|
|
|
Number: uint16(i),
|
|
|
|
StorageNode: node.Id,
|
2019-07-25 17:59:46 +01:00
|
|
|
}
|
2020-12-14 14:29:48 +00:00
|
|
|
repairedPieces = append(repairedPieces, piece)
|
|
|
|
repairedMap[uint16(i)] = true
|
2018-12-13 07:12:36 +00:00
|
|
|
}
|
|
|
|
|
2021-07-20 15:41:38 +01:00
|
|
|
mon.Meter("repair_bytes_uploaded").Mark64(bytesRepaired) //mon:locked
|
|
|
|
|
2023-10-06 10:53:48 +01:00
|
|
|
healthyAfterRepair := piecesCheck.Healthy.Size() + len(repairedPieces)
|
2019-05-29 14:14:25 +01:00
|
|
|
switch {
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
case healthyAfterRepair >= int(segment.Redundancy.OptimalShares):
|
|
|
|
mon.Meter("repair_success").Mark(1) //mon:locked
|
|
|
|
stats.repairSuccess.Mark(1)
|
2020-12-14 14:29:48 +00:00
|
|
|
case healthyAfterRepair <= int(segment.Redundancy.RepairShares):
|
2020-02-24 20:13:12 +00:00
|
|
|
// Important: this indicates a failure to PUT enough pieces to the network to pass
|
|
|
|
// the repair threshold, and _not_ a failure to reconstruct the segment. But we
|
|
|
|
// put at least one piece, else ec.Repair() would have returned an error. So the
|
|
|
|
// repair "succeeded" in that the segment is now healthier than it was, but it is
|
|
|
|
// not as healthy as we want it to be.
|
2020-10-13 13:13:41 +01:00
|
|
|
mon.Meter("repair_failed").Mark(1) //mon:locked
|
2021-02-03 22:22:46 +00:00
|
|
|
stats.repairFailed.Mark(1)
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
default:
|
2020-10-13 13:13:41 +01:00
|
|
|
mon.Meter("repair_partial").Mark(1) //mon:locked
|
2021-02-03 22:22:46 +00:00
|
|
|
stats.repairPartial.Mark(1)
|
2019-05-28 15:10:26 +01:00
|
|
|
}
|
|
|
|
|
2019-05-28 15:54:31 +01:00
|
|
|
healthyRatioAfterRepair := 0.0
|
2020-12-14 14:29:48 +00:00
|
|
|
if segment.Redundancy.TotalShares != 0 {
|
|
|
|
healthyRatioAfterRepair = float64(healthyAfterRepair) / float64(segment.Redundancy.TotalShares)
|
2019-05-28 15:54:31 +01:00
|
|
|
}
|
2021-02-03 22:22:46 +00:00
|
|
|
|
2020-10-13 13:13:41 +01:00
|
|
|
mon.FloatVal("healthy_ratio_after_repair").Observe(healthyRatioAfterRepair) //mon:locked
|
2021-02-03 22:22:46 +00:00
|
|
|
stats.healthyRatioAfterRepair.Observe(healthyRatioAfterRepair)
|
2019-05-28 15:10:26 +01:00
|
|
|
|
2020-12-14 14:29:48 +00:00
|
|
|
var toRemove metabase.Pieces
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
switch {
|
|
|
|
case healthyAfterRepair >= int(segment.Redundancy.OptimalShares):
|
|
|
|
// Repair was fully successful; remove all unhealthy pieces except those in
|
|
|
|
// (Retrievable AND InExcludedCountry). Those, we allow to remain on the nodes as
|
|
|
|
// long as the nodes are keeping the pieces intact and available.
|
|
|
|
for _, piece := range pieces {
|
2023-10-06 10:53:48 +01:00
|
|
|
if piecesCheck.Unhealthy.Contains(int(piece.Number)) {
|
|
|
|
retrievable := piecesCheck.Retrievable.Contains(int(piece.Number))
|
|
|
|
inExcludedCountry := piecesCheck.InExcludedCountry.Contains(int(piece.Number))
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
if retrievable && inExcludedCountry {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
toRemove = append(toRemove, piece)
|
|
|
|
}
|
2022-12-13 20:40:15 +00:00
|
|
|
}
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
case healthyAfterRepair > int(segment.Redundancy.RepairShares):
|
|
|
|
// Repair was successful enough that we still want to drop all out-of-placement
|
|
|
|
// pieces. We want to do that wherever possible, except where doing so puts data in
|
|
|
|
// jeopardy.
|
|
|
|
for _, piece := range pieces {
|
2023-10-06 10:53:48 +01:00
|
|
|
if piecesCheck.OutOfPlacement.Contains(int(piece.Number)) {
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
toRemove = append(toRemove, piece)
|
2019-06-28 20:48:51 +01:00
|
|
|
}
|
|
|
|
}
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
default:
|
|
|
|
// Repair improved the health of the piece, but it is still at or below the
|
|
|
|
// repair threshold (not counting unhealthy-but-retrievable pieces). To be safe,
|
|
|
|
// we will keep unhealthy-but-retrievable pieces in the segment for now.
|
|
|
|
}
|
|
|
|
|
|
|
|
// in any case, we want to remove pieces for which we have replacements now.
|
|
|
|
for _, piece := range pieces {
|
|
|
|
if repairedMap[piece.Number] {
|
|
|
|
toRemove = append(toRemove, piece)
|
|
|
|
}
|
2019-06-28 20:48:51 +01:00
|
|
|
}
|
|
|
|
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
// add pieces that failed piece hash verification to the removal list
|
2022-09-19 22:16:48 +01:00
|
|
|
for _, outcome := range piecesReport.Failed {
|
|
|
|
toRemove = append(toRemove, outcome.Piece)
|
|
|
|
}
|
2019-09-16 18:13:24 +01:00
|
|
|
|
2021-07-28 07:43:24 +01:00
|
|
|
newPieces, err := segment.Pieces.Update(repairedPieces, toRemove)
|
2020-12-14 14:29:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, repairPutError.Wrap(err)
|
2019-10-07 18:54:12 +01:00
|
|
|
}
|
|
|
|
|
2020-12-14 14:29:48 +00:00
|
|
|
err = repairer.metabase.UpdateSegmentPieces(ctx, metabase.UpdateSegmentPieces{
|
2021-01-29 15:28:19 +00:00
|
|
|
StreamID: segment.StreamID,
|
2021-06-17 16:05:04 +01:00
|
|
|
Position: segment.Position,
|
2019-09-17 20:18:48 +01:00
|
|
|
|
2021-03-12 11:23:44 +00:00
|
|
|
OldPieces: segment.Pieces,
|
|
|
|
NewRedundancy: segment.Redundancy,
|
|
|
|
NewPieces: newPieces,
|
2021-03-17 10:31:07 +00:00
|
|
|
|
|
|
|
NewRepairedAt: time.Now(),
|
2020-12-14 14:29:48 +00:00
|
|
|
})
|
2019-09-17 20:18:48 +01:00
|
|
|
if err != nil {
|
2020-02-24 20:13:12 +00:00
|
|
|
return false, metainfoPutError.Wrap(err)
|
2019-09-17 20:18:48 +01:00
|
|
|
}
|
|
|
|
|
2021-03-17 10:31:07 +00:00
|
|
|
repairedAt := time.Time{}
|
|
|
|
if segment.RepairedAt != nil {
|
|
|
|
repairedAt = *segment.RepairedAt
|
|
|
|
}
|
|
|
|
|
|
|
|
var segmentAge time.Duration
|
2021-08-05 00:56:50 +01:00
|
|
|
if segment.CreatedAt.Before(repairedAt) {
|
2021-03-17 10:31:07 +00:00
|
|
|
segmentAge = time.Since(repairedAt)
|
|
|
|
} else {
|
2021-08-05 00:56:50 +01:00
|
|
|
segmentAge = time.Since(segment.CreatedAt)
|
2021-03-17 10:31:07 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 13:13:41 +01:00
|
|
|
mon.IntVal("segment_time_until_repair").Observe(int64(segmentAge.Seconds())) //mon:locked
|
2021-08-05 00:56:50 +01:00
|
|
|
stats.segmentTimeUntilRepair.Observe(int64(segmentAge.Seconds()))
|
2019-09-17 20:18:48 +01:00
|
|
|
|
2023-05-18 19:47:23 +01:00
|
|
|
repairer.log.Debug("repaired segment",
|
|
|
|
zap.Stringer("Stream ID", segment.StreamID),
|
|
|
|
zap.Uint64("Position", segment.Position.Encode()),
|
2023-10-06 10:53:48 +01:00
|
|
|
zap.Int("clumped pieces", piecesCheck.Clumped.Size()),
|
|
|
|
zap.Int("exiting-node pieces", piecesCheck.Exiting.Size()),
|
|
|
|
zap.Int("out of placement pieces", piecesCheck.OutOfPlacement.Size()),
|
|
|
|
zap.Int("in excluded countries", piecesCheck.InExcludedCountry.Size()),
|
|
|
|
zap.Int("missing pieces", piecesCheck.Missing.Size()),
|
2023-05-18 19:47:23 +01:00
|
|
|
zap.Int("removed pieces", len(toRemove)),
|
|
|
|
zap.Int("repaired pieces", len(repairedPieces)),
|
2023-10-06 10:53:48 +01:00
|
|
|
zap.Int("retrievable pieces", piecesCheck.Retrievable.Size()),
|
|
|
|
zap.Int("healthy before repair", piecesCheck.Healthy.Size()),
|
satellite/repair: unify repair logic
The repair checker and repair worker both need to determine which pieces
are healthy, which are retrievable, and which should be replaced, but
they have been doing it in different ways in different code, which has
been the cause of bugs. The same term could have very similar but subtly
different meanings between the two, causing much confusion.
With this change, the piece- and node-classification logic is
consolidated into one place within the satellite/repair package, so that
both subsystems can use it. This ought to make decision-making code more
concise and more readable.
The consolidated classification logic has been expanded to create more
sets, so that the decision-making code does not need to do as much
precalculation. It should now be clearer in comments and code that a
piece can belong to multiple sets arbitrarily (except where the
definition of the sets makes this logically impossible), and what the
precise meaning of each set is. These sets include Missing, Suspended,
Clumped, OutOfPlacement, InExcludedCountry, ForcingRepair,
UnhealthyRetrievable, Unhealthy, Retrievable, and Healthy.
Some other side effects of this change:
* CreatePutRepairOrderLimits no longer needs to special-case excluded
countries; it can just create as many order limits as requested (by
way of len(newNodes)).
* The repair checker will now queue a segment for repair when there are
any pieces out of placement. The code calls this "forcing a repair".
* The checker.ReliabilityCache is now accessed by way of a GetNodes()
function similar to the one on the overlay. The classification methods
like MissingPieces(), OutOfPlacementPieces(), and
PiecesNodesLastNetsInOrder() are removed in favor of the
classification logic in satellite/repair/classification.go. This
means the reliability cache no longer needs access to the placement
rules or excluded countries list.
Change-Id: I105109fb94ee126952f07d747c6e11131164fadb
2023-09-11 05:07:39 +01:00
|
|
|
zap.Int("healthy after repair", healthyAfterRepair),
|
|
|
|
zap.Int("total before repair", len(piecesCheck.ExcludeNodeIDs)),
|
|
|
|
zap.Int("total after repair", len(newPieces)))
|
2019-09-17 20:18:48 +01:00
|
|
|
return true, nil
|
2019-03-18 10:55:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-03 14:21:27 +01:00
|
|
|
// checkIfSegmentAltered checks if oldSegment has been altered since it was selected for audit.
|
|
|
|
func (repairer *SegmentRepairer) checkIfSegmentAltered(ctx context.Context, oldSegment metabase.Segment) (err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if repairer.OnTestingCheckSegmentAlteredHook != nil {
|
|
|
|
repairer.OnTestingCheckSegmentAlteredHook()
|
|
|
|
}
|
|
|
|
|
|
|
|
newSegment, err := repairer.metabase.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
|
|
|
StreamID: oldSegment.StreamID,
|
|
|
|
Position: oldSegment.Position,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
if metabase.ErrSegmentNotFound.Has(err) {
|
|
|
|
return segmentDeletedError.New("StreamID: %q Position: %d", oldSegment.StreamID.String(), oldSegment.Position.Encode())
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !oldSegment.Pieces.Equal(newSegment.Pieces) {
|
|
|
|
return segmentModifiedError.New("StreamID: %q Position: %d", oldSegment.StreamID.String(), oldSegment.Position.Encode())
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-03 22:22:46 +00:00
|
|
|
func (repairer *SegmentRepairer) getStatsByRS(redundancy *pb.RedundancyScheme) *stats {
|
|
|
|
rsString := getRSString(repairer.loadRedundancy(redundancy))
|
|
|
|
return repairer.statsCollector.getStatsByRS(rsString)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repairer *SegmentRepairer) loadRedundancy(redundancy *pb.RedundancyScheme) (int, int, int, int) {
|
|
|
|
repair := int(redundancy.RepairThreshold)
|
|
|
|
overrideValue := repairer.repairOverrides.GetOverrideValuePB(redundancy)
|
|
|
|
if overrideValue != 0 {
|
|
|
|
repair = int(overrideValue)
|
|
|
|
}
|
|
|
|
return int(redundancy.MinReq), repair, int(redundancy.SuccessThreshold), int(redundancy.Total)
|
|
|
|
}
|
|
|
|
|
2020-12-18 08:49:31 +00:00
|
|
|
// SetNow allows tests to have the server act as if the current time is whatever they want.
|
|
|
|
func (repairer *SegmentRepairer) SetNow(nowFn func() time.Time) {
|
|
|
|
repairer.nowFn = nowFn
|
|
|
|
}
|
|
|
|
|
2022-02-13 04:19:29 +00:00
|
|
|
// AdminFetchInfo groups together all the information about a piece that should be retrievable
|
|
|
|
// from storage nodes.
|
|
|
|
type AdminFetchInfo struct {
|
|
|
|
Reader io.ReadCloser
|
|
|
|
Hash *pb.PieceHash
|
|
|
|
GetLimit *pb.AddressedOrderLimit
|
|
|
|
OriginalLimit *pb.OrderLimit
|
|
|
|
FetchError error
|
|
|
|
}
|
|
|
|
|
|
|
|
// AdminFetchPieces retrieves raw pieces and the associated hashes and original order
|
|
|
|
// limits from the storage nodes on which they are stored, and returns them intact to
|
|
|
|
// the caller rather than decoding or decrypting or verifying anything. This is to be
|
|
|
|
// used for debugging purposes.
|
|
|
|
func (repairer *SegmentRepairer) AdminFetchPieces(ctx context.Context, seg *metabase.Segment, saveDir string) (pieceInfos []AdminFetchInfo, err error) {
|
|
|
|
if seg.Inline() {
|
|
|
|
return nil, errs.New("cannot download an inline segment")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(seg.Pieces) < int(seg.Redundancy.RequiredShares) {
|
|
|
|
return nil, errs.New("segment only has %d pieces; needs %d for reconstruction", seg.Pieces, seg.Redundancy.RequiredShares)
|
|
|
|
}
|
|
|
|
|
|
|
|
// we treat all pieces as "healthy" for our purposes here; we want to download as many
|
|
|
|
// of them as we reasonably can. Thus, we pass in seg.Pieces for 'healthy'
|
2023-05-22 13:35:23 +01:00
|
|
|
getOrderLimits, getPrivateKey, cachedNodesInfo, err := repairer.orders.CreateGetRepairOrderLimits(ctx, *seg, seg.Pieces)
|
2022-02-13 04:19:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.New("could not create order limits: %w", err)
|
|
|
|
}
|
|
|
|
|
2023-02-22 10:32:26 +00:00
|
|
|
pieceSize := seg.PieceSize()
|
2022-02-13 04:19:29 +00:00
|
|
|
|
|
|
|
pieceInfos = make([]AdminFetchInfo, len(getOrderLimits))
|
2023-02-22 10:32:26 +00:00
|
|
|
limiter := sync2.NewLimiter(int(seg.Redundancy.RequiredShares))
|
2022-02-13 04:19:29 +00:00
|
|
|
|
|
|
|
for currentLimitIndex, limit := range getOrderLimits {
|
|
|
|
if limit == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
pieceInfos[currentLimitIndex].GetLimit = limit
|
|
|
|
|
|
|
|
currentLimitIndex, limit := currentLimitIndex, limit
|
|
|
|
limiter.Go(ctx, func() {
|
|
|
|
info := cachedNodesInfo[limit.GetLimit().StorageNodeId]
|
|
|
|
address := limit.GetStorageNodeAddress().GetAddress()
|
|
|
|
var triedLastIPPort bool
|
|
|
|
if info.LastIPPort != "" && info.LastIPPort != address {
|
|
|
|
address = info.LastIPPort
|
|
|
|
triedLastIPPort = true
|
|
|
|
}
|
|
|
|
|
|
|
|
pieceReadCloser, hash, originalLimit, err := repairer.ec.downloadAndVerifyPiece(ctx, limit, address, getPrivateKey, saveDir, pieceSize)
|
|
|
|
// if piecestore dial with last ip:port failed try again with node address
|
|
|
|
if triedLastIPPort && piecestore.Error.Has(err) {
|
|
|
|
if pieceReadCloser != nil {
|
|
|
|
_ = pieceReadCloser.Close()
|
|
|
|
}
|
|
|
|
pieceReadCloser, hash, originalLimit, err = repairer.ec.downloadAndVerifyPiece(ctx, limit, limit.GetStorageNodeAddress().GetAddress(), getPrivateKey, saveDir, pieceSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
pieceInfos[currentLimitIndex].Reader = pieceReadCloser
|
|
|
|
pieceInfos[currentLimitIndex].Hash = hash
|
|
|
|
pieceInfos[currentLimitIndex].OriginalLimit = originalLimit
|
|
|
|
pieceInfos[currentLimitIndex].FetchError = err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
limiter.Wait()
|
|
|
|
|
|
|
|
return pieceInfos, nil
|
|
|
|
}
|
|
|
|
|
2022-09-19 22:16:48 +01:00
|
|
|
// commaSeparatedArray concatenates an array into a comma-separated string,
|
|
|
|
// lazily.
|
|
|
|
type commaSeparatedArray []string
|
|
|
|
|
|
|
|
func (c commaSeparatedArray) String() string {
|
|
|
|
return strings.Join(c, ", ")
|
|
|
|
}
|