mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +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>
155 lines
5.6 KiB
Go
155 lines
5.6 KiB
Go
package mount
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
)
|
|
|
|
var _ = filer_pb.FilerClient(&WFS{})
|
|
|
|
func (wfs *WFS) WithFilerClient(streamingMode bool, fn func(filer_pb.SeaweedFilerClient) error) (err error) {
|
|
return wfs.withFilerClient(context.Background(), streamingMode, wfs.filerRPCWait(), func(_ context.Context, client filer_pb.SeaweedFilerClient) error {
|
|
return fn(client)
|
|
})
|
|
}
|
|
|
|
// isRetryableFilerCall decides whether withFilerClient tries a failed call
|
|
// again. A filer verdict, such as a read-only path, is final whatever its
|
|
// message says, and the path it names can contain "transport".
|
|
func isRetryableFilerCall(err error) bool {
|
|
return !filer_pb.IsFilerVerdict(err) && util.IsTransientError(err)
|
|
}
|
|
|
|
// withFilerClient walks the filer addresses until one answers fn. callWait
|
|
// bounds one attempt; callWait <= 0 leaves the attempt to ctx alone, for
|
|
// calls whose duration the metadata bound cannot anticipate (a whole-file
|
|
// remote download). Streaming calls ignore callWait — their callbacks bound
|
|
// themselves (the rename fallback arms its own silence timer). The callback
|
|
// must run its RPCs under the supplied context: that is what lets a
|
|
// timed-out attempt be cancelled without disturbing the shared cached
|
|
// channel's other callers.
|
|
func (wfs *WFS) withFilerClient(ctx context.Context, streamingMode bool, callWait time.Duration, fn func(ctx context.Context, client filer_pb.SeaweedFilerClient) error) (err error) {
|
|
|
|
return util.RetryOnError("filer grpc", isRetryableFilerCall, func() error {
|
|
|
|
i := atomic.LoadInt32(&wfs.option.filerIndex)
|
|
n := len(wfs.option.FilerAddresses)
|
|
for x := 0; x < n; x++ {
|
|
|
|
filerGrpcAddress := wfs.option.FilerAddresses[i].ToGrpcAddress()
|
|
err = wfs.callFiler(ctx, streamingMode, callWait, filerGrpcAddress, fn)
|
|
|
|
if err != nil {
|
|
// glog.V(0).Infof("WithFilerClient %d %v: %v", x, filerGrpcAddress, err)
|
|
// A verdict is the filer's answer, and another filer would give
|
|
// the same one. Stop here, so that a later filer's transport
|
|
// error cannot replace it and turn it into a retry.
|
|
if filer_pb.IsFilerVerdict(err) {
|
|
atomic.StoreInt32(&wfs.option.filerIndex, i)
|
|
return err
|
|
}
|
|
} else {
|
|
atomic.StoreInt32(&wfs.option.filerIndex, i)
|
|
return nil
|
|
}
|
|
|
|
i++
|
|
if i >= int32(n) {
|
|
i = 0
|
|
}
|
|
|
|
}
|
|
return err
|
|
})
|
|
|
|
}
|
|
|
|
// filerRPCWait bounds one filer call when the callers' RPCs carry no deadline
|
|
// of their own. filerCallTimeout is only settable on the WFS for tests.
|
|
func (wfs *WFS) filerRPCWait() time.Duration {
|
|
if wfs.filerCallTimeout > 0 {
|
|
return wfs.filerCallTimeout
|
|
}
|
|
return filerRPCTimeout
|
|
}
|
|
|
|
// callFiler runs fn against one filer under a per-attempt context derived
|
|
// from ctx, so a filer whose transport silently stalls (stopped peer,
|
|
// black-holed connection) cannot block forever and keep the walk from
|
|
// reaching the remaining filer addresses. Cancelling the attempt aborts its
|
|
// RPCs on the shared cached channel without tearing that channel down.
|
|
//
|
|
// On timeout the call waits for the attempt's callback to unwind before
|
|
// returning: a slow attempt must not overlap the next filer's run of the
|
|
// same closure and clobber the caller's shared result variables. A callback
|
|
// that ignored the attempt context is forced out by dropping the channel.
|
|
func (wfs *WFS) callFiler(ctx context.Context, streamingMode bool, callWait time.Duration, filerGrpcAddress string, fn func(ctx context.Context, client filer_pb.SeaweedFilerClient) error) error {
|
|
if streamingMode {
|
|
return pb.WithGrpcClient(ctx, streamingMode, wfs.signature, func(grpcConnection *grpc.ClientConn) error {
|
|
return fn(ctx, filer_pb.NewSeaweedFilerClient(grpcConnection))
|
|
}, filerGrpcAddress, false, wfs.option.GrpcDialOption)
|
|
}
|
|
|
|
attemptCtx, cancel := context.WithCancel(ctx)
|
|
if callWait > 0 {
|
|
attemptCtx, cancel = context.WithTimeout(ctx, callWait)
|
|
}
|
|
defer cancel()
|
|
|
|
done := make(chan error, 1)
|
|
go func() {
|
|
done <- pb.WithGrpcClient(attemptCtx, streamingMode, wfs.signature, func(grpcConnection *grpc.ClientConn) error {
|
|
return fn(attemptCtx, filer_pb.NewSeaweedFilerClient(grpcConnection))
|
|
}, filerGrpcAddress, false, wfs.option.GrpcDialOption)
|
|
}()
|
|
|
|
select {
|
|
case err := <-done:
|
|
if err != nil && ctx.Err() == nil && attemptCtx.Err() == context.DeadlineExceeded {
|
|
// fn surfaced the attempt deadline itself; report it like the
|
|
// timer path so the failure reads as a filer timeout, not as a
|
|
// caller cancellation (which IsTransientError would not retry).
|
|
return status.Error(codes.Unavailable, fmt.Sprintf("filer %s: call timed out", filerGrpcAddress))
|
|
}
|
|
return err
|
|
case <-attemptCtx.Done():
|
|
// Give the callback one RPC's grace to unwind on its own; only if it
|
|
// ignored the attempt context does the cached channel get dropped —
|
|
// the collateral is borne by calls to the same unresponsive filer,
|
|
// which the walk is abandoning anyway.
|
|
drain := time.NewTimer(wfs.filerRPCWait())
|
|
defer drain.Stop()
|
|
select {
|
|
case <-done:
|
|
case <-drain.C:
|
|
pb.InvalidateGrpcConnection(filerGrpcAddress)
|
|
<-done
|
|
}
|
|
if ctx.Err() != nil {
|
|
return ctx.Err()
|
|
}
|
|
return status.Error(codes.Unavailable, fmt.Sprintf("filer %s: call timed out", filerGrpcAddress))
|
|
}
|
|
}
|
|
|
|
func (wfs *WFS) AdjustedUrl(location *filer_pb.Location) string {
|
|
if wfs.option.VolumeServerAccess == "publicUrl" {
|
|
return location.PublicUrl
|
|
}
|
|
return location.Url
|
|
}
|
|
|
|
func (wfs *WFS) GetDataCenter() string {
|
|
return wfs.option.DataCenter
|
|
}
|