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

Bugfix: patch can't overwrite twice #558

Merged
merged 8 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 13 additions & 3 deletions components/cluster/command/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pingcap/tiup/pkg/cluster/task"
"github.com/pingcap/tiup/pkg/meta"
"github.com/pingcap/tiup/pkg/set"
"github.com/pingcap/tiup/pkg/utils"
tiuputils "github.com/pingcap/tiup/pkg/utils"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -186,13 +187,22 @@ func overwritePatch(clusterName, comp, packagePath string) error {
if err := os.MkdirAll(spec.ClusterPath(clusterName, spec.PatchDirName), 0755); err != nil {
return err
}

checksum, err := tiuputils.Checksum(packagePath)
if err != nil {
return err
}

tg := spec.ClusterPath(clusterName, spec.PatchDirName, comp+"-"+checksum[:7]+".tar.gz")
if err := tiuputils.CopyFile(packagePath, tg); err != nil {
return err
if !utils.IsExist(tg) {
if err := tiuputils.CopyFile(packagePath, tg); err != nil {
return err
}
}

symlink := spec.ClusterPath(clusterName, spec.PatchDirName, comp+".tar.gz")
if utils.IsExist(symlink) {
os.Remove(symlink)
}
return os.Symlink(tg, spec.ClusterPath(clusterName, spec.PatchDirName, comp+".tar.gz"))
return os.Symlink(tg, symlink)
}
2 changes: 1 addition & 1 deletion components/cluster/command/scale_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func scaleOut(clusterName, topoFile string, opt scaleOutOptions) error {

patchedComponents := set.NewStringSet()
newPart.IterInstance(func(instance spec.Instance) {
if exists := tiuputils.IsExist(spec.ClusterPath(clusterName, spec.PatchDirName, instance.ComponentName()+".tar.gz")); exists {
if tiuputils.IsExist(spec.ClusterPath(clusterName, spec.PatchDirName, instance.ComponentName()+".tar.gz")) {
patchedComponents.Insert(instance.ComponentName())
}
})
Expand Down
5 changes: 5 additions & 0 deletions tests/tiup-cluster/script/cmd_subtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ function cmd_subtest() {
tiup-cluster exec $name -N 172.19.0.102 --command "grep /home/tidb/deploy/tikv-20160/data /home/tidb/deploy/tikv-20160/scripts/run_tikv.sh"
tiup-cluster exec $name -N 172.19.0.103 --command "grep /home/tidb/my_kv_data /home/tidb/deploy/tikv-20160/scripts/run_tikv.sh"

# test patch overwrite
tiup-cluster --yes patch $name ~/.tiup/storage/cluster/packages/tidb-$version-linux-amd64.tar.gz -R tidb --overwrite
# overwrite with the same tarball twice
tiup-cluster --yes patch $name ~/.tiup/storage/cluster/packages/tidb-$version-linux-amd64.tar.gz -R tidb --overwrite

tiup-cluster --yes stop $name

tiup-cluster --yes restart $name
Expand Down