Skip to content

Commit f88a1e4

Browse files
committed
cluster: prompt for instance restart
1 parent 6552f30 commit f88a1e4

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

components/cluster/command/upgrade.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
package command
1515

1616
import (
17+
"time"
18+
1719
"github.com/pingcap/tiup/pkg/cluster/spec"
1820
"github.com/pingcap/tiup/pkg/utils"
1921
"github.com/spf13/cobra"
@@ -23,6 +25,7 @@ func newUpgradeCmd() *cobra.Command {
2325
offlineMode := false
2426
ignoreVersionCheck := false
2527
var tidbVer, tikvVer, pdVer, tsoVer, schedulingVer, tiflashVer, kvcdcVer, dashboardVer, cdcVer, alertmanagerVer, nodeExporterVer, blackboxExporterVer, tiproxyVer string
28+
var restartTimeout time.Duration
2629

2730
cmd := &cobra.Command{
2831
Use: "upgrade <cluster-name> <version>",
@@ -57,7 +60,7 @@ func newUpgradeCmd() *cobra.Command {
5760
spec.ComponentNodeExporter: nodeExporterVer,
5861
}
5962

60-
return cm.Upgrade(clusterName, version, componentVersions, gOpt, skipConfirm, offlineMode, ignoreVersionCheck)
63+
return cm.Upgrade(clusterName, version, componentVersions, gOpt, skipConfirm, offlineMode, ignoreVersionCheck, restartTimeout)
6164
},
6265
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
6366
switch len(args) {
@@ -89,5 +92,6 @@ func newUpgradeCmd() *cobra.Command {
8992
cmd.Flags().StringVar(&nodeExporterVer, "node-exporter-version", "", "Fix the version of node-exporter and no longer follows the cluster version.")
9093
cmd.Flags().StringVar(&blackboxExporterVer, "blackbox-exporter-version", "", "Fix the version of blackbox-exporter and no longer follows the cluster version.")
9194
cmd.Flags().StringVar(&tiproxyVer, "tiproxy-version", "", "Fix the version of tiproxy and no longer follows the cluster version.")
95+
cmd.Flags().DurationVar(&restartTimeout, "restart-timeout", time.Second*0, "Timeout for after upgrade prompt")
9296
return cmd
9397
}

components/dm/command/upgrade.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
package command
1515

1616
import (
17+
"time"
18+
1719
"github.com/spf13/cobra"
1820
)
1921

@@ -28,7 +30,7 @@ func newUpgradeCmd() *cobra.Command {
2830
return cmd.Help()
2931
}
3032

31-
return cm.Upgrade(args[0], args[1], nil, gOpt, skipConfirm, offlineMode, ignoreVersionCheck)
33+
return cm.Upgrade(args[0], args[1], nil, gOpt, skipConfirm, offlineMode, ignoreVersionCheck, time.Second*0)
3234
},
3335
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
3436
switch len(args) {

pkg/cluster/manager/patch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (m *Manager) Patch(name string, packagePath string, opt operator.Options, o
105105
return nil
106106
}
107107
// TBD: should patch be treated as an upgrade?
108-
return operator.Upgrade(ctx, topo, opt, tlsCfg, base.Version, base.Version)
108+
return operator.Upgrade(ctx, topo, opt, tlsCfg, base.Version, base.Version, nil)
109109
}).
110110
Build()
111111

pkg/cluster/manager/reload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (m *Manager) Reload(name string, gOpt operator.Options, skipRestart, skipCo
124124
return err
125125
}
126126
b.Func("Upgrade Cluster", func(ctx context.Context) error {
127-
return operator.Upgrade(ctx, topo, gOpt, tlsCfg, base.Version, base.Version)
127+
return operator.Upgrade(ctx, topo, gOpt, tlsCfg, base.Version, base.Version, nil)
128128
})
129129
}
130130

pkg/cluster/manager/upgrade.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
)
4040

4141
// Upgrade the cluster.
42-
func (m *Manager) Upgrade(name string, clusterVersion string, componentVersions map[string]string, opt operator.Options, skipConfirm, offline, ignoreVersionCheck bool) error {
42+
func (m *Manager) Upgrade(name string, clusterVersion string, componentVersions map[string]string, opt operator.Options, skipConfirm, offline, ignoreVersionCheck bool, restartTimeout time.Duration) error {
4343
if !skipConfirm && strings.ToLower(opt.DisplayMode) != "json" {
4444
for _, v := range componentVersions {
4545
if v != "" {
@@ -121,11 +121,12 @@ func (m *Manager) Upgrade(name string, clusterVersion string, componentVersions
121121
}
122122

123123
m.logger.Warnf(`%s
124-
This operation will upgrade %s %s cluster %s to %s:%s`,
124+
This operation will upgrade %s %s cluster %s (with a concurrency of %d) to %s:%s`,
125125
color.YellowString("Before the upgrade, it is recommended to read the upgrade guide at https://docs.pingcap.com/tidb/stable/upgrade-tidb-using-tiup and finish the preparation steps."),
126126
m.sysName,
127127
color.HiYellowString(base.Version),
128128
color.HiYellowString(name),
129+
opt.Concurrency,
129130
color.HiYellowString(clusterVersion),
130131
compVersionMsg)
131132
if !skipConfirm {
@@ -317,7 +318,23 @@ This operation will upgrade %s %s cluster %s to %s:%s`,
317318
}
318319
nopt := opt
319320
nopt.Roles = restartComponents
320-
return operator.Upgrade(ctx, topo, nopt, tlsCfg, base.Version, clusterVersion)
321+
waitFunc := func() {}
322+
if restartTimeout.Nanoseconds() > 0 {
323+
waitFunc = func() {
324+
// A tui.PromptWithTimeout(str, time.Duration) would have been nice
325+
ch := make(chan any, 1)
326+
go func() {
327+
tui.Prompt(fmt.Sprintf("\nPress any key to continue (timeout %s)", restartTimeout))
328+
ch <- nil
329+
}()
330+
select {
331+
case <-time.After(restartTimeout):
332+
fmt.Printf("\nTimeout, continueing\n")
333+
case <-ch:
334+
}
335+
}
336+
}
337+
return operator.Upgrade(ctx, topo, nopt, tlsCfg, base.Version, clusterVersion, waitFunc)
321338
}).
322339
Build()
323340

pkg/cluster/operation/upgrade.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ var (
3939
increaseLimitPoint = checkpoint.Register()
4040
)
4141

42+
type UpgradeWaitFunc func()
43+
4244
// Upgrade the cluster. (actually, it's rolling restart)
4345
func Upgrade(
4446
ctx context.Context,
@@ -47,6 +49,7 @@ func Upgrade(
4749
tlsCfg *tls.Config,
4850
currentVersion string,
4951
targetVersion string,
52+
waitFunc UpgradeWaitFunc,
5053
) error {
5154
roleFilter := set.NewStringSet(options.Roles...)
5255
nodeFilter := set.NewStringSet(options.Nodes...)
@@ -189,6 +192,8 @@ func Upgrade(
189192
if err := upgradeInstance(ctx, topo, instance, options, tlsCfg); err != nil {
190193
return err
191194
}
195+
196+
waitFunc()
192197
}
193198

194199
// process deferred instances
@@ -288,6 +293,8 @@ func upgradeInstance(
288293
return err
289294
}
290295

296+
297+
291298
return nil
292299
}
293300

0 commit comments

Comments
 (0)