Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion components/cluster/command/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func initPassword(clusterName string) (string, error) {

var lastErr error
for _, spec := range metadata.Topology.TiDBServers {
spec := spec
endpoint := utils.JoinHostPort(spec.Host, spec.Port)
if tcpProxy != nil {
closeC := tcpProxy.Run([]string{endpoint})
Expand Down
2 changes: 0 additions & 2 deletions components/cluster/command/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func data(topo *spec.Specification, tcpProxy *proxy.TCPProxy) error {
errg, _ := errgroup.WithContext(context.Background())

for _, spec := range topo.TiDBServers {
spec := spec
endpoint := utils.JoinHostPort(spec.Host, spec.Port)
errg.Go(func() error {
if tcpProxy != nil {
Expand Down Expand Up @@ -112,7 +111,6 @@ func writable(topo *spec.Specification, tcpProxy *proxy.TCPProxy) error {
errg, _ := errgroup.WithContext(context.Background())

for _, spec := range topo.TiDBServers {
spec := spec
endpoint := utils.JoinHostPort(spec.Host, spec.Port)
errg.Go(func() error {
if tcpProxy != nil {
Expand Down
2 changes: 0 additions & 2 deletions components/dm/command/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,13 @@ func clearOutDatedEtcdInfo(clusterName string, metadata *spec.Metadata, opt oper
var wg sync.WaitGroup

for _, master := range mastersToDelete {
master := master
wg.Add(1)
go func() {
errCh <- dmMasterClient.OfflineMaster(master, nil)
wg.Done()
}()
}
for _, worker := range workersToDelete {
worker := worker
wg.Add(1)
go func() {
errCh <- dmMasterClient.OfflineWorker(worker, nil)
Expand Down
2 changes: 0 additions & 2 deletions components/dm/spec/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func (c *DMMasterComponent) SetVersion(version string) {
func (c *DMMasterComponent) Instances() []Instance {
ins := make([]Instance, 0)
for _, s := range c.Topology.Masters {
s := s
ins = append(ins, &MasterInstance{
Name: s.Name,
BaseInstance: spec.BaseInstance{
Expand Down Expand Up @@ -315,7 +314,6 @@ func (c *DMWorkerComponent) SetVersion(version string) {
func (c *DMWorkerComponent) Instances() []Instance {
ins := make([]Instance, 0)
for _, s := range c.Topology.Workers {
s := s
ins = append(ins, &WorkerInstance{
Name: s.Name,
BaseInstance: spec.BaseInstance{
Expand Down
2 changes: 1 addition & 1 deletion components/playground/instance/tiflash.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func isKeyPresentInMap(m map[string]any, key string) bool {
keys := strings.Split(key, ".")
currentMap := m

for i := 0; i < len(keys); i++ {
for i := range keys {
if _, ok := currentMap[keys[i]]; !ok {
return false
}
Expand Down
6 changes: 3 additions & 3 deletions components/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func tryConnect(addr string, timeoutSec int) error {
// checkDB check if the addr is connectable by getting a connection from sql.DB. timeout <=0 means no timeout
func checkDB(dbAddr string, timeout int) bool {
if timeout > 0 {
for i := 0; i < timeout; i++ {
for range timeout {
if tryConnect(dbAddr, timeout) == nil {
return true
}
Expand All @@ -449,7 +449,7 @@ func checkDB(dbAddr string, timeout int) bool {
// checkStoreStatus uses pd client to check whether a store is up. timeout <= 0 means no timeout
func checkStoreStatus(pdClient *api.PDClient, storeAddr string, timeout int) bool {
if timeout > 0 {
for i := 0; i < timeout; i++ {
for range timeout {
if up, err := pdClient.IsUp(storeAddr); err == nil && up {
return true
}
Expand All @@ -467,7 +467,7 @@ func checkStoreStatus(pdClient *api.PDClient, storeAddr string, timeout int) boo

func checkDMMasterStatus(dmMasterClient *api.DMMasterClient, dmMasterAddr string, timeout int) bool {
if timeout > 0 {
for i := 0; i < timeout; i++ {
for range timeout {
if _, isActive, _, err := dmMasterClient.GetMaster(dmMasterAddr); err == nil && isActive {
return true
}
Expand Down
46 changes: 23 additions & 23 deletions pkg/cluster/ansible/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func parseDirs(ctx context.Context, user string, ins spec.InstanceSpec, sshTimeo
case spec.ComponentTiDB:
// parse dirs
newIns := ins.(*spec.TiDBSpec)
for _, line := range strings.Split(stdout, "\n") {
if strings.HasPrefix(line, "DEPLOY_DIR=") {
newIns.DeployDir = strings.TrimPrefix(line, "DEPLOY_DIR=")
for line := range strings.SplitSeq(stdout, "\n") {
if after, ok := strings.CutPrefix(line, "DEPLOY_DIR="); ok {
newIns.DeployDir = after
continue
}
if strings.Contains(line, "--log-file=") {
Expand All @@ -78,7 +78,7 @@ func parseDirs(ctx context.Context, user string, ins spec.InstanceSpec, sshTimeo
case spec.ComponentTiKV:
// parse dirs
newIns := ins.(*spec.TiKVSpec)
for _, line := range strings.Split(stdout, "\n") {
for line := range strings.SplitSeq(stdout, "\n") {
if strings.HasPrefix(line, "cd \"") {
newIns.DeployDir = strings.Trim(strings.Split(line, " ")[1], "\"")
continue
Expand All @@ -100,9 +100,9 @@ func parseDirs(ctx context.Context, user string, ins spec.InstanceSpec, sshTimeo
case spec.ComponentPD:
// parse dirs
newIns := ins.(*spec.PDSpec)
for _, line := range strings.Split(stdout, "\n") {
if strings.HasPrefix(line, "DEPLOY_DIR=") {
newIns.DeployDir = strings.TrimPrefix(line, "DEPLOY_DIR=")
for line := range strings.SplitSeq(stdout, "\n") {
if after, ok := strings.CutPrefix(line, "DEPLOY_DIR="); ok {
newIns.DeployDir = after
continue
}
if strings.Contains(line, "--name") {
Expand All @@ -129,7 +129,7 @@ func parseDirs(ctx context.Context, user string, ins spec.InstanceSpec, sshTimeo
case spec.ComponentTiFlash:
// parse dirs
newIns := ins.(*spec.TiFlashSpec)
for _, line := range strings.Split(stdout, "\n") {
for line := range strings.SplitSeq(stdout, "\n") {
if strings.HasPrefix(line, "cd \"") {
newIns.DeployDir = strings.Trim(strings.Split(line, " ")[1], "\"")
continue
Expand All @@ -154,9 +154,9 @@ func parseDirs(ctx context.Context, user string, ins spec.InstanceSpec, sshTimeo
case spec.ComponentPump:
// parse dirs
newIns := ins.(*spec.PumpSpec)
for _, line := range strings.Split(stdout, "\n") {
if strings.HasPrefix(line, "DEPLOY_DIR=") {
newIns.DeployDir = strings.TrimPrefix(line, "DEPLOY_DIR=")
for line := range strings.SplitSeq(stdout, "\n") {
if after, ok := strings.CutPrefix(line, "DEPLOY_DIR="); ok {
newIns.DeployDir = after
continue
}
if strings.Contains(line, "--data-dir") {
Expand All @@ -177,9 +177,9 @@ func parseDirs(ctx context.Context, user string, ins spec.InstanceSpec, sshTimeo
case spec.ComponentDrainer:
// parse dirs
newIns := ins.(*spec.DrainerSpec)
for _, line := range strings.Split(stdout, "\n") {
if strings.HasPrefix(line, "DEPLOY_DIR=") {
newIns.DeployDir = strings.TrimPrefix(line, "DEPLOY_DIR=")
for line := range strings.SplitSeq(stdout, "\n") {
if after, ok := strings.CutPrefix(line, "DEPLOY_DIR="); ok {
newIns.DeployDir = after
continue
}
if strings.Contains(line, "--data-dir") {
Expand All @@ -206,9 +206,9 @@ func parseDirs(ctx context.Context, user string, ins spec.InstanceSpec, sshTimeo
case spec.ComponentPrometheus:
// parse dirs
newIns := ins.(*spec.PrometheusSpec)
for _, line := range strings.Split(stdout, "\n") {
if strings.HasPrefix(line, "DEPLOY_DIR=") {
newIns.DeployDir = strings.TrimPrefix(line, "DEPLOY_DIR=")
for line := range strings.SplitSeq(stdout, "\n") {
if after, ok := strings.CutPrefix(line, "DEPLOY_DIR="); ok {
newIns.DeployDir = after
continue
}
if strings.Contains(line, "exec > >(tee -i -a") {
Expand All @@ -229,9 +229,9 @@ func parseDirs(ctx context.Context, user string, ins spec.InstanceSpec, sshTimeo
case spec.ComponentAlertmanager:
// parse dirs
newIns := ins.(*spec.AlertmanagerSpec)
for _, line := range strings.Split(stdout, "\n") {
if strings.HasPrefix(line, "DEPLOY_DIR=") {
newIns.DeployDir = strings.TrimPrefix(line, "DEPLOY_DIR=")
for line := range strings.SplitSeq(stdout, "\n") {
if after, ok := strings.CutPrefix(line, "DEPLOY_DIR="); ok {
newIns.DeployDir = after
continue
}
if strings.Contains(line, "exec > >(tee -i -a") {
Expand All @@ -252,9 +252,9 @@ func parseDirs(ctx context.Context, user string, ins spec.InstanceSpec, sshTimeo
case spec.ComponentGrafana:
// parse dirs
newIns := ins.(*spec.GrafanaSpec)
for _, line := range strings.Split(stdout, "\n") {
if strings.HasPrefix(line, "DEPLOY_DIR=") {
newIns.DeployDir = strings.TrimPrefix(line, "DEPLOY_DIR=")
for line := range strings.SplitSeq(stdout, "\n") {
if after, ok := strings.CutPrefix(line, "DEPLOY_DIR="); ok {
newIns.DeployDir = after
continue
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type RegionInfo struct {
RegionEpoch *metapb.RegionEpoch `json:"epoch,omitempty"`
Peers []MetaPeer `json:"peers,omitempty"`

Leader MetaPeer `json:"leader,omitempty"`
Leader MetaPeer `json:"leader"`
DownPeers []PDPeerStats `json:"down_peers,omitempty"`
PendingPeers []MetaPeer `json:"pending_peers,omitempty"`
WrittenBytes uint64 `json:"written_bytes"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/audit/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestOutputAuditLog(t *testing.T) {
resetDir()

var g errgroup.Group
for i := 0; i < 20; i++ {
for range 20 {
g.Go(func() error { return OutputAuditLog(dir, "", []byte("audit log")) })
}
err := g.Wait()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func FindSSHAuthorizedKeysFile(ctx context.Context, exec ctxt.Executor) string {
sshAuthorizedKeys := defaultSSHAuthorizedKeys
cmd := "grep -Ev '^\\s*#|^\\s*$' /etc/ssh/sshd_config"
stdout, _, _ := exec.Execute(ctx, cmd, true) // error ignored as we have default value
for _, line := range strings.Split(string(stdout), "\n") {
for line := range strings.SplitSeq(string(stdout), "\n") {
if !strings.Contains(line, "AuthorizedKeysFile") {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/manager/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func buildScaleOutTask(
var dirs []string
globalOptions := metadata.GetTopology().BaseTopo().GlobalOptions
for _, dir := range []string{globalOptions.DeployDir, globalOptions.DataDir, globalOptions.LogDir} {
for _, dirname := range strings.Split(dir, ",") {
for dirname := range strings.SplitSeq(dir, ",") {
if dirname == "" {
continue
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cluster/manager/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ func (c *cleanupFiles) instanceCleanupFiles(topo spec.Topology) {
tlsPath := set.NewStringSet()

if c.cleanupData && len(ins.DataDir()) > 0 {
for _, dataDir := range strings.Split(ins.DataDir(), ",") {
for dataDir := range strings.SplitSeq(ins.DataDir(), ",") {
dataPaths.Insert(path.Join(dataDir, "*"))
}
}

if c.cleanupLog && len(ins.LogDir()) > 0 {
for _, logDir := range strings.Split(ins.LogDir(), ",") {
for logDir := range strings.SplitSeq(ins.LogDir(), ",") {
// need to judge the audit log of tidb server
if ins.ComponentName() == spec.ComponentTiDB {
logPaths.Insert(path.Join(logDir, "tidb?[!audit]*.log"))
Expand All @@ -236,7 +236,7 @@ func (c *cleanupFiles) instanceCleanupFiles(topo spec.Topology) {
}

if c.cleanupAuditLog && ins.ComponentName() == spec.ComponentTiDB {
for _, logDir := range strings.Split(ins.LogDir(), ",") {
for logDir := range strings.SplitSeq(ins.LogDir(), ",") {
logPaths.Insert(path.Join(logDir, "tidb-audit*.log"))
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/manager/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func renderInstanceSpec(t string, inst spec.Instance) ([]string, error) {
result := make([]string, 0)
switch inst.ComponentName() {
case spec.ComponentTiFlash:
for _, d := range strings.Split(inst.DataDir(), ",") {
for d := range strings.SplitSeq(inst.DataDir(), ",") {
tfs, ok := inst.(*spec.TiFlashInstance).InstanceSpec.(*spec.TiFlashSpec)
if !ok {
return result, perrs.Errorf("instance type mismatch for %v", inst)
Expand Down
5 changes: 0 additions & 5 deletions pkg/cluster/operation/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ func systemctlMonitor(ctx context.Context, hosts []string, noAgentHosts set.Stri

errg, _ := errgroup.WithContext(ctx)
for _, host := range hosts {
host := host
if noAgentHosts.Exist(host) {
logger.Debugf("Ignored %s component %s for %s", action, comp, host)
continue
Expand Down Expand Up @@ -460,8 +459,6 @@ func EnableComponent(ctx context.Context, instances []spec.Instance, noAgentHost
errg, _ := errgroup.WithContext(ctx)

for _, ins := range instances {
ins := ins

// skip certain instances
switch name {
case spec.ComponentNodeExporter,
Expand Down Expand Up @@ -514,7 +511,6 @@ func StartComponent(ctx context.Context, instances []spec.Instance, noAgentHosts
errg, _ := errgroup.WithContext(ctx)

for _, ins := range instances {
ins := ins
switch name {
case spec.ComponentNodeExporter,
spec.ComponentBlackboxExporter:
Expand Down Expand Up @@ -586,7 +582,6 @@ func StopComponent(ctx context.Context,
errg, _ := errgroup.WithContext(ctx)

for _, ins := range instances {
ins := ins
switch name {
case spec.ComponentNodeExporter,
spec.ComponentBlackboxExporter:
Expand Down
8 changes: 4 additions & 4 deletions pkg/cluster/operation/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func CheckSysLimits(opt *CheckOptions, user string, l []byte) []*CheckResult {
nofileHard int
)

for _, line := range strings.Split(string(l), "\n") {
for line := range strings.SplitSeq(string(l), "\n") {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "#") {
continue
Expand Down Expand Up @@ -447,7 +447,7 @@ func CheckSysLimits(opt *CheckOptions, user string, l []byte) []*CheckResult {
func CheckKernelParameters(opt *CheckOptions, p []byte) []*CheckResult {
var results []*CheckResult

for _, line := range strings.Split(string(p), "\n") {
for line := range strings.SplitSeq(string(p), "\n") {
line = strings.TrimSpace(line)
fields := strings.Fields(line)
if len(fields) < 3 {
Expand Down Expand Up @@ -615,7 +615,7 @@ func CheckListeningPort(opt *CheckOptions, host string, topo *spec.Specification
})

for p := range ports {
for _, line := range strings.Split(string(rawData), "\n") {
for line := range strings.SplitSeq(string(rawData), "\n") {
fields := strings.Fields(line)
if len(fields) < 5 || fields[0] != "LISTEN" {
continue
Expand Down Expand Up @@ -859,7 +859,7 @@ func CheckTHP(ctx context.Context, e ctxt.Executor, sudo bool) *CheckResult {
return result
}

for _, line := range strings.Split(strings.Trim(string(stdout), "\n"), "\n") {
for line := range strings.SplitSeq(strings.Trim(string(stdout), "\n"), "\n") {
if len(line) > 0 && !strings.Contains(line, "[never]") {
result.Err = fmt.Errorf("THP is enabled, please disable it for best performance")
return result
Expand Down
1 change: 0 additions & 1 deletion pkg/cluster/operation/scale_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ func scaleInCDC(
if len(instances) == len(cluster.CDCServers) {
g, _ := errgroup.WithContext(ctx)
for _, ins := range instances {
ins := ins
instCount[ins.GetManageHost()]++
destroyNode := instCount[ins.GetManageHost()] == 0
g.Go(func() error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/operation/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func GetServiceStatus(ctx context.Context, e ctxt.Executor, name string, scope s
// ignore error since stopped service returns exit code 3
stdout, _, _ := systemd.Execute(ctx, e)

lines := strings.Split(string(stdout), "\n")
for _, line := range lines {
lines := strings.SplitSeq(string(stdout), "\n")
for line := range lines {
words := strings.Split(strings.TrimSpace(line), " ")
if len(words) >= 2 {
switch words[0] {
Expand Down
1 change: 0 additions & 1 deletion pkg/cluster/spec/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ func (c *AlertManagerComponent) Instances() []Instance {
ins := make([]Instance, 0, len(alertmanagers))

for _, s := range alertmanagers {
s := s
ins = append(ins, &AlertManagerInstance{
BaseInstance: BaseInstance{
InstanceSpec: s,
Expand Down
1 change: 0 additions & 1 deletion pkg/cluster/spec/cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ func (c *CDCComponent) SetVersion(version string) {
func (c *CDCComponent) Instances() []Instance {
ins := make([]Instance, 0, len(c.Topology.CDCServers))
for _, s := range c.Topology.CDCServers {
s := s
instance := &CDCInstance{BaseInstance{
InstanceSpec: s,
Name: c.Name(),
Expand Down
1 change: 0 additions & 1 deletion pkg/cluster/spec/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func (c *DashboardComponent) SetVersion(version string) {
func (c *DashboardComponent) Instances() []Instance {
ins := make([]Instance, 0, len(c.Topology.Drainers))
for _, s := range c.Topology.DashboardServers {
s := s
ins = append(ins, &DashboardInstance{BaseInstance{
InstanceSpec: s,
Name: c.Name(),
Expand Down
1 change: 0 additions & 1 deletion pkg/cluster/spec/drainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ func (c *DrainerComponent) SetVersion(version string) {
func (c *DrainerComponent) Instances() []Instance {
ins := make([]Instance, 0, len(c.Topology.Drainers))
for _, s := range c.Topology.Drainers {
s := s
ins = append(ins, &DrainerInstance{BaseInstance{
InstanceSpec: s,
Name: c.Name(),
Expand Down
1 change: 0 additions & 1 deletion pkg/cluster/spec/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func (c *GrafanaComponent) Instances() []Instance {
ins := make([]Instance, 0, len(servers))

for _, s := range servers {
s := s
ins = append(ins, &GrafanaInstance{
BaseInstance: BaseInstance{
InstanceSpec: s,
Expand Down
Loading
Loading