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

Support upgrade/patch offline tidb/dm cluster #1096

Merged
merged 3 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions components/cluster/command/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (

func newPatchCmd() *cobra.Command {
var (
overwrite bool
overwrite bool
offlineMode bool
)
cmd := &cobra.Command{
Use: "patch <cluster-name> <package-path>",
Expand All @@ -40,13 +41,14 @@ func newPatchCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return cm.Patch(clusterName, args[1], gOpt, overwrite)
return cm.Patch(clusterName, args[1], gOpt, overwrite, offlineMode)
},
}

cmd.Flags().BoolVar(&overwrite, "overwrite", false, "Use this package in the future scale-out operations")
cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Specify the nodes")
cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Specify the roles")
cmd.Flags().Uint64Var(&gOpt.APITimeout, "transfer-timeout", 300, "Timeout in seconds when transferring PD and TiKV store leaders")
cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Patch a stopped cluster")
return cmd
}
5 changes: 4 additions & 1 deletion components/cluster/command/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
)

func newUpgradeCmd() *cobra.Command {
offlineMode := false

cmd := &cobra.Command{
Use: "upgrade <cluster-name> <version>",
Short: "Upgrade a specified TiDB cluster",
Expand All @@ -35,12 +37,13 @@ func newUpgradeCmd() *cobra.Command {
teleCommand = append(teleCommand, scrubClusterName(clusterName))
teleCommand = append(teleCommand, version)

return cm.Upgrade(clusterName, version, gOpt, skipConfirm)
return cm.Upgrade(clusterName, version, gOpt, skipConfirm, offlineMode)
},
}
cmd.Flags().BoolVar(&gOpt.Force, "force", false, "Force upgrade without transferring PD leader")
cmd.Flags().Uint64Var(&gOpt.APITimeout, "transfer-timeout", 300, "Timeout in seconds when transferring PD and TiKV store leaders")
cmd.Flags().BoolVarP(&gOpt.IgnoreConfigCheck, "ignore-config-check", "", false, "Ignore the config check result")
cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Upgrade a stopped cluster")

return cmd
}
6 changes: 4 additions & 2 deletions components/dm/command/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (

func newPatchCmd() *cobra.Command {
var (
overwrite bool
overwrite bool
offlineMode bool
)
cmd := &cobra.Command{
Use: "patch <cluster-name> <package-path>",
Expand All @@ -40,12 +41,13 @@ func newPatchCmd() *cobra.Command {

clusterName := args[0]

return cm.Patch(clusterName, args[1], gOpt, overwrite)
return cm.Patch(clusterName, args[1], gOpt, overwrite, offlineMode)
},
}

cmd.Flags().BoolVar(&overwrite, "overwrite", false, "Use this package in the future scale-out operations")
cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Specify the nodes")
cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Specify the roles")
cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Patch a stopped cluster")
return cmd
}
6 changes: 5 additions & 1 deletion components/dm/command/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
)

func newUpgradeCmd() *cobra.Command {
offlineMode := false

cmd := &cobra.Command{
Use: "upgrade <cluster-name> <version>",
Short: "Upgrade a specified DM cluster",
Expand All @@ -26,9 +28,11 @@ func newUpgradeCmd() *cobra.Command {
return cmd.Help()
}

return cm.Upgrade(args[0], args[1], gOpt, skipConfirm)
return cm.Upgrade(args[0], args[1], gOpt, skipConfirm, offlineMode)
},
}

cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Upgrade a stopped cluster")

return cmd
}
5 changes: 4 additions & 1 deletion pkg/cluster/manager/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

// Patch the cluster.
func (m *Manager) Patch(name string, packagePath string, opt operator.Options, overwrite bool) error {
func (m *Manager) Patch(name string, packagePath string, opt operator.Options, overwrite, offline bool) error {
metadata, err := m.meta(name)
if err != nil {
return err
Expand Down Expand Up @@ -70,6 +70,9 @@ func (m *Manager) Patch(name string, packagePath string, opt operator.Options, o
t := m.sshTaskBuilder(name, topo, base.User, opt).
Parallel(false, replacePackageTasks...).
Func("UpgradeCluster", func(ctx context.Context) error {
if offline {
return nil
}
return operator.Upgrade(ctx, topo, opt, tlsCfg)
}).
Build()
Expand Down
5 changes: 4 additions & 1 deletion pkg/cluster/manager/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

// Upgrade the cluster.
func (m *Manager) Upgrade(name string, clusterVersion string, opt operator.Options, skipConfirm bool) error {
func (m *Manager) Upgrade(name string, clusterVersion string, opt operator.Options, skipConfirm, offline bool) error {
metadata, err := m.meta(name)
if err != nil {
return err
Expand Down Expand Up @@ -167,6 +167,9 @@ func (m *Manager) Upgrade(name string, clusterVersion string, opt operator.Optio
Parallel(false, downloadCompTasks...).
Parallel(opt.Force, copyCompTasks...).
Func("UpgradeCluster", func(ctx context.Context) error {
if offline {
return nil
}
return operator.Upgrade(ctx, topo, opt, tlsCfg)
}).
Build()
Expand Down
3 changes: 3 additions & 0 deletions tests/tiup-cluster/script/cmd_subtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ function cmd_subtest() {

tiup-cluster $client --yes start $name

# Patch a stopped cluster
tiup-cluster $client --yes patch $name ~/.tiup/storage/cluster/packages/tidb-v$version-linux-amd64.tar.gz -R tidb --offline

tiup-cluster $client _test $name writable

# check the data dir of tikv
Expand Down