storj/satellite/audit/pieces.go
paul cannon 7d0885bbaa satellite/repair: move over audit.Pieces
This structure is entirely unused within the audit module, and is only
used by repair code. Accordingly, this change moves the structure from
audit code to repair code.

Also, we take the opportunity here to rename the structure to something
less generic.

Refs: https://github.com/storj/storj/issues/4669

Change-Id: If85b37e08620cda1fde2afe98206293e02b5c36e
2022-09-22 16:43:03 +00:00

57 lines
1.2 KiB
Go

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package audit
import (
"context"
"github.com/zeebo/errs"
"storj.io/common/errs2"
"storj.io/common/rpc"
"storj.io/common/rpc/rpcstatus"
)
// PieceAudit is piece audit status.
type PieceAudit int
const (
// PieceAuditUnknown is unknown piece audit.
PieceAuditUnknown PieceAudit = iota
// PieceAuditFailure is failed piece audit.
PieceAuditFailure
// PieceAuditOffline is offline node piece audit.
PieceAuditOffline
// PieceAuditContained is online but unresponsive node piece audit.
PieceAuditContained
// PieceAuditSuccess is successful piece audit.
PieceAuditSuccess
)
// PieceAuditFromErr returns piece audit based on error.
func PieceAuditFromErr(err error) PieceAudit {
if err == nil {
return PieceAuditSuccess
}
if rpc.Error.Has(err) {
switch {
case errs.Is(err, context.DeadlineExceeded), errs2.IsRPC(err, rpcstatus.Unknown):
return PieceAuditOffline
default:
// TODO: is this path not reachable?
return PieceAuditUnknown
}
}
switch {
case errs2.IsRPC(err, rpcstatus.NotFound):
return PieceAuditFailure
case errs2.IsRPC(err, rpcstatus.DeadlineExceeded):
return PieceAuditContained
default:
return PieceAuditUnknown
}
}