2019-09-05 16:40:52 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package audit
|
|
|
|
|
|
|
|
import (
|
2020-07-13 23:24:15 +01:00
|
|
|
"context"
|
2022-11-22 00:35:13 +00:00
|
|
|
"time"
|
2019-09-05 16:40:52 +01:00
|
|
|
|
|
|
|
"github.com/zeebo/errs"
|
2022-11-21 23:53:00 +00:00
|
|
|
|
|
|
|
"storj.io/common/storj"
|
2019-09-05 16:40:52 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// ErrEmptyQueue is used to indicate that the queue is empty.
|
|
|
|
var ErrEmptyQueue = errs.Class("empty audit queue")
|
|
|
|
|
2022-11-01 17:45:41 +00:00
|
|
|
// VerifyQueue controls manipulation of a database-based queue of segments to be
|
|
|
|
// verified; that is, segments chosen at random from all segments on the
|
|
|
|
// satellite, for which workers should perform audits. We will try to download a
|
|
|
|
// stripe of data across all pieces in the segment and ensure that all pieces
|
|
|
|
// conform to the same polynomial.
|
|
|
|
type VerifyQueue interface {
|
2022-11-23 16:37:39 +00:00
|
|
|
Push(ctx context.Context, segments []Segment, maxBatchSize int) (err error)
|
2022-11-01 17:45:41 +00:00
|
|
|
Next(ctx context.Context) (Segment, error)
|
|
|
|
}
|
|
|
|
|
2022-10-05 14:24:04 +01:00
|
|
|
// ReverifyQueue controls manipulation of a queue of pieces to be _re_verified;
|
|
|
|
// that is, a node timed out when we requested an audit of the piece, and now
|
|
|
|
// we need to follow up with that node until we get a proper answer to the
|
|
|
|
// audit. (Or until we try too many times, and disqualify the node.)
|
|
|
|
type ReverifyQueue interface {
|
2022-11-21 23:53:00 +00:00
|
|
|
Insert(ctx context.Context, piece *PieceLocator) (err error)
|
2022-11-22 00:35:13 +00:00
|
|
|
GetNextJob(ctx context.Context, retryInterval time.Duration) (job *ReverificationJob, err error)
|
2022-11-21 23:53:00 +00:00
|
|
|
Remove(ctx context.Context, piece *PieceLocator) (wasDeleted bool, err error)
|
|
|
|
GetByNodeID(ctx context.Context, nodeID storj.NodeID) (audit *ReverificationJob, err error)
|
2023-01-25 22:34:40 +00:00
|
|
|
GetAllContainedNodes(ctx context.Context) ([]storj.NodeID, error)
|
2022-10-05 14:24:04 +01:00
|
|
|
}
|
2022-11-23 16:37:39 +00:00
|
|
|
|
|
|
|
// ByStreamIDAndPosition allows sorting of a slice of segments by stream ID and position.
|
|
|
|
type ByStreamIDAndPosition []Segment
|
|
|
|
|
|
|
|
func (b ByStreamIDAndPosition) Len() int {
|
|
|
|
return len(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b ByStreamIDAndPosition) Less(i, j int) bool {
|
|
|
|
comparison := b[i].StreamID.Compare(b[j].StreamID)
|
|
|
|
if comparison < 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if comparison > 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return b[i].Position.Less(b[j].Position)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b ByStreamIDAndPosition) Swap(i, j int) {
|
|
|
|
b[i], b[j] = b[j], b[i]
|
|
|
|
}
|