2022-09-07 16:30:33 +01:00
|
|
|
// Copyright (C) 2022 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-09-09 09:16:22 +01:00
|
|
|
"sync/atomic"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2022-09-07 16:30:33 +01:00
|
|
|
"storj.io/common/uuid"
|
|
|
|
"storj.io/storj/satellite/metabase"
|
|
|
|
)
|
|
|
|
|
|
|
|
// VerifyPieces defines how many pieces we check per segment.
|
|
|
|
const VerifyPieces = 3
|
|
|
|
|
2022-09-09 09:16:22 +01:00
|
|
|
// ConcurrentRequests defines how many concurrent requests we do to the storagenodes.
|
|
|
|
const ConcurrentRequests = 10000
|
|
|
|
|
2022-09-07 16:30:33 +01:00
|
|
|
// Service implements segment verification logic.
|
|
|
|
type Service struct {
|
2022-09-09 09:16:22 +01:00
|
|
|
log *zap.Logger
|
|
|
|
|
2022-09-07 16:30:33 +01:00
|
|
|
PriorityNodes NodeAliasSet
|
|
|
|
OfflineNodes NodeAliasSet
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewService returns a new service for verifying segments.
|
2022-09-09 09:16:22 +01:00
|
|
|
func NewService(log *zap.Logger) *Service {
|
2022-09-07 16:30:33 +01:00
|
|
|
return &Service{
|
2022-09-09 09:16:22 +01:00
|
|
|
log: log,
|
|
|
|
|
2022-09-07 16:30:33 +01:00
|
|
|
PriorityNodes: NodeAliasSet{},
|
|
|
|
OfflineNodes: NodeAliasSet{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Segment contains minimal information necessary for verifying a single Segment.
|
|
|
|
type Segment struct {
|
|
|
|
StreamID uuid.UUID
|
|
|
|
Position metabase.SegmentPosition
|
|
|
|
Pieces []metabase.AliasPiece
|
2022-09-09 09:16:22 +01:00
|
|
|
|
|
|
|
Status Status
|
|
|
|
}
|
|
|
|
|
|
|
|
// Status contains the statistics about the segment.
|
|
|
|
type Status struct {
|
|
|
|
Retry int32
|
|
|
|
Found int32
|
|
|
|
NotFound int32
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarkFound moves a retry token from retry to found.
|
|
|
|
func (status *Status) MarkFound() {
|
|
|
|
atomic.AddInt32(&status.Retry, -1)
|
|
|
|
atomic.AddInt32(&status.Found, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarkNotFound moves a retry token from retry to not found.
|
|
|
|
func (status *Status) MarkNotFound() {
|
|
|
|
atomic.AddInt32(&status.Retry, -1)
|
|
|
|
atomic.AddInt32(&status.NotFound, 1)
|
2022-09-07 16:30:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Batch is a list of segments to be verified on a single node.
|
|
|
|
type Batch struct {
|
|
|
|
Alias metabase.NodeAlias
|
|
|
|
Items []*Segment
|
|
|
|
}
|
|
|
|
|
|
|
|
// Len returns the length of the batch.
|
|
|
|
func (b *Batch) Len() int { return len(b.Items) }
|