Files
seaweedfs/seaweed-block/core/rpc/lifecycleclient/reason.go
T
pingqiu-cpu a6304c2101 feat(geometry): new volumes up to 1 TiB (v1.1) (#757)
Interim merge note (spec trace workflow startup_failure on all branches since 22:45Z): branch updated to current main (69c5c6bd); go test (linux) and process-level tests (real binaries) passed on 69c5c6bd; spec-trace-check.sh and public-text-check.sh run locally with the base branch's scripts against this head and body: both pass (Model line now also cites FormatGate.Report for core/host/master/services.go, mapped since the PR was accepted). Code review ACCEPT on e1ed5073; the 1 TiB loaded first-cut measurement on current main passed on both volume formats.
2026-12-02 18:05:50 -08:00

81 lines
3.1 KiB
Go

package lifecycleclient
import (
"errors"
"google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc/status"
)
// Typed refusal reasons the master attaches to a gRPC status (an ErrorInfo
// detail in ErrorDomain), so a client decides by the reason, never by the
// message text.
const (
ErrorDomain = "seaweed-block"
// ReasonRestoreSourceNotOwn: a restore was refused because the snapshot
// names chunks of a volume other than its source (a restore target's
// snapshot cannot be restored again).
ReasonRestoreSourceNotOwn = "RESTORE_SOURCE_NOT_OWN"
// ReasonBinaryTooOld: the caller's binary does not read the cluster's
// format level (its heartbeat's reads_level is below it), so the master
// refuses it and gives it no work.
ReasonBinaryTooOld = "BINARY_TOO_OLD"
// ReasonFormatHostsTooOld: the format finalize was refused because a
// process that holds a volume reports that it reads below the new level.
ReasonFormatHostsTooOld = "FORMAT_HOSTS_TOO_OLD"
// ReasonHostHoldsWork: a host retire was refused because the host still
// holds a lease or an assignment for a volume.
ReasonHostHoldsWork = "HOST_HOLDS_WORK"
// ReasonSizeRequiresFormatLevel1: a new volume above 256 GiB was refused
// because the cluster's format level is 0 (finalize the v1.1 format).
ReasonSizeRequiresFormatLevel1 = "SIZE_REQUIRES_FORMAT_LEVEL_1"
)
// WithReason returns st with an ErrorInfo detail carrying reason in
// ErrorDomain; st unchanged if the detail cannot be attached.
func WithReason(st *status.Status, reason string) *status.Status {
return WithReasonMetadata(st, reason, nil)
}
// WithReasonMetadata is WithReason with typed fields in the detail's
// metadata (for example one entry per refused host).
func WithReasonMetadata(st *status.Status, reason string, md map[string]string) *status.Status {
if d, err := st.WithDetails(&errdetails.ErrorInfo{Reason: reason, Domain: ErrorDomain, Metadata: md}); err == nil {
return d
}
return st
}
// Reason is the typed refusal reason in err's gRPC status (an ErrorInfo in
// ErrorDomain), or "" when it carries none. err may be wrapped.
func Reason(err error) string {
reason, _ := ReasonDetail(err)
return reason
}
// ReasonDetail is Reason with the detail's metadata (nil when none).
func ReasonDetail(err error) (string, map[string]string) {
var se interface{ GRPCStatus() *status.Status }
if !errors.As(err, &se) {
return "", nil
}
for _, d := range se.GRPCStatus().Details() {
if info, ok := d.(*errdetails.ErrorInfo); ok && info.GetDomain() == ErrorDomain {
return info.GetReason(), info.GetMetadata()
}
}
return "", nil
}
// HostMetadataPrefix keys one refused host in a reason's metadata:
// "host.<server id>" maps to what that host reported.
const HostMetadataPrefix = "host."
// UnconfirmedMetadataPrefix keys one host a format finalize could not
// confirm and did not block on: "unconfirmed.<server id>" maps to why.
const UnconfirmedMetadataPrefix = "unconfirmed."
// VolumeMetadataPrefix keys one volume in a reason's metadata:
// "volume.<volume id>" maps to the host that holds it.
const VolumeMetadataPrefix = "volume."