@@ -25,6 +25,7 @@ import (
2525 "strings"
2626 "time"
2727
28+ perrs "github.com/pingcap/errors"
2829 "github.com/pingcap/tiup/pkg/cluster/api"
2930 "github.com/pingcap/tiup/pkg/cluster/ctxt"
3031 "github.com/pingcap/tiup/pkg/cluster/template/scripts"
@@ -526,7 +527,7 @@ func (i *TiFlashInstance) InitConfig(
526527 }
527528 tidbStatusStr := strings .Join (tidbStatusAddrs , "," )
528529
529- pdStr := strings .Join (i .getEndpoints (), "," )
530+ pdStr := strings .Join (i .getEndpoints (i . topo ), "," )
530531
531532 cfg := scripts .NewTiFlashScript (
532533 i .GetHost (),
@@ -652,25 +653,37 @@ type replicateConfig struct {
652653 EnablePlacementRules string `json:"enable-placement-rules"`
653654}
654655
655- func (i * TiFlashInstance ) getEndpoints () []string {
656+ func (i * TiFlashInstance ) getEndpoints (topo Topology ) []string {
656657 var endpoints []string
657- for _ , pd := range i . topo .(* Specification ).PDServers {
658+ for _ , pd := range topo .(* Specification ).PDServers {
658659 endpoints = append (endpoints , fmt .Sprintf ("%s:%d" , pd .Host , uint64 (pd .ClientPort )))
659660 }
660661 return endpoints
661662}
662663
663664// PrepareStart checks TiFlash requirements before starting
664- func (i * TiFlashInstance ) PrepareStart (tlsCfg * tls.Config ) error {
665- endPoints := i .getEndpoints ()
665+ func (i * TiFlashInstance ) PrepareStart (ctx context.Context , tlsCfg * tls.Config ) error {
666666 // set enable-placement-rules to true via PDClient
667- pdClient := api .NewPDClient (endPoints , 10 * time .Second , tlsCfg )
668667 enablePlacementRules , err := json .Marshal (replicateConfig {
669668 EnablePlacementRules : "true" ,
670669 })
670+ // this should not failed, else exit
671671 if err != nil {
672- return nil
672+ return perrs .Annotate (err , "failed to marshal replicate config" )
673+ }
674+
675+ var topo Topology
676+ if topoVal := ctx .Value (ctxt .CtxBaseTopo ); topoVal != nil { // in scale-out phase
677+ var ok bool
678+ topo , ok = topoVal .(Topology )
679+ if ! ok {
680+ return perrs .New ("base topology in context is invalid" )
681+ }
682+ } else { // in start phase
683+ topo = i .topo
673684 }
674685
686+ endpoints := i .getEndpoints (topo )
687+ pdClient := api .NewPDClient (endpoints , 10 * time .Second , tlsCfg )
675688 return pdClient .UpdateReplicateConfig (bytes .NewBuffer (enablePlacementRules ))
676689}
0 commit comments