From 79680d346d05c1d0064518047f3c1ba8f5b3ab44 Mon Sep 17 00:00:00 2001 From: nexustar Date: Thu, 30 May 2024 16:40:43 +0800 Subject: [PATCH] remove duplicate download when upgrade --- pkg/cluster/manager/upgrade.go | 3 +-- pkg/cluster/operation/download.go | 16 +++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pkg/cluster/manager/upgrade.go b/pkg/cluster/manager/upgrade.go index 061182a91e..65c08ea384 100644 --- a/pkg/cluster/manager/upgrade.go +++ b/pkg/cluster/manager/upgrade.go @@ -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). diff --git a/pkg/cluster/operation/download.go b/pkg/cluster/operation/download.go index 4063fcdeb7..a2dfb6a6f5 100644 --- a/pkg/cluster/operation/download.go +++ b/pkg/cluster/operation/download.go @@ -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 @@ -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 }