Skip to content

Commit

Permalink
Upgrade TiCDC before TiKV and PD when cluster is equal or greater tha…
Browse files Browse the repository at this point in the history
…n v5.1.0 (#2253)
  • Loading branch information
KanShiori authored Aug 21, 2023
1 parent 2feb74b commit af2aa2a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/dm/spec/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func (topo *Specification) ComponentsByStartOrder() (comps []Component) {
}

// ComponentsByUpdateOrder return component in the order need to be updated.
func (topo *Specification) ComponentsByUpdateOrder() (comps []Component) {
func (topo *Specification) ComponentsByUpdateOrder(curVer string) (comps []Component) {
// "dm-master", "dm-worker"
comps = append(comps, &DMMasterComponent{topo})
comps = append(comps, &DMWorkerComponent{topo})
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/manager/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func checkSystemInfo(

roleFilter := set.NewStringSet(gOpt.Roles...)
nodeFilter := set.NewStringSet(gOpt.Nodes...)
components := topo.ComponentsByUpdateOrder()
components := topo.ComponentsByStartOrder()
components = operator.FilterComponent(components, roleFilter)

for _, comp := range components {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/manager/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Do you want to continue? [y/N]:`,
}

hasImported := false
for _, comp := range topo.ComponentsByUpdateOrder() {
for _, comp := range topo.ComponentsByUpdateOrder(base.Version) {
for _, inst := range comp.Instances() {
compName := inst.ComponentName()

Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/operation/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Upgrade(
) error {
roleFilter := set.NewStringSet(options.Roles...)
nodeFilter := set.NewStringSet(options.Nodes...)
components := topo.ComponentsByUpdateOrder()
components := topo.ComponentsByUpdateOrder(currentVersion)
components = FilterComponent(components, roleFilter)
logger := ctx.Value(logprinter.ContextKeyLogger).(*logprinter.Logger)

Expand Down
16 changes: 12 additions & 4 deletions pkg/cluster/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ type Topology interface {
// Instances() []Instance
ComponentsByStartOrder() []Component
ComponentsByStopOrder() []Component
ComponentsByUpdateOrder() []Component
ComponentsByUpdateOrder(curVer string) []Component
IterInstance(fn func(instance Instance), concurrency ...int)
GetMonitoredOptions() *MonitoredOptions
// count how many time a path is used by instances in cluster
Expand Down Expand Up @@ -728,16 +728,24 @@ func (s *Specification) ComponentsByStartOrder() (comps []Component) {
}

// ComponentsByUpdateOrder return component in the order need to be updated.
func (s *Specification) ComponentsByUpdateOrder() (comps []Component) {
// "tiflash", "pd", "dashboard", "tikv", "pump", "tidb", "drainer", "cdc", "prometheus", "grafana", "alertmanager"
func (s *Specification) ComponentsByUpdateOrder(curVer string) (comps []Component) {
// Ref: https://github.com/pingcap/tiup/issues/2166
cdcUpgradeBeforePDTiKVTiDB := tidbver.TiCDCUpgradeBeforePDTiKVTiDB(curVer)

// "tiflash", <"cdc">, "pd", "dashboard", "tikv", "pump", "tidb", "drainer", <"cdc>", "prometheus", "grafana", "alertmanager"
comps = append(comps, &TiFlashComponent{s})
if cdcUpgradeBeforePDTiKVTiDB {
comps = append(comps, &CDCComponent{s})
}
comps = append(comps, &PDComponent{s})
comps = append(comps, &DashboardComponent{s})
comps = append(comps, &TiKVComponent{s})
comps = append(comps, &PumpComponent{s})
comps = append(comps, &TiDBComponent{s})
comps = append(comps, &DrainerComponent{s})
comps = append(comps, &CDCComponent{s})
if !cdcUpgradeBeforePDTiKVTiDB {
comps = append(comps, &CDCComponent{s})
}
comps = append(comps, &MonitorComponent{s})
comps = append(comps, &GrafanaComponent{s})
comps = append(comps, &AlertManagerComponent{s})
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/spec/spec_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (t *TestTopology) ComponentsByStopOrder() []Component {
return nil
}

func (t *TestTopology) ComponentsByUpdateOrder() []Component {
func (t *TestTopology) ComponentsByUpdateOrder(curVer string) []Component {
return nil
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/tidbver/tidbver.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func TiCDCSupportRollingUpgrade(version string) bool {
return semver.Compare(version, "v6.3.0") >= 0 || strings.Contains(version, "nightly")
}

// TiCDCUpgradeBeforePDTiKVTiDB return if the given version of TiCDC should upgrade TiCDC before PD and TiKV
func TiCDCUpgradeBeforePDTiKVTiDB(version string) bool {
return semver.Compare(version, "v5.1.0") >= 0 || strings.Contains(version, "nightly")
}

// NgMonitorDeployByDefault return if given version of TiDB cluster should contain ng-monitoring
func NgMonitorDeployByDefault(version string) bool {
return semver.Compare(version, "v5.4.0") >= 0 || strings.Contains(version, "nightly")
Expand Down

0 comments on commit af2aa2a

Please sign in to comment.