From 9b0e00c6312b324f30deb647f2e90425e13b3db7 Mon Sep 17 00:00:00 2001 From: SIGSEGV Date: Mon, 25 Jan 2021 19:07:43 +0800 Subject: [PATCH] Fix the issue that tiup-cluster disable monitoring service regardless if there are other service still running on that node. (#1088) Fix https://github.com/pingcap/tiup/issues/697 Co-authored-by: Ti Chi Robot <71242396+ti-chi-bot@users.noreply.github.com> --- pkg/cluster/operation/action.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/cluster/operation/action.go b/pkg/cluster/operation/action.go index 1b782a70cc..a2ac2a4e71 100644 --- a/pkg/cluster/operation/action.go +++ b/pkg/cluster/operation/action.go @@ -35,13 +35,17 @@ func Enable( options Options, isEnable bool, ) error { - uniqueHosts := set.NewStringSet() roleFilter := set.NewStringSet(options.Roles...) nodeFilter := set.NewStringSet(options.Nodes...) components := cluster.ComponentsByStartOrder() components = FilterComponent(components, roleFilter) monitoredOptions := cluster.GetMonitoredOptions() + instCount := map[string]int{} + cluster.IterInstance(func(inst spec.Instance) { + instCount[inst.GetHost()]++ + }) + for _, comp := range components { insts := FilterInstance(comp.Instances(), nodeFilter) err := EnableComponent(getter, insts, options, isEnable) @@ -52,8 +56,8 @@ func Enable( continue } for _, inst := range insts { - if !uniqueHosts.Exist(inst.GetHost()) { - uniqueHosts.Insert(inst.GetHost()) + instCount[inst.GetHost()]-- + if instCount[inst.GetHost()] == 0 { if err := EnableMonitored(getter, inst, monitoredOptions, options.OptTimeout, isEnable); err != nil { return err }