add retry to assign volume

fix https://github.com/chrislusf/seaweedfs/issues/2056
This commit is contained in:
Chris Lu 2021-05-07 07:29:26 -07:00
parent 007401f3a0
commit 8f8738867f
5 changed files with 136 additions and 116 deletions

View file

@ -308,25 +308,27 @@ func (worker *FileCopyWorker) uploadFileAsOne(task FileCopyTask, f *os.File) err
} }
// assign a volume // assign a volume
err = pb.WithGrpcFilerClient(worker.filerGrpcAddress, worker.options.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error { err = util.Retry("assignVolume", func() error {
return pb.WithGrpcFilerClient(worker.filerGrpcAddress, worker.options.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
request := &filer_pb.AssignVolumeRequest{ request := &filer_pb.AssignVolumeRequest{
Count: 1, Count: 1,
Replication: *worker.options.replication, Replication: *worker.options.replication,
Collection: *worker.options.collection, Collection: *worker.options.collection,
TtlSec: worker.options.ttlSec, TtlSec: worker.options.ttlSec,
DiskType: *worker.options.diskType, DiskType: *worker.options.diskType,
Path: task.destinationUrlPath, Path: task.destinationUrlPath,
} }
assignResult, assignError = client.AssignVolume(context.Background(), request) assignResult, assignError = client.AssignVolume(context.Background(), request)
if assignError != nil { if assignError != nil {
return fmt.Errorf("assign volume failure %v: %v", request, assignError) return fmt.Errorf("assign volume failure %v: %v", request, assignError)
} }
if assignResult.Error != "" { if assignResult.Error != "" {
return fmt.Errorf("assign volume failure %v: %v", request, assignResult.Error) return fmt.Errorf("assign volume failure %v: %v", request, assignResult.Error)
} }
return nil return nil
})
}) })
if err != nil { if err != nil {
return fmt.Errorf("Failed to assign from %v: %v\n", worker.options.masters, err) return fmt.Errorf("Failed to assign from %v: %v\n", worker.options.masters, err)
@ -404,24 +406,26 @@ func (worker *FileCopyWorker) uploadFileInChunks(task FileCopyTask, f *os.File,
// assign a volume // assign a volume
var assignResult *filer_pb.AssignVolumeResponse var assignResult *filer_pb.AssignVolumeResponse
var assignError error var assignError error
err := pb.WithGrpcFilerClient(worker.filerGrpcAddress, worker.options.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error { err := util.Retry("assignVolume", func() error {
request := &filer_pb.AssignVolumeRequest{ return pb.WithGrpcFilerClient(worker.filerGrpcAddress, worker.options.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
Count: 1, request := &filer_pb.AssignVolumeRequest{
Replication: *worker.options.replication, Count: 1,
Collection: *worker.options.collection, Replication: *worker.options.replication,
TtlSec: worker.options.ttlSec, Collection: *worker.options.collection,
DiskType: *worker.options.diskType, TtlSec: worker.options.ttlSec,
Path: task.destinationUrlPath + fileName, DiskType: *worker.options.diskType,
} Path: task.destinationUrlPath + fileName,
}
assignResult, assignError = client.AssignVolume(context.Background(), request) assignResult, assignError = client.AssignVolume(context.Background(), request)
if assignError != nil { if assignError != nil {
return fmt.Errorf("assign volume failure %v: %v", request, assignError) return fmt.Errorf("assign volume failure %v: %v", request, assignError)
} }
if assignResult.Error != "" { if assignResult.Error != "" {
return fmt.Errorf("assign volume failure %v: %v", request, assignResult.Error) return fmt.Errorf("assign volume failure %v: %v", request, assignResult.Error)
} }
return nil return nil
})
}) })
if err != nil { if err != nil {
fmt.Printf("Failed to assign from %v: %v\n", worker.options.masters, err) fmt.Printf("Failed to assign from %v: %v\n", worker.options.masters, err)

View file

@ -20,35 +20,36 @@ func (wfs *WFS) saveDataAsChunk(fullPath util.FullPath, writeOnly bool) filer.Sa
var auth security.EncodedJwt var auth security.EncodedJwt
if err := wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { if err := wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
return util.Retry("assignVolume", func() error {
request := &filer_pb.AssignVolumeRequest{
Count: 1,
Replication: wfs.option.Replication,
Collection: wfs.option.Collection,
TtlSec: wfs.option.TtlSec,
DiskType: string(wfs.option.DiskType),
DataCenter: wfs.option.DataCenter,
Path: string(fullPath),
}
request := &filer_pb.AssignVolumeRequest{ resp, err := client.AssignVolume(context.Background(), request)
Count: 1, if err != nil {
Replication: wfs.option.Replication, glog.V(0).Infof("assign volume failure %v: %v", request, err)
Collection: wfs.option.Collection, return err
TtlSec: wfs.option.TtlSec, }
DiskType: string(wfs.option.DiskType), if resp.Error != "" {
DataCenter: wfs.option.DataCenter, return fmt.Errorf("assign volume failure %v: %v", request, resp.Error)
Path: string(fullPath), }
}
resp, err := client.AssignVolume(context.Background(), request) fileId, auth = resp.FileId, security.EncodedJwt(resp.Auth)
if err != nil { loc := &filer_pb.Location{
glog.V(0).Infof("assign volume failure %v: %v", request, err) Url: resp.Url,
return err PublicUrl: resp.PublicUrl,
} }
if resp.Error != "" { host = wfs.AdjustedUrl(loc)
return fmt.Errorf("assign volume failure %v: %v", request, resp.Error) collection, replication = resp.Collection, resp.Replication
}
fileId, auth = resp.FileId, security.EncodedJwt(resp.Auth) return nil
loc := &filer_pb.Location{ })
Url: resp.Url,
PublicUrl: resp.PublicUrl,
}
host = wfs.AdjustedUrl(loc)
collection, replication = resp.Collection, resp.Replication
return nil
}); err != nil { }); err != nil {
return nil, "", "", fmt.Errorf("filerGrpcAddress assign volume: %v", err) return nil, "", "", fmt.Errorf("filerGrpcAddress assign volume: %v", err)
} }

View file

@ -3,6 +3,7 @@ package broker
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/chrislusf/seaweedfs/weed/security"
"io" "io"
"github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/glog"
@ -10,7 +11,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/pb" "github.com/chrislusf/seaweedfs/weed/pb"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/pb/messaging_pb" "github.com/chrislusf/seaweedfs/weed/pb/messaging_pb"
"github.com/chrislusf/seaweedfs/weed/security"
"github.com/chrislusf/seaweedfs/weed/util" "github.com/chrislusf/seaweedfs/weed/util"
) )
@ -53,26 +53,33 @@ func (broker *MessageBroker) assignAndUpload(topicConfig *messaging_pb.TopicConf
// assign a volume location // assign a volume location
if err := broker.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { if err := broker.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
request := &filer_pb.AssignVolumeRequest{ assignErr := util.Retry("assignVolume", func() error {
Count: 1, request := &filer_pb.AssignVolumeRequest{
Replication: topicConfig.Replication, Count: 1,
Collection: topicConfig.Collection, Replication: topicConfig.Replication,
} Collection: topicConfig.Collection,
}
resp, err := client.AssignVolume(context.Background(), request) resp, err := client.AssignVolume(context.Background(), request)
if err != nil { if err != nil {
glog.V(0).Infof("assign volume failure %v: %v", request, err) glog.V(0).Infof("assign volume failure %v: %v", request, err)
return err return err
} }
if resp.Error != "" { if resp.Error != "" {
return fmt.Errorf("assign volume failure %v: %v", request, resp.Error) return fmt.Errorf("assign volume failure %v: %v", request, resp.Error)
} }
assignResult.Auth = security.EncodedJwt(resp.Auth) assignResult.Auth = security.EncodedJwt(resp.Auth)
assignResult.Fid = resp.FileId assignResult.Fid = resp.FileId
assignResult.Url = resp.Url assignResult.Url = resp.Url
assignResult.PublicUrl = resp.PublicUrl assignResult.PublicUrl = resp.PublicUrl
assignResult.Count = uint64(resp.Count) assignResult.Count = uint64(resp.Count)
return nil
})
if assignErr != nil {
return assignErr
}
return nil return nil
}); err != nil { }); err != nil {

View file

@ -71,29 +71,30 @@ func (fs *FilerSink) fetchAndWrite(sourceChunk *filer_pb.FileChunk, path string)
var auth security.EncodedJwt var auth security.EncodedJwt
if err := fs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { if err := fs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
return util.Retry("assignVolume", func() error {
request := &filer_pb.AssignVolumeRequest{
Count: 1,
Replication: fs.replication,
Collection: fs.collection,
TtlSec: fs.ttlSec,
DataCenter: fs.dataCenter,
DiskType: fs.diskType,
Path: path,
}
request := &filer_pb.AssignVolumeRequest{ resp, err := client.AssignVolume(context.Background(), request)
Count: 1, if err != nil {
Replication: fs.replication, glog.V(0).Infof("assign volume failure %v: %v", request, err)
Collection: fs.collection, return err
TtlSec: fs.ttlSec, }
DataCenter: fs.dataCenter, if resp.Error != "" {
DiskType: fs.diskType, return fmt.Errorf("assign volume failure %v: %v", request, resp.Error)
Path: path, }
}
resp, err := client.AssignVolume(context.Background(), request) fileId, host, auth = resp.FileId, resp.Url, security.EncodedJwt(resp.Auth)
if err != nil {
glog.V(0).Infof("assign volume failure %v: %v", request, err)
return err
}
if resp.Error != "" {
return fmt.Errorf("assign volume failure %v: %v", request, resp.Error)
}
fileId, host, auth = resp.FileId, resp.Url, security.EncodedJwt(resp.Auth) return nil
})
return nil
}); err != nil { }); err != nil {
return "", fmt.Errorf("filerGrpcAddress assign volume: %v", err) return "", fmt.Errorf("filerGrpcAddress assign volume: %v", err)
} }

View file

@ -380,25 +380,32 @@ func (f *WebDavFile) saveDataAsChunk(reader io.Reader, name string, offset int64
ctx := context.Background() ctx := context.Background()
request := &filer_pb.AssignVolumeRequest{ assignErr := util.Retry("assignVolume", func() error {
Count: 1, request := &filer_pb.AssignVolumeRequest{
Replication: f.fs.option.Replication, Count: 1,
Collection: f.fs.option.Collection, Replication: f.fs.option.Replication,
DiskType: f.fs.option.DiskType, Collection: f.fs.option.Collection,
Path: name, DiskType: f.fs.option.DiskType,
} Path: name,
}
resp, err := client.AssignVolume(ctx, request) resp, err := client.AssignVolume(ctx, request)
if err != nil { if err != nil {
glog.V(0).Infof("assign volume failure %v: %v", request, err) glog.V(0).Infof("assign volume failure %v: %v", request, err)
return err return err
} }
if resp.Error != "" { if resp.Error != "" {
return fmt.Errorf("assign volume failure %v: %v", request, resp.Error) return fmt.Errorf("assign volume failure %v: %v", request, resp.Error)
} }
fileId, host, auth = resp.FileId, resp.Url, security.EncodedJwt(resp.Auth) fileId, host, auth = resp.FileId, resp.Url, security.EncodedJwt(resp.Auth)
f.collection, f.replication = resp.Collection, resp.Replication f.collection, f.replication = resp.Collection, resp.Replication
return nil
})
if assignErr != nil {
return assignErr
}
return nil return nil
}); flushErr != nil { }); flushErr != nil {