mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
* filer: report a read-only create in the response, not as a gRPC error CreateEntry returned a storage rule's read-only verdict (a bucket over quota) as a status-less error, which reaches clients as codes.Unknown. Clients retry Unknown like a filer outage. A mount retried the create of every new file four times (1/2/4 s) before returning EIO, so each close() on an over-quota bucket hung 7 s, git on its index.lock included. Report it the way AssignVolume already does: a successful RPC whose response carries the text and FilerError_READ_ONLY. CreateEntryWithResponse and the mount's stream path already map that code to filer_pb.ErrReadOnly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: fail a write to a read-only path at once, as EDQUOT On a read-only path (a bucket over quota), close() of a new file retried its create for 7 s and then returned EIO, and a failed chunk upload returned EIO as well. The verdict holds until the bucket is back under quota, so a retry gains nothing, and EIO names no cause. - isRetryableFilerError does not retry filer_pb.ErrReadOnly. - grpcErrorToFuseStatus, writeErrorToFuseStatus, and mkdir, symlink and link return EDQUOT for it. ENOSPC still means the cluster is out of space. - ShouldReassignUpload never reassigns on it, even when the path in the message contains "transport". - CreateEntryWithResponse and the stream path recognize the text an older filer sends ("read only: <prefix> ...", as codes.Unknown or as a bare message). The mount stops retrying even before its filer is upgraded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * admin, iam, shell: check a create's response, not only the RPC error A filer reports a refused create in CreateEntryResponse with a nil RPC error: an existing directory, a parent that is a file, a store error, and now a read-only path. Ten callers sent CreateEntry directly and looked only at the RPC error, so they took every refusal for success. An admin upload into a bucket that went read-only mid-upload reported success and skipped its chunk cleanup, and a session revocation that the filer refused left the session usable. They now go through filer_pb.CreateEntry, which returns the response's error as the call's error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * pb, mount, operation: read a filer verdict as an answer, not a failure A filer verdict, such as a read-only path, names the path in its message. Classifiers that fall back to matching that text for words like "transport" still read a refusal of /buckets/b/transport/f as a broken network: - shouldInvalidateConnection closed the shared filer channel, failing every other RPC in flight on it. - The mount's withFilerClient retried the call for about 13 s. filer_pb.IsFilerVerdict reports whether an error carries a sentinel that a filer response code maps to. shouldInvalidateConnection keeps the channel for such an error, and also for an older filer's read-only refusal that arrives as codes.Unknown. withFilerClient no longer retries it, and an upload with RetryForever no longer loops on a read-only assignment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: keep the first filer's verdict when another filer is down withFilerClient walks the filer addresses and keeps the last error. When the first filer refuses a write to a read-only path and the next one is unreachable, the walk returned the Unavailable from the second, so the call was retried for 13 s and then failed without the verdict. Stop the walk at a verdict and keep that filer as the one to try first: it answered, and every filer gives the same verdict. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * java client: fail a metadata write the filer refuses in its response The filer now reports a create on a read-only path in CreateEntryResponse instead of as a gRPC error. writeMeta ignored the response, so closing a zero-byte file under a read-only rule reported success without creating it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
133 lines
4.1 KiB
Go
133 lines
4.1 KiB
Go
package mount
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"syscall"
|
|
|
|
"github.com/seaweedfs/go-fuse/v2/fuse"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
)
|
|
|
|
// readOnlyStatus is the status the kernel gets when the filer refuses a write
|
|
// under a read-only filer.conf rule. That rule is how bucket quotas are
|
|
// enforced (s3.bucket.quota.enforce), so EDQUOT names the usual cause, where
|
|
// EIO named none. A path locked by hand reads as over quota too. A cluster out
|
|
// of space stays ENOSPC.
|
|
const readOnlyStatus = fuse.Status(syscall.EDQUOT)
|
|
|
|
func grpcErrorToFuseStatus(err error) fuse.Status {
|
|
if err == nil {
|
|
return fuse.OK
|
|
}
|
|
if errors.Is(err, filer_pb.ErrReadOnly) {
|
|
return readOnlyStatus
|
|
}
|
|
|
|
// Unpack error for inspection
|
|
if s, ok := status.FromError(err); ok {
|
|
switch s.Code() {
|
|
case codes.OK:
|
|
return fuse.OK
|
|
case codes.Canceled, codes.DeadlineExceeded:
|
|
return fuse.Status(syscall.ETIMEDOUT)
|
|
case codes.Unavailable:
|
|
return fuse.Status(syscall.EAGAIN)
|
|
case codes.ResourceExhausted:
|
|
return fuse.Status(syscall.EAGAIN) // Or syscall.ENOSPC
|
|
case codes.PermissionDenied:
|
|
return fuse.Status(syscall.EACCES)
|
|
case codes.Unauthenticated:
|
|
return fuse.Status(syscall.EPERM)
|
|
case codes.NotFound:
|
|
return fuse.ENOENT
|
|
case codes.AlreadyExists:
|
|
return fuse.Status(syscall.EEXIST)
|
|
case codes.InvalidArgument:
|
|
return fuse.EINVAL
|
|
}
|
|
}
|
|
|
|
// String matching for errors that don't have proper gRPC codes but are known
|
|
errStr := err.Error()
|
|
if strings.Contains(errStr, "transport") {
|
|
return fuse.Status(syscall.EAGAIN)
|
|
}
|
|
// Add other string matches if necessary
|
|
|
|
return fuse.EIO
|
|
}
|
|
|
|
// isStorageFullError reports whether a chunk upload failed because the cluster
|
|
// has no writable volume left (disks full and volume growth failed). The
|
|
// master's message reaches the mount as plain text inside
|
|
// AssignVolumeResponse.Error, so match on text rather than a status code.
|
|
func isStorageFullError(err error) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
errStr := strings.ToLower(err.Error())
|
|
return strings.Contains(errStr, "no writable volumes") ||
|
|
strings.Contains(errStr, "no free volumes")
|
|
}
|
|
|
|
// writeErrorToFuseStatus maps a dirty-page write/flush failure to the status
|
|
// returned to the kernel: EDQUOT when the path is read-only (a bucket over
|
|
// quota), ENOSPC when the cluster is out of space, EIO otherwise.
|
|
func writeErrorToFuseStatus(err error) fuse.Status {
|
|
if errors.Is(err, filer_pb.ErrReadOnly) {
|
|
return readOnlyStatus
|
|
}
|
|
if isStorageFullError(err) {
|
|
return fuse.Status(syscall.ENOSPC)
|
|
}
|
|
return fuse.EIO
|
|
}
|
|
|
|
// entryCreateErrorToFuseStatus maps a failed mkdir, symlink or link create to
|
|
// the status returned to the kernel. Only the read-only verdict gets its own
|
|
// errno. Everything else stays the EIO these calls have always returned.
|
|
func entryCreateErrorToFuseStatus(err error) fuse.Status {
|
|
if errors.Is(err, filer_pb.ErrReadOnly) {
|
|
return readOnlyStatus
|
|
}
|
|
return fuse.EIO
|
|
}
|
|
|
|
// isRetryableFilerError reports whether a filer RPC error looks transient
|
|
// enough to retry. It takes a conservative whitelist approach: only errors
|
|
// that clearly describe a permanent application-level failure
|
|
// (NotFound/AlreadyExists/InvalidArgument/PermissionDenied/Unauthenticated/
|
|
// FailedPrecondition) short-circuit the retry loop. Everything else —
|
|
// transport errors, Canceled/Unavailable/ResourceExhausted, or errors with no
|
|
// gRPC status — is treated as potentially transient and retried.
|
|
func isRetryableFilerError(err error) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
// CreateEntry reports a failed write condition in its response, not as a status.
|
|
if errors.Is(err, filer_pb.ErrPreconditionFailed) {
|
|
return false
|
|
}
|
|
// A read-only path is a verdict. It holds until the bucket is back under
|
|
// quota, so retrying only held close() for 7 s before the same failure.
|
|
if errors.Is(err, filer_pb.ErrReadOnly) {
|
|
return false
|
|
}
|
|
if s, ok := status.FromError(err); ok {
|
|
switch s.Code() {
|
|
case codes.NotFound,
|
|
codes.AlreadyExists,
|
|
codes.InvalidArgument,
|
|
codes.PermissionDenied,
|
|
codes.Unauthenticated,
|
|
codes.FailedPrecondition:
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|