Skip to content

Commit

Permalink
remove duplicate download when upgrade (#2423)
Browse files Browse the repository at this point in the history
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
nexustar and ti-chi-bot[bot] authored May 30, 2024
1 parent 647d508 commit 3352a93
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
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
}

0 comments on commit 3352a93

Please sign in to comment.