mirror of
https://github.com/chrislusf/seaweedfs
synced 2024-07-01 06:40:45 +02:00
refactoring
This commit is contained in:
parent
65ff7198fe
commit
973f6dd162
|
@ -331,8 +331,6 @@ func (worker *FileCopyWorker) uploadFileAsOne(task FileCopyTask, f *os.File) err
|
||||||
var mimeType string
|
var mimeType string
|
||||||
|
|
||||||
var chunks []*filer_pb.FileChunk
|
var chunks []*filer_pb.FileChunk
|
||||||
var assignResult *filer_pb.AssignVolumeResponse
|
|
||||||
var assignError error
|
|
||||||
|
|
||||||
if task.fileMode&os.ModeDir == 0 && task.fileSize > 0 {
|
if task.fileMode&os.ModeDir == 0 && task.fileSize > 0 {
|
||||||
|
|
||||||
|
@ -342,66 +340,32 @@ func (worker *FileCopyWorker) uploadFileAsOne(task FileCopyTask, f *os.File) err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = util.Retry("upload", func() error {
|
finalFileId, uploadResult, flushErr, _ := operation.UploadWithRetry(
|
||||||
// assign a volume
|
worker,
|
||||||
assignErr := pb.WithGrpcFilerClient(false, worker.filerAddress, worker.options.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
&filer_pb.AssignVolumeRequest{
|
||||||
|
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,
|
||||||
DiskType: *worker.options.diskType,
|
},
|
||||||
Path: task.destinationUrlPath,
|
&operation.UploadOption{
|
||||||
}
|
|
||||||
|
|
||||||
assignResult, assignError = client.AssignVolume(context.Background(), request)
|
|
||||||
if assignError != nil {
|
|
||||||
return fmt.Errorf("assign volume failure %v: %v", request, assignError)
|
|
||||||
}
|
|
||||||
if assignResult.Error != "" {
|
|
||||||
return fmt.Errorf("assign volume failure %v: %v", request, assignResult.Error)
|
|
||||||
}
|
|
||||||
if assignResult.Location.Url == "" {
|
|
||||||
return fmt.Errorf("assign volume failure %v: %v", request, assignResult)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if assignErr != nil {
|
|
||||||
return assignErr
|
|
||||||
}
|
|
||||||
|
|
||||||
// upload data
|
|
||||||
targetUrl := "http://" + assignResult.Location.Url + "/" + assignResult.FileId
|
|
||||||
uploadOption := &operation.UploadOption{
|
|
||||||
UploadUrl: targetUrl,
|
|
||||||
Filename: fileName,
|
Filename: fileName,
|
||||||
Cipher: worker.options.cipher,
|
Cipher: worker.options.cipher,
|
||||||
IsInputCompressed: false,
|
IsInputCompressed: false,
|
||||||
MimeType: mimeType,
|
MimeType: mimeType,
|
||||||
PairMap: nil,
|
PairMap: nil,
|
||||||
Jwt: security.EncodedJwt(assignResult.Auth),
|
},
|
||||||
}
|
func(host, fileId string) string {
|
||||||
uploadResult, err := operation.UploadData(data, uploadOption)
|
return fmt.Sprintf("http://%s/%s", host, fileId)
|
||||||
if err != nil {
|
},
|
||||||
return fmt.Errorf("upload data %v to %s: %v\n", fileName, targetUrl, err)
|
util.NewBytesReader(data),
|
||||||
}
|
)
|
||||||
if uploadResult.Error != "" {
|
if flushErr != nil {
|
||||||
return fmt.Errorf("upload %v to %s result: %v\n", fileName, targetUrl, uploadResult.Error)
|
return flushErr
|
||||||
}
|
|
||||||
if *worker.options.verbose {
|
|
||||||
fmt.Printf("uploaded %s to %s\n", fileName, targetUrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("copied %s => http://%s%s%s\n", f.Name(), worker.filerAddress.ToHttpAddress(), task.destinationUrlPath, fileName)
|
|
||||||
chunks = append(chunks, uploadResult.ToPbFileChunk(assignResult.FileId, 0))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("upload %v: %v\n", fileName, err)
|
|
||||||
}
|
}
|
||||||
|
chunks = append(chunks, uploadResult.ToPbFileChunk(finalFileId, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pb.WithGrpcFilerClient(false, worker.filerAddress, worker.options.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
if err := pb.WithGrpcFilerClient(false, worker.filerAddress, worker.options.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
|
Loading…
Reference in a new issue