Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support high availability for file download --task=75127660 #115

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 46 additions & 20 deletions internal/downloader/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@

start := time.Now()
exec := &execDownload{
ctx: context.Background(),
dl: dl,
fileMeta: fileMeta,
to: to,
client: dl.initClient(),
header: http.Header{},
downloadUri: downloadUri,
fileSize: fileSize,
ctx: context.Background(),
dl: dl,
fileMeta: fileMeta,
to: to,
client: dl.initClient(),
header: http.Header{},
downloadUris: []string{downloadUri},
fileSize: fileSize,
}
switch to {
case DownloadToFile:
Expand Down Expand Up @@ -180,17 +180,18 @@
}

type execDownload struct {
fileMeta *pbfs.FileMeta
ctx context.Context
dl *httpDownloader
to DownloadTo
bytes []byte
file *os.File
client *http.Client
header http.Header
downloadUri string
fileSize uint64
waitTimeMil int64
fileMeta *pbfs.FileMeta
ctx context.Context
dl *httpDownloader
to DownloadTo
bytes []byte
file *os.File
client *http.Client
header http.Header
downloadUri string // used for every request
downloadUris []string // returned by feed server
fileSize uint64
waitTimeMil int64
}

func (exec *execDownload) do() error {
Expand Down Expand Up @@ -226,8 +227,33 @@
sfs.SecondaryError{SpecificFailedReason: sfs.NoDownloadPermission,
Err: fmt.Errorf("get temporary download url failed, err: %s", err.Error())})
}
exec.downloadUri = resp.Url

exec.waitTimeMil = resp.WaitTimeMil
exec.downloadUris = resp.Urls

Check failure on line 232 in internal/downloader/http.go

View workflow job for this annotation

GitHub Actions / build

resp.Urls undefined (type *pbfs.GetDownloadURLResp has no field or method Urls)

Check failure on line 232 in internal/downloader/http.go

View workflow job for this annotation

GitHub Actions / lint

resp.Urls undefined (type *pbfs.GetDownloadURLResp has no field or method Urls)

Check failure on line 232 in internal/downloader/http.go

View workflow job for this annotation

GitHub Actions / lint

resp.Urls undefined (type *pbfs.GetDownloadURLResp has no field or method Urls)

Check failure on line 232 in internal/downloader/http.go

View workflow job for this annotation

GitHub Actions / lint

resp.Urls undefined (type *pbfs.GetDownloadURLResp has no field or method Urls)
logger.Debug("download uri info", slog.String("file", path.Join(exec.fileMeta.ConfigItemSpec.Path,
exec.fileMeta.ConfigItemSpec.Name)), slog.Any("uris", exec.downloadUris))
// 兼容老版服务端
if len(resp.Urls) == 0 {

Check failure on line 236 in internal/downloader/http.go

View workflow job for this annotation

GitHub Actions / build

resp.Urls undefined (type *pbfs.GetDownloadURLResp has no field or method Urls)

Check failure on line 236 in internal/downloader/http.go

View workflow job for this annotation

GitHub Actions / lint

resp.Urls undefined (type *pbfs.GetDownloadURLResp has no field or method Urls) (typecheck)

Check failure on line 236 in internal/downloader/http.go

View workflow job for this annotation

GitHub Actions / lint

resp.Urls undefined (type *pbfs.GetDownloadURLResp has no field or method Urls)) (typecheck)

Check failure on line 236 in internal/downloader/http.go

View workflow job for this annotation

GitHub Actions / lint

resp.Urls undefined (type *pbfs.GetDownloadURLResp has no field or method Urls)) (typecheck)
exec.downloadUris = []string{resp.Url}
}

var errs []error
for _, uri := range exec.downloadUris {
exec.downloadUri = uri
e := exec.download()
if e == nil {
return nil
}
errs = append(errs, e)
}

if len(errs) == 1 {
return errs[0]
}
return fmt.Errorf("master repo err: %v, slave repo err: %v", errs[0], errs[1])
}

func (exec *execDownload) download() error {
if exec.fileSize <= exec.dl.balanceDownloadByteSize {
// the file size is not big enough, download directly
if e := exec.downloadDirectlyWithRetry(); e != nil {
Expand Down
Loading