2019-05-22 15:50:22 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellitedb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-06-26 16:44:25 +01:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/pb"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/audit"
|
2019-05-22 15:50:22 +01:00
|
|
|
)
|
|
|
|
|
2022-11-23 15:24:30 +00:00
|
|
|
type containment struct {
|
2022-11-22 16:59:04 +00:00
|
|
|
reverifyQueue audit.ReverifyQueue
|
|
|
|
}
|
|
|
|
|
2022-11-23 15:24:30 +00:00
|
|
|
var _ audit.Containment = &containment{}
|
2022-11-22 21:55:19 +00:00
|
|
|
|
2022-11-22 16:59:04 +00:00
|
|
|
// Get gets a pending reverification audit by node id. If there are
|
|
|
|
// multiple pending reverification audits, an arbitrary one is returned.
|
|
|
|
// If there are none, an error wrapped by audit.ErrContainedNotFound is
|
|
|
|
// returned.
|
2022-11-23 15:24:30 +00:00
|
|
|
func (containment *containment) Get(ctx context.Context, id pb.NodeID) (_ *audit.ReverificationJob, err error) {
|
2022-11-22 16:59:04 +00:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
if id.IsZero() {
|
|
|
|
return nil, audit.ContainError.New("node ID empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
return containment.reverifyQueue.GetByNodeID(ctx, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert creates a new pending audit entry.
|
2022-11-23 15:24:30 +00:00
|
|
|
func (containment *containment) Insert(ctx context.Context, pendingJob *audit.PieceLocator) (err error) {
|
2022-11-22 16:59:04 +00:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
return containment.reverifyQueue.Insert(ctx, pendingJob)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete removes a job from the reverification queue, whether because the job
|
|
|
|
// was successful or because the job is no longer necessary. The wasDeleted
|
|
|
|
// return value indicates whether the indicated job was actually deleted (if
|
|
|
|
// not, there was no such job in the queue).
|
2022-11-23 15:24:30 +00:00
|
|
|
func (containment *containment) Delete(ctx context.Context, pendingJob *audit.PieceLocator) (isDeleted, nodeStillContained bool, err error) {
|
2022-11-22 16:59:04 +00:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
isDeleted, err = containment.reverifyQueue.Remove(ctx, pendingJob)
|
|
|
|
if err != nil {
|
|
|
|
return false, false, audit.ContainError.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeStillContained = true
|
|
|
|
_, err = containment.reverifyQueue.GetByNodeID(ctx, pendingJob.NodeID)
|
|
|
|
if audit.ErrContainedNotFound.Has(err) {
|
|
|
|
nodeStillContained = false
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
return isDeleted, nodeStillContained, audit.ContainError.Wrap(err)
|
|
|
|
}
|
2023-01-25 22:34:40 +00:00
|
|
|
|
|
|
|
func (containment *containment) GetAllContainedNodes(ctx context.Context) (nodes []pb.NodeID, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
return containment.reverifyQueue.GetAllContainedNodes(ctx)
|
|
|
|
}
|