Files
seaweedfs/seaweed-block/core/rpc/lifecycleclient/reason.go
T
pingqiuandClaude Opus 5.5 647ba06119 master: cluster format level (FORMAT-GATE): reads_level, finalize, level-0 v1.0 semantics, retire
Hosts report the format they read (heartbeat reads_level). The cluster's
format level is the master's attestation file's form: v1.0's bare map is
level 0, the envelope (format 2, format_level 1) level 1.

At level 0 the master keeps v1.0's semantics, so a v1.0.x master started
on the store stays safe: renewals clamp to the persisted horizon and an
extender keeps it current; forced moves and re-grants wait for the later
of horizon and deadline plus skew; records are envelope version 1.

sw-block cluster finalize-format raises the level in one durable step
(the envelope write), refused while a registered host has not reported
that it reads level 1; then the publisher switches under both its locks.
At any level no new work goes to a host that reads below it; its
heartbeat is refused binary_too_old; every assignment carries the level.
sw-block cluster retire-host removes a host that holds no volume.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 18:27:53 -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 ""
}