Files
seaweedfs/weed/mount/weedfs_stream_mutate_error_test.go
T
f28d101a82 filer, mount: fail writes to a read-only path at once, as EDQUOT (#12823)
* 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>
2026-11-20 12:49:05 -08:00

162 lines
5.3 KiB
Go

package mount
import (
"errors"
"syscall"
"testing"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
)
// The filer reports a failed create twice: a generic errno at the top level and
// a structured code in the nested CreateEntryResponse. doUnary must not consume
// the response on the generic one, or the sentinel never reaches Mkdir and a
// lost create race surfaces as EIO instead of EEXIST.
func TestHasCreateResponse(t *testing.T) {
cases := []struct {
name string
resp *filer_pb.StreamMutateEntryResponse
want bool
}{
{
name: "create carrying a nested response",
resp: &filer_pb.StreamMutateEntryResponse{
Response: &filer_pb.StreamMutateEntryResponse_CreateResponse{
CreateResponse: &filer_pb.CreateEntryResponse{
Error: "entry already exists",
ErrorCode: filer_pb.FilerError_ENTRY_ALREADY_EXISTS,
},
},
},
want: true,
},
{
name: "create wrapper with no nested response",
resp: &filer_pb.StreamMutateEntryResponse{
Response: &filer_pb.StreamMutateEntryResponse_CreateResponse{},
},
want: false,
},
{
name: "a different mutation",
resp: &filer_pb.StreamMutateEntryResponse{
Response: &filer_pb.StreamMutateEntryResponse_DeleteResponse{
DeleteResponse: &filer_pb.DeleteEntryResponse{Error: "boom"},
},
},
want: false,
},
{
name: "no response at all",
resp: &filer_pb.StreamMutateEntryResponse{},
want: false,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := hasCreateResponse(tc.resp); got != tc.want {
t.Fatalf("hasCreateResponse = %v, want %v", got, tc.want)
}
})
}
}
// CreateEntry turns the nested code into the sentinel Mkdir matches on.
func TestStreamMutateCreateEntryUnwrapsAlreadyExists(t *testing.T) {
resp := &filer_pb.StreamMutateEntryResponse{
Response: &filer_pb.StreamMutateEntryResponse_CreateResponse{
CreateResponse: &filer_pb.CreateEntryResponse{
Error: "/dir/name: entry already exists",
ErrorCode: filer_pb.FilerError_ENTRY_ALREADY_EXISTS,
},
},
}
_, err := createEntryFromResponse(resp, &filer_pb.CreateEntryRequest{
Directory: "/dir",
Entry: &filer_pb.Entry{Name: "name"},
})
if !errors.Is(err, filer_pb.ErrEntryAlreadyExists) {
t.Fatalf("err = %v, want it to wrap ErrEntryAlreadyExists", err)
}
}
// A read-only verdict must reach Mkdir as ErrReadOnly (EDQUOT), both coded and
// as the bare text an older filer sends.
func TestStreamMutateCreateEntryUnwrapsReadOnly(t *testing.T) {
const msg = "read only: /buckets/b/ (e.g. bucket over quota)"
for name, cr := range map[string]*filer_pb.CreateEntryResponse{
"coded": {Error: msg, ErrorCode: filer_pb.FilerError_READ_ONLY},
"legacy": {Error: msg},
} {
t.Run(name, func(t *testing.T) {
resp := &filer_pb.StreamMutateEntryResponse{
Error: msg,
Errno: int32(syscall.EIO),
Response: &filer_pb.StreamMutateEntryResponse_CreateResponse{CreateResponse: cr},
}
_, err := createEntryFromResponse(resp, &filer_pb.CreateEntryRequest{
Directory: "/buckets/b",
Entry: &filer_pb.Entry{Name: "d"},
})
if !errors.Is(err, filer_pb.ErrReadOnly) {
t.Fatalf("err = %v, want it to wrap ErrReadOnly", err)
}
})
}
}
// Any other create failure keeps the generic errno rather than inventing one.
func TestStreamMutateCreateEntryKeepsGenericFailure(t *testing.T) {
resp := &filer_pb.StreamMutateEntryResponse{
Response: &filer_pb.StreamMutateEntryResponse_CreateResponse{
CreateResponse: &filer_pb.CreateEntryResponse{Error: "store unavailable"},
},
}
_, err := createEntryFromResponse(resp, &filer_pb.CreateEntryRequest{
Directory: "/dir",
Entry: &filer_pb.Entry{Name: "name"},
})
var sme *streamMutateError
if !errors.As(err, &sme) || sme.Errno() != syscall.EIO {
t.Fatalf("err = %v, want a streamMutateError with EIO", err)
}
}
// A create wrapper whose nested response is missing must be reported, not
// dereferenced. Nothing our filer sends looks like this, but the mount is
// reading off the wire and a panic here takes the whole mount down.
func TestStreamMutateCreateEntryRejectsMissingNestedResponse(t *testing.T) {
_, err := createEntryFromResponse(&filer_pb.StreamMutateEntryResponse{
Response: &filer_pb.StreamMutateEntryResponse_CreateResponse{},
}, &filer_pb.CreateEntryRequest{
Directory: "/dir",
Entry: &filer_pb.Entry{Name: "name"},
})
var sme *streamMutateError
if !errors.As(err, &sme) || sme.Errno() != syscall.EIO {
t.Fatalf("err = %v, want a streamMutateError with EIO", err)
}
}
// A top-level failure the nested response does not explain must not read as
// success just because the nested fields happen to be empty.
func TestStreamMutateCreateEntryKeepsUnexplainedTopLevelError(t *testing.T) {
_, err := createEntryFromResponse(&filer_pb.StreamMutateEntryResponse{
Error: "filer went away mid-create",
Errno: int32(syscall.EAGAIN),
Response: &filer_pb.StreamMutateEntryResponse_CreateResponse{
CreateResponse: &filer_pb.CreateEntryResponse{},
},
}, &filer_pb.CreateEntryRequest{
Directory: "/dir",
Entry: &filer_pb.Entry{Name: "name"},
})
var sme *streamMutateError
if !errors.As(err, &sme) {
t.Fatalf("err = %v, want a streamMutateError", err)
}
if sme.Errno() != syscall.EAGAIN {
t.Fatalf("errno = %v, want the top-level EAGAIN", sme.Errno())
}
}