mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +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>
129 lines
3.9 KiB
Go
129 lines
3.9 KiB
Go
package weed_server
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
)
|
|
|
|
func newAssignTestServer(fc *filer.FilerConf, diskType string) *FilerServer {
|
|
return &FilerServer{
|
|
option: &FilerOption{
|
|
DiskType: diskType,
|
|
},
|
|
filer: &filer.Filer{
|
|
DirBucketsPath: "/buckets",
|
|
FilerConf: fc,
|
|
MaxFilenameLength: 255,
|
|
},
|
|
}
|
|
}
|
|
|
|
func TestResolveAssignStorageOptionUsesBucketRuleBeforeFilerDiskDefault(t *testing.T) {
|
|
fc := filer.NewFilerConf()
|
|
if err := fc.SetLocationConf(&filer_pb.FilerConf_PathConf{
|
|
LocationPrefix: "/buckets/zot",
|
|
DiskType: "disk",
|
|
}); err != nil {
|
|
t.Fatalf("set location conf: %v", err)
|
|
}
|
|
|
|
fs := newAssignTestServer(fc, "hdd")
|
|
|
|
so, err := fs.resolveAssignStorageOption(context.Background(), &filer_pb.AssignVolumeRequest{
|
|
Path: "/buckets/zot/.uploads/upload-id/0001_part.part",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("resolve assign storage option: %v", err)
|
|
}
|
|
|
|
if got, want := so.Collection, "zot"; got != want {
|
|
t.Fatalf("collection = %q, want %q", got, want)
|
|
}
|
|
if got, want := so.DiskType, "disk"; got != want {
|
|
t.Fatalf("disk type = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestResolveAssignStorageOptionFallsBackToFilerDiskDefault(t *testing.T) {
|
|
fs := newAssignTestServer(filer.NewFilerConf(), "hdd")
|
|
|
|
so, err := fs.resolveAssignStorageOption(context.Background(), &filer_pb.AssignVolumeRequest{
|
|
Path: "/tmp/unmatched/file.bin",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("resolve assign storage option: %v", err)
|
|
}
|
|
|
|
if got, want := so.DiskType, "hdd"; got != want {
|
|
t.Fatalf("disk type = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
// A read-only path is a verdict, not a transport failure: it must come back as a
|
|
// successful RPC (so clients neither retry nor fail over) carrying READ_ONLY.
|
|
func TestAssignVolumeReadOnlyReturnsErrorCode(t *testing.T) {
|
|
fc := filer.NewFilerConf()
|
|
if err := fc.SetLocationConf(&filer_pb.FilerConf_PathConf{
|
|
LocationPrefix: "/buckets/overquota",
|
|
ReadOnly: true,
|
|
}); err != nil {
|
|
t.Fatalf("set location conf: %v", err)
|
|
}
|
|
|
|
fs := newAssignTestServer(fc, "")
|
|
|
|
resp, err := fs.AssignVolume(context.Background(), &filer_pb.AssignVolumeRequest{
|
|
Path: "/buckets/overquota/x",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("AssignVolume err = %v, want a response", err)
|
|
}
|
|
if resp.ErrorCode != filer_pb.FilerError_READ_ONLY {
|
|
t.Fatalf("AssignVolume error_code = %v, want %v", resp.ErrorCode, filer_pb.FilerError_READ_ONLY)
|
|
}
|
|
// Clients that predate error_code still get the old message.
|
|
if want := "assign volume: read only: /buckets/overquota"; !strings.HasPrefix(resp.Error, want) {
|
|
t.Fatalf("AssignVolume error = %q, want prefix %q", resp.Error, want)
|
|
}
|
|
if err := filer_pb.AssignVolumeResponseError(resp); !errors.Is(err, ErrReadOnly) {
|
|
t.Fatalf("AssignVolumeResponseError = %v, want ErrReadOnly", err)
|
|
}
|
|
}
|
|
|
|
// A create on a read-only path must come back as a coded response, like
|
|
// AssignVolume. A gRPC error reaches clients as codes.Unknown, and they retry
|
|
// that like a filer outage.
|
|
func TestCreateEntryReadOnlyReturnsErrorCode(t *testing.T) {
|
|
fc := filer.NewFilerConf()
|
|
if err := fc.SetLocationConf(&filer_pb.FilerConf_PathConf{
|
|
LocationPrefix: "/buckets/overquota",
|
|
ReadOnly: true,
|
|
}); err != nil {
|
|
t.Fatalf("set location conf: %v", err)
|
|
}
|
|
|
|
fs := newAssignTestServer(fc, "")
|
|
|
|
resp, err := fs.CreateEntry(context.Background(), &filer_pb.CreateEntryRequest{
|
|
Directory: "/buckets/overquota/dir",
|
|
Entry: &filer_pb.Entry{
|
|
Name: "x",
|
|
Attributes: &filer_pb.FuseAttributes{FileMode: 0644},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateEntry err = %v, want a response", err)
|
|
}
|
|
if resp.ErrorCode != filer_pb.FilerError_READ_ONLY {
|
|
t.Fatalf("CreateEntry error_code = %v, want %v", resp.ErrorCode, filer_pb.FilerError_READ_ONLY)
|
|
}
|
|
if want := "read only: /buckets/overquota"; !strings.HasPrefix(resp.Error, want) {
|
|
t.Fatalf("CreateEntry error = %q, want prefix %q", resp.Error, want)
|
|
}
|
|
}
|