Skip to content

Commit

Permalink
*: fix scheduler init (#5938)
Browse files Browse the repository at this point in the history
close #5936

Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 authored Feb 8, 2023
1 parent 4b38021 commit 950883e
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func main() {
}

func createServerWrapper(args []string) (context.Context, context.CancelFunc, basicsvr.Server) {
schedulers.Register()
cfg := config.NewConfig()
err := cfg.Parse(args)

Expand Down Expand Up @@ -135,7 +136,6 @@ func createServerWrapper(args []string) (context.Context, context.CancelFunc, ba
if err != nil {
log.Fatal("create server failed", errs.ZapError(err))
}
schedulers.Register()

return ctx, cancel, svr
}
Expand Down
1 change: 0 additions & 1 deletion server/cluster/cluster_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/mock/mockid"
_ "github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/server/storage"
)

Expand Down
9 changes: 9 additions & 0 deletions server/schedulers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,24 @@ package schedulers
import (
"strconv"
"strings"
"sync"

"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/storage/endpoint"
"github.com/tikv/pd/server/schedule"
)

var registerOnce sync.Once

// Register registers schedulers.
func Register() {
registerOnce.Do(func() {
schedulersRegister()
})
}

func schedulersRegister() {
// balance leader
schedule.RegisterSliceDecoderBuilder(BalanceLeaderType, func(args []string) schedule.ConfigDecoder {
return func(v interface{}) error {
Expand Down
3 changes: 2 additions & 1 deletion tests/dashboard/race_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import (
"github.com/tikv/pd/pkg/dashboard"
"github.com/tikv/pd/tests"

_ "github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/server/schedulers"
)

func TestCancelDuringStarting(t *testing.T) {
schedulers.Register()
prepareTestConfig()
defer resetTestConfig()
ctx, cancel := context.WithCancel(context.Background())
Expand Down
2 changes: 2 additions & 0 deletions tests/dashboard/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/tikv/pd/pkg/dashboard"
"github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/server/config"
"github.com/tikv/pd/server/schedulers"
"github.com/tikv/pd/tests"
"github.com/tikv/pd/tests/pdctl"
pdctlCmd "github.com/tikv/pd/tools/pd-ctl/pdctl"
Expand All @@ -49,6 +50,7 @@ func TestDashboardTestSuite(t *testing.T) {
}

func (suite *dashboardTestSuite) SetupSuite() {
schedulers.Register()
dashboard.SetCheckInterval(10 * time.Millisecond)
suite.ctx, suite.cancel = context.WithCancel(context.Background())
suite.httpClient = &http.Client{
Expand Down
5 changes: 5 additions & 0 deletions tests/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ import (
"github.com/tikv/pd/pkg/utils/tempurl"
"github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/server/config"
"github.com/tikv/pd/server/schedulers"
"github.com/tikv/pd/tests"
"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
schedulers.Register()
goleak.VerifyTestMain(m, testutil.LeakOptions...)
}

func TestUpdateAdvertiseUrls(t *testing.T) {
schedulers.Register()
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -72,6 +75,7 @@ func TestUpdateAdvertiseUrls(t *testing.T) {
}

func TestClusterID(t *testing.T) {
schedulers.Register()
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -108,6 +112,7 @@ func TestClusterID(t *testing.T) {
}

func TestLeader(t *testing.T) {
schedulers.Register()
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
2 changes: 2 additions & 0 deletions tools/pd-simulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/tikv/pd/server"
"github.com/tikv/pd/server/api"
"github.com/tikv/pd/server/config"
"github.com/tikv/pd/server/schedulers"
"github.com/tikv/pd/server/statistics"
"github.com/tikv/pd/tools/pd-analysis/analysis"
"github.com/tikv/pd/tools/pd-simulator/simulator"
Expand All @@ -55,6 +56,7 @@ var (
)

func main() {
schedulers.Register()
// wait PD start. Otherwise it will happen error when getting cluster ID.
time.Sleep(3 * time.Second)
// ignore some undefined flag
Expand Down

0 comments on commit 950883e

Please sign in to comment.