mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
75 lines
2.6 KiB
Go
75 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net"
|
|
|
|
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
|
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
|
|
"github.com/seaweedfs/seaweed-block/core/rpc/answer"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// Translate domain facts and transport evidence; the registry owns the
|
|
// output code, retry decision and exit. Partial verify uses the same path.
|
|
func chunkAnswer(err error) (answer.Policy, string) {
|
|
return chunkAnswerFor(err, answer.Chunk)
|
|
}
|
|
|
|
func chunkAnswerFor(err error, contract answer.Contract) (answer.Policy, string) {
|
|
var domain *chunkstore.CatalogError
|
|
hasDomain := errors.As(err, &domain)
|
|
guard := layoutCode(err)
|
|
_, recordedPolicy := answer.PolicyOf(err, contract)
|
|
if !hasDomain && guard == "" && recordedPolicy != nil && errors.Is(err, errVerifyStalled) {
|
|
policy, _ := answer.Lookup(answer.Unsent, answer.ForContract(contract, answer.Guard("deadline_exceeded")))
|
|
return policy, err.Error() + "; " + policy.Cure
|
|
}
|
|
if (!hasDomain || domain.Code == chunkstore.CodeRemoteUnavailable) && (guard == "" || errors.Is(err, layout.ErrHolderActive)) {
|
|
observed := err
|
|
if kind, listed := answer.ErrorKind(err); listed && kind == answer.Configuration {
|
|
observed = answer.EnsureEvidence(answer.Unsent, err)
|
|
}
|
|
if _, remote := status.FromError(err); remote {
|
|
observed = answer.EnsureEvidence(answer.PossiblyAdmitted, err)
|
|
}
|
|
var network *net.OpError
|
|
if errors.As(err, &network) {
|
|
observed = answer.EnsureEvidence(answer.PossiblyAdmitted, observed)
|
|
}
|
|
if policy, check := answer.PolicyOf(observed, contract); check == nil {
|
|
if policy.Code == codeCanceledCLI {
|
|
return policy, policy.Cure
|
|
}
|
|
detail := err.Error()
|
|
if hasDomain {
|
|
detail = domain.Detail()
|
|
}
|
|
return policy, detail + "; " + policy.Cure
|
|
}
|
|
}
|
|
kind, detail := answer.Guard("internal"), err.Error()
|
|
switch {
|
|
case hasDomain:
|
|
kind = answer.Domain(domain.Code, domain.Retryable, domain.Detail())
|
|
case guard != "":
|
|
kind = answer.Guard(guard)
|
|
case errors.Is(err, context.Canceled):
|
|
kind = answer.Canceled
|
|
case errors.Is(err, context.DeadlineExceeded):
|
|
kind = answer.CallerDeadline
|
|
case errors.Is(err, errVerifyStalled):
|
|
kind = answer.Guard("deadline_exceeded")
|
|
}
|
|
policy, check := answer.Lookup(answer.Unsent, answer.ForContract(contract, kind))
|
|
if check != nil {
|
|
policy, _ = answer.Lookup(answer.Unsent, answer.ForContract(contract, answer.Guard("unsupported_error_code")))
|
|
return policy, detail + "; " + check.Error()
|
|
}
|
|
if hasDomain || policy.Code == codeCanceledCLI {
|
|
detail = policy.Cure
|
|
}
|
|
return policy, detail
|
|
}
|