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

remove duplicate download when upgrade #2423

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions pkg/cluster/manager/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,11 @@ This operation will upgrade %s %s cluster %s to %s:%s`,

hasImported := false
for _, comp := range components {
compName := comp.Name()
version := comp.CalculateVersion(clusterVersion)

for _, inst := range comp.Instances() {
// Download component from repository
key := fmt.Sprintf("%s-%s-%s-%s", compName, version, inst.OS(), inst.Arch())
key := fmt.Sprintf("%s-%s-%s-%s", inst.ComponentSource(), version, inst.OS(), inst.Arch())
if _, found := uniqueComps[key]; !found {
uniqueComps[key] = struct{}{}
t := task.NewBuilder(m.logger).
Expand Down
16 changes: 7 additions & 9 deletions pkg/cluster/operation/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Download(component, nodeOS, arch string, version string) error {

resName := fmt.Sprintf("%s-%s", component, version)
fileName := fmt.Sprintf("%s-%s-%s.tar.gz", resName, nodeOS, arch)
srcPath := spec.ProfilePath(spec.TiUPPackageCacheDir, fileName)
targetPath := spec.ProfilePath(spec.TiUPPackageCacheDir, fileName)

if err := utils.MkdirAll(spec.ProfilePath(spec.TiUPPackageCacheDir), 0755); err != nil {
return err
Expand All @@ -46,17 +46,15 @@ func Download(component, nodeOS, arch string, version string) error {
return err
}

if utils.IsExist(srcPath) {
if err := repo.VerifyComponent(component, version, srcPath); err != nil {
os.Remove(srcPath)
}
}

// Download from repository if not exists
if utils.IsNotExist(srcPath) {
if err := repo.DownloadComponent(component, version, srcPath); err != nil {
if utils.IsNotExist(targetPath) {
if err := repo.DownloadComponent(component, version, targetPath); err != nil {
return err
}
} else {
if err := repo.VerifyComponent(component, version, targetPath); err != nil {
os.Remove(targetPath)
}
}
return nil
}
Loading