mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
* mount: stop the filer walk at a live filer's "not found" With several filers listed and some of them down, a lookup that the live filer answered with "not found" went on to the dead filers. Their dial error replaced the answer, so the walk retried it as a transient failure: the mount failed to start when filer.conf did not exist, and looking up a missing file or creating a new one failed with an I/O error after about 40 seconds. Stop at a missing entry the way a filer verdict already stops the walk, and keep the walk on the filer that answered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: test a live filer's "not found" next to dead filers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
174 lines
6.6 KiB
Go
174 lines
6.6 KiB
Go
package mount
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"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/security"
|
|
"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, and a consumer that
|
|
// stopped following are final whatever their message says, and the path or
|
|
// cause they name can contain "transport".
|
|
func isRetryableFilerCall(err error) bool {
|
|
return !filer_pb.IsFilerVerdict(err) && !endsFollowAttempt(err) && util.IsTransientError(err)
|
|
}
|
|
|
|
// endsFollowAttempt reports a metadata follow its consumer ended, for good or
|
|
// to resubscribe: no other filer should run the same attempt.
|
|
func endsFollowAttempt(err error) bool {
|
|
return errors.Is(err, pb.ErrStopFollowing) || errors.Is(err, pb.ErrResubscribe)
|
|
}
|
|
|
|
// 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 or a missing entry 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. A consumer that stopped following, or asked to
|
|
// resubscribe, is done with this attempt on every filer.
|
|
if filer_pb.IsFilerVerdict(err) || errors.Is(err, filer_pb.ErrNotFound) || endsFollowAttempt(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, wfs.newFilerClient(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, wfs.newFilerClient(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))
|
|
}
|
|
}
|
|
|
|
// newFilerClient authorizes each call through the client with the mount's
|
|
// filer token source, resolved per attempt so a retry carries a replaced
|
|
// token. The cached channel itself carries no identity. Creates and updates
|
|
// carry the assignment proofs of the new chunks they store.
|
|
func (wfs *WFS) newFilerClient(conn *grpc.ClientConn) filer_pb.SeaweedFilerClient {
|
|
return filer_pb.NewSeaweedFilerClient(wfs.chunkProofs.conn(security.WithFilerClientAuth(conn, wfs.option.FilerTokenSource)))
|
|
}
|
|
|
|
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
|
|
}
|