mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
104 lines
5.5 KiB
Go
104 lines
5.5 KiB
Go
package answer
|
|
|
|
import "strings"
|
|
|
|
// LeaseBarrier is a definite dated admission refusal, not a transport guess.
|
|
func LeaseBarrier(stamp string) Kind { return Kind{Name: "delete_lease_barrier", ServerMessage: stamp} }
|
|
|
|
// Domain preserves an authoritative typed answer, rather than inferring
|
|
// admission or retry safety from a transport diagnostic.
|
|
func Domain(code string, retryable bool, message string) Kind {
|
|
return Kind{Name: "server_domain", ServerCode: code, ServerRetryable: retryable, ServerMessage: message}
|
|
}
|
|
|
|
// Guard names an existing definite local/kernel refusal.
|
|
func Guard(code string) Kind { return Kind{Name: "guard/" + code} }
|
|
|
|
func isDomainKind(kind Kind) bool {
|
|
return kind.Name == "server_domain" || strings.HasPrefix(kind.Name, "guard/")
|
|
}
|
|
|
|
func addDomainCells(registry map[key]Policy) {
|
|
for _, phase := range []Phase{Unsent, PossiblyAdmitted} {
|
|
for _, code := range strings.Fields(`awaiting_assignment bad_request base_installing canceled capture_refused closing
|
|
cut_aborted cut_busy cut_stalled deadline_exceeded detach_aborted epoch_stale fenced forbidden
|
|
format_level_below_head_version frozen_detach_unsupported frozen_tail_too_large geometry_mismatch
|
|
head_conflict host_slot_busy in_progress internal invalid_class invalid_freeze_budget invalid_label
|
|
invalid_name invalid_policy layout_busy layout_refused lsn_behind method_not_allowed no_progress
|
|
not_chunk_volume not_found not_primary operation_capacity operation_conflict operation_handle_mismatch
|
|
operation_incomplete operation_intent_conflict operation_not_found operation_retired outcome_unknown
|
|
plain_detach_busy plain_detach_unsupported precopy_not_converged precopy_unknown queue_full reconciling
|
|
remote_full remote_unavailable schedule_not_running snapshot_delete_requires_operation snapshot_deleting
|
|
snapshot_exists snapshot_generation_mismatch snapshot_generation_unavailable snapshot_has_dependents
|
|
snapshot_limit snapshot_name_taken snapshot_not_found snapshot_operations_unsupported target_exists
|
|
unknown_cut_id volume_not_served volume_not_found restore_source_not_own not_admitted target_live
|
|
identity_mismatch volume_deleting conflict unsupported_api_version unsupported_error_code`) {
|
|
registry[key{phase, Kind{Name: "server_domain", ServerCode: code}}] = Policy{Retry: Never}
|
|
}
|
|
registry[key{phase, LeaseBarrier("")}] = Policy{"not_admitted", true, Recover, "", 0}
|
|
}
|
|
for _, row := range []struct {
|
|
code string
|
|
retry bool
|
|
cure string
|
|
}{
|
|
{"bad_request", false, "correct the request before sending it again"},
|
|
{"deadline_exceeded", true, "retry the same operation with a sufficient no-progress window"},
|
|
{"internal", false, "inspect the reported error before retrying the operation"},
|
|
{"readout_unproven", false, "inspect the stored range and its integrity evidence; never infer no loss from an unproven readout"},
|
|
{"outcome_unknown", true, "recover the same operation by its replay key or poll its existing handle; do not start another operation"},
|
|
{"unsupported_error_code", false, "upgrade the client, then recover the original operation by its replay key or poll; do not start another operation"},
|
|
{"queue_full", true, "let pending work drain before retrying the same operation"},
|
|
{"layout_busy", true, "retry the same operation after the current layout activity releases"},
|
|
{"snapshot_not_found", false, "check the snapshot identity; do not target a replacement as a retry"},
|
|
{"snapshot_delete_requires_operation", false, "delete through the snapshot operation interface with a stable request id"},
|
|
{"snapshot_has_dependents", false, "remove dependent volumes or release their dependency before resuming the same request id"},
|
|
{"restore_source_not_own", false, "use a source that owns its snapshot's chunks"},
|
|
{"volume_not_found", false, "check the recorded volume identity"},
|
|
{"target_exists", false, "read the existing target and reconcile the original operation"},
|
|
{"volume_deleting", false, "resume the existing deletion instead of creating a new operation"},
|
|
{"not_admitted", false, "resolve the stated admission refusal before retrying"},
|
|
{"delete_live_holder", false, "stop the volume first"},
|
|
{"target_live", false, "stop and release the target before retrying"},
|
|
{"identity_mismatch", false, "use the recorded full volume identity"},
|
|
{"geometry_mismatch", false, "use the recorded geometry"},
|
|
{"conflict", true, "read the current state and retry the same operation"},
|
|
{"invalid_policy", false, "correct the retention policy before retrying"},
|
|
} {
|
|
rule := Never
|
|
if row.retry {
|
|
rule = Resend
|
|
}
|
|
if row.code == "outcome_unknown" || row.code == "unsupported_error_code" {
|
|
rule = Recover
|
|
}
|
|
for _, phase := range []Phase{Unsent, PossiblyAdmitted} {
|
|
code := row.code
|
|
if code == "delete_live_holder" {
|
|
code = "not_admitted"
|
|
}
|
|
registry[key{phase, Guard(row.code)}] = Policy{code, row.retry, rule, row.cure, 0}
|
|
}
|
|
}
|
|
}
|
|
|
|
func projectDomain(policy Policy, kind Kind) Policy {
|
|
policy.Code, policy.Retryable, policy.Cure = kind.ServerCode, kind.ServerRetryable, kind.ServerMessage
|
|
if kind.ServerRetryable {
|
|
policy.Retry = Resend
|
|
}
|
|
if kind.ServerCode == "outcome_unknown" || kind.ServerCode == "in_progress" || kind.ServerCode == "no_progress" {
|
|
policy.Retry = Recover
|
|
}
|
|
if kind.ServerCode == "remote_unavailable" && kind.ServerRetryable {
|
|
remote := registry[key{Unsent, ForContract(kind.Contract, Connection)}]
|
|
if !strings.HasSuffix(policy.Cure, remote.Cure) {
|
|
policy.Cure += "; " + remote.Cure
|
|
}
|
|
}
|
|
if kind.ServerCode == "not_admitted" && kind.ServerRetryable && kind.Contract == Chunk {
|
|
policy.Retry = Recover
|
|
}
|
|
return policy
|
|
}
|