2617925f8d
Adding a new worker comparable to Verifier, called Reverifier; as the name suggests, it will be used for reverifications, whereas Verifier will be used for verifications. This allows distinct logging from the two classes, plus we can add some configuration that is specific to the Reverifier. There is a slight modification to GetNextJob that goes along with this. This should have no impact on operational concerns. Refs: https://github.com/storj/storj/issues/5251 Change-Id: Ie60d2d833bc5db8660bb463dd93c764bb40fc49c
60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package audit
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"storj.io/common/storj"
|
|
)
|
|
|
|
// ErrEmptyQueue is used to indicate that the queue is empty.
|
|
var ErrEmptyQueue = errs.Class("empty audit queue")
|
|
|
|
// 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 {
|
|
Push(ctx context.Context, segments []Segment, maxBatchSize int) (err error)
|
|
Next(ctx context.Context) (Segment, error)
|
|
}
|
|
|
|
// 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 {
|
|
Insert(ctx context.Context, piece *PieceLocator) (err error)
|
|
GetNextJob(ctx context.Context, retryInterval time.Duration) (job *ReverificationJob, err error)
|
|
Remove(ctx context.Context, piece *PieceLocator) (wasDeleted bool, err error)
|
|
GetByNodeID(ctx context.Context, nodeID storj.NodeID) (audit *ReverificationJob, err error)
|
|
}
|
|
|
|
// 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]
|
|
}
|