Files
seaweedfs/seaweed-block/core/rpc/lifecycleclient/reason.go
T
pingqiuandClaude Opus 5.5 744d238163 master: the format gate at the grant, not the placement (r2.875)
Placement (create, move, restore target, a failover candidate) refuses
only a host known to read a lower level, typed BINARY_TOO_OLD: with one
process per volume and create-then-start a placement target cannot have
reported yet. The grant (an authority line published to its holder)
needs the holder's own report at the cluster level; no report, no grant.
awaiting_first_report stays only as a status state; its refusal reason
is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 02:27:24 -08:00

54 lines
1.9 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
// registered host has not reported that it reads 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"
)
// 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 {
if d, err := st.WithDetails(&errdetails.ErrorInfo{Reason: reason, Domain: ErrorDomain}); 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 {
var se interface{ GRPCStatus() *status.Status }
if !errors.As(err, &se) {
return ""
}
for _, d := range se.GRPCStatus().Details() {
if info, ok := d.(*errdetails.ErrorInfo); ok && info.GetDomain() == ErrorDomain {
return info.GetReason()
}
}
return ""
}