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

Mirror clone err #2309

Merged
merged 2 commits into from
Nov 10, 2023
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
7 changes: 1 addition & 6 deletions cmd/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

"github.com/fatih/color"
perrs "github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cluster/spec"
"github.com/pingcap/tiup/pkg/environment"
"github.com/pingcap/tiup/pkg/localdata"
"github.com/pingcap/tiup/pkg/repository"
Expand Down Expand Up @@ -990,10 +989,6 @@ func newMirrorCloneCmd() *cobra.Command {
}
}()

var versionMapper = func(comp string) string {
return spec.TiDBComponentVersion(comp, "")
}

// format input versions
versionList := make([]string, 0)
for _, ver := range args[1:] {
Expand All @@ -1004,7 +999,7 @@ func newMirrorCloneCmd() *cobra.Command {
versionList = append(versionList, v)
}

return repository.CloneMirror(repo, components, versionMapper, args[0], versionList, options)
return repository.CloneMirror(repo, components, args[0], versionList, options)
},
}

Expand Down
19 changes: 0 additions & 19 deletions pkg/cluster/spec/bindversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,6 @@ import (
"strings"
)

// TiDBComponentVersion maps the TiDB version to the third components binding version
// Empty version should be treated as the last stable one
func TiDBComponentVersion(comp, version string) string {
switch comp {
case ComponentAlertmanager,
ComponentBlackboxExporter,
ComponentNodeExporter,
ComponentCheckCollector,
ComponentSpark,
ComponentTiSpark,
ComponentTiKVCDC: // TiKV-CDC use individual version.
return ""
case ComponentTiProxy:
return "nightly"
default:
return version
}
}

// ComponentSubDir maps a component with version to a subdir if needed
func ComponentSubDir(comp, version string) string {
if comp == ComponentSpark {
Expand Down
110 changes: 62 additions & 48 deletions pkg/repository/clone_mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type CloneOptions struct {
// CloneMirror clones a local mirror from the remote repository
func CloneMirror(repo *V1Repository,
components []string,
tidbClusterVersionMapper func(string) string,
targetDir string,
selectedVersions []string,
options CloneOptions) error {
Expand Down Expand Up @@ -149,7 +148,7 @@ func CloneMirror(repo *V1Repository,
snapshot := v1manifest.NewSnapshot(initTime)
snapshot.SetExpiresAt(expiresAt)

componentManifests, err := cloneComponents(repo, components, selectedVersions, tidbClusterVersionMapper, targetDir, tmpDir, options)
componentManifests, err := cloneComponents(repo, components, selectedVersions, targetDir, tmpDir, options)
if err != nil {
return err
}
Expand Down Expand Up @@ -246,7 +245,6 @@ func CloneMirror(repo *V1Repository,

func cloneComponents(repo *V1Repository,
components, selectedVersions []string,
tidbClusterVersionMapper func(string) string,
targetDir, tmpDir string,
options CloneOptions) (map[string]*v1manifest.Component, error) {
compManifests := map[string]*v1manifest.Component{}
Expand All @@ -265,7 +263,10 @@ func cloneComponents(repo *V1Repository,
return nil, errors.Annotatef(err, "fetch component '%s' manifest failed", name)
}

vs := combineVersions(options.Components[name], tidbClusterVersionMapper, manifest, options.OSs, options.Archs, selectedVersions)
vs, err := combineVersions(options.Components[name], manifest, options.OSs, options.Archs, selectedVersions)
if err != nil {
return nil, err
}

var newManifest *v1manifest.Component
if options.Full {
Expand Down Expand Up @@ -317,8 +318,8 @@ func cloneComponents(repo *V1Repository,
continue
}
name, versionItem := name, versionItem
tickets <- struct{}{}
errG.Go(func() error {
tickets <- struct{}{}
defer func() { <-tickets }()

err := download(targetDir, tmpDir, repo, &versionItem)
Expand Down Expand Up @@ -419,31 +420,19 @@ func checkVersion(options CloneOptions, versions set.StringSet, version string)
return false
}

func combineVersions(versions *[]string,
tidbClusterVersionMapper func(string) string,
func combineVersions(componentVersions *[]string,
manifest *v1manifest.Component, oss, archs,
selectedVersions []string) set.StringSet {
if (versions == nil || len(*versions) < 1) && len(selectedVersions) < 1 {
return nil
}

if bindver := tidbClusterVersionMapper(manifest.ID); bindver != "" {
return set.NewStringSet(bindver)
globalVersions []string) (set.StringSet, error) {
if (componentVersions == nil || len(*componentVersions) < 1) && len(globalVersions) < 1 {
return nil, errors.New("no version specified")
}

result := set.NewStringSet()
if versions != nil && len(*versions) > 0 {
result = set.NewStringSet(*versions...)
}

// Some components version binding to TiDB
coreSuites := set.NewStringSet("tidb", "tikv", "pd", "tiflash", "prometheus", "grafana", "ctl", "cdc")

for _, os := range oss {
for _, arch := range archs {
platform := PlatformString(os, arch)
versions := manifest.VersionList(platform)
if versions == nil {
versionList := manifest.VersionList(platform)
if versionList == nil {
continue
}

Expand All @@ -455,41 +444,66 @@ func combineVersions(versions *[]string,
}
}

for _, selectedVersion := range selectedVersions {
if selectedVersion == utils.NightlyVersionAlias {
selectedVersion = manifest.Nightly
}
if componentVersions != nil && len(*componentVersions) > 0 {
for _, selectedVersion := range *componentVersions {
fmt.Printf("%s %s/%s selected version is %s\n", manifest.ID, os, arch, selectedVersion)
if selectedVersion == utils.NightlyVersionAlias {
selectedVersion = manifest.Nightly
}

if selectedVersion == utils.LatestVersionAlias {
latest := manifest.LatestVersion(platform)
if latest == "" {
continue
if selectedVersion == utils.LatestVersionAlias {
latest := manifest.LatestVersion(platform)
if latest == "" {
continue
}

fmt.Printf("%s %s/%s found the lastest version %s\n", manifest.ID, os, arch, latest)
// set latest version
selectedVersion = latest
}

fmt.Printf("%s %s/%s found the lastest version %s\n", manifest.ID, os, arch, latest)
// set latest version
selectedVersion = latest
_, found := versionList[selectedVersion]
fmt.Println(found)
if !found {
return nil, errors.Errorf("version %s not found in %s %s/%s", selectedVersion, manifest.ID, os, arch)
}
result.Insert(selectedVersion)
}
} else {
for _, selectedVersion := range globalVersions {
if selectedVersion == utils.NightlyVersionAlias {
selectedVersion = manifest.Nightly
}

_, found := versions[selectedVersion]
// Some TiUP components won't be bound version with TiDB, if cannot find
// selected version we download the latest version to as a alternative
if !found && !coreSuites.Exist(manifest.ID) {
// Use the latest stable versionS if the selected version doesn't exist in specific platform
latest := manifest.LatestVersion(platform)
if latest == "" {
continue
if selectedVersion == utils.LatestVersionAlias {
latest := manifest.LatestVersion(platform)
if latest == "" {
continue
}

fmt.Printf("%s %s/%s found the lastest version %s\n", manifest.ID, os, arch, latest)
// set latest version
selectedVersion = latest
}
if selectedVersion != utils.LatestVersionAlias {
fmt.Printf("%s %s/%s %s not found, using %s instead.\n", manifest.ID, os, arch, selectedVersion, latest)

_, found := versionList[selectedVersion]
// Some TiUP components won't be bound version with TiDB, if cannot find
// selected version we download the latest version to as a alternative
if !found {
// Use the latest stable versionS if the selected version doesn't exist in specific platform
latest := manifest.LatestVersion(platform)
if latest == "" {
continue
}
if selectedVersion != utils.LatestVersionAlias {
fmt.Printf("%s %s/%s %s not found, using %s instead.\n", manifest.ID, os, arch, selectedVersion, latest)
}
selectedVersion = latest
}
selectedVersion = latest
}
if !result.Exist(selectedVersion) {
result.Insert(selectedVersion)
}
}
}
}
return result
return result, nil
}
Loading