Skip to content

Commit 05feed8

Browse files
committed
resolve conflicts
Signed-off-by: Ryan Leung <rleungx@gmail.com>
1 parent ed1fa0a commit 05feed8

File tree

7 files changed

+33
-25
lines changed

7 files changed

+33
-25
lines changed

pkg/mcs/scheduling/server/server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package server
1616

1717
import (
1818
"context"
19-
"fmt"
2019
"net/http"
2120
"os"
2221
"os/signal"
@@ -223,7 +222,7 @@ func (s *Server) updatePDMemberLoop() {
223222
}
224223
if s.cluster.SwitchPDLeader(pdpb.NewPDClient(cc)) {
225224
if status.Leader != curLeader {
226-
log.Info("switch PD leader", zap.String("current-leader", fmt.Sprintf("%x", curLeader)), zap.String("new-leader-id", fmt.Sprintf("%x", ep.ID)), zap.String("endpoint", ep.ClientURLs[0]))
225+
log.Info("switch PD leader", zap.String("current-leader", strconv.FormatUint(curLeader, 16)), zap.String("new-leader-id", strconv.FormatUint(ep.ID, 16)), zap.String("endpoint", ep.ClientURLs[0]))
227226
}
228227
curLeader = ep.ID
229228
break

pkg/schedule/checker/checker_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
sche "github.com/tikv/pd/pkg/schedule/core"
3636
"github.com/tikv/pd/pkg/schedule/labeler"
3737
"github.com/tikv/pd/pkg/schedule/operator"
38+
"github.com/tikv/pd/pkg/schedule/preparecheck"
3839
"github.com/tikv/pd/pkg/utils/keyutil"
3940
"github.com/tikv/pd/pkg/utils/logutil"
4041
)
@@ -92,12 +93,12 @@ type Controller struct {
9293
// patrolRegionScanLimit is the limit of regions to scan.
9394
// It is calculated by the number of regions.
9495
patrolRegionScanLimit int
95-
prepareChecker *sche.PrepareChecker
96+
prepareChecker *preparecheck.Checker
9697
metrics *checkerControllerMetrics
9798
}
9899

99100
// NewController create a new Controller.
100-
func NewController(ctx context.Context, cluster sche.CheckerCluster, opController *operator.Controller, prepareChecker *sche.PrepareChecker) *Controller {
101+
func NewController(ctx context.Context, cluster sche.CheckerCluster, opController *operator.Controller, prepareChecker *preparecheck.Checker) *Controller {
101102
pendingProcessedRegions := cache.NewIDTTL(ctx, time.Minute, 3*time.Minute)
102103
conf := cluster.GetCheckerConfig()
103104
ruleManager := cluster.GetRuleManager()

pkg/schedule/coordinator.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/tikv/pd/pkg/schedule/diagnostic"
3535
"github.com/tikv/pd/pkg/schedule/hbstream"
3636
"github.com/tikv/pd/pkg/schedule/operator"
37+
"github.com/tikv/pd/pkg/schedule/preparecheck"
3738
"github.com/tikv/pd/pkg/schedule/scatter"
3839
"github.com/tikv/pd/pkg/schedule/schedulers"
3940
"github.com/tikv/pd/pkg/schedule/splitter"
@@ -46,9 +47,7 @@ import (
4647

4748
const (
4849
runSchedulerCheckInterval = 3 * time.Second
49-
// collectTimeout is the timeout for collecting regions.
50-
collectTimeout = 5 * time.Minute
51-
maxLoadConfigRetries = 10
50+
maxLoadConfigRetries = 10
5251
// pushOperatorTickInterval is the interval try to push the operator.
5352
pushOperatorTickInterval = 500 * time.Millisecond
5453

@@ -69,7 +68,7 @@ type Coordinator struct {
6968
schedulersInitialized bool
7069

7170
cluster sche.ClusterInformer
72-
prepareChecker *prepareChecker
71+
prepareChecker *preparecheck.Checker
7372
checkers *checker.Controller
7473
regionScatterer *scatter.RegionScatterer
7574
regionSplitter *splitter.RegionSplitter
@@ -83,7 +82,7 @@ type Coordinator struct {
8382
// NewCoordinator creates a new Coordinator.
8483
func NewCoordinator(parentCtx context.Context, cluster sche.ClusterInformer, hbStreams *hbstream.HeartbeatStreams) *Coordinator {
8584
ctx, cancel := context.WithCancel(parentCtx)
86-
prepareChecker := newPrepareChecker(cluster.GetPrepareRegionCount)
85+
prepareChecker := preparecheck.NewChecker(cluster.GetPrepareRegionCount)
8786
opController := operator.NewController(ctx, cluster.GetBasicCluster(), cluster.GetSharedConfig(), hbStreams)
8887
schedulers := schedulers.NewController(ctx, cluster, cluster.GetStorage(), opController, prepareChecker)
8988
checkers := checker.NewController(ctx, cluster, opController, prepareChecker)
@@ -641,7 +640,7 @@ func (c *Coordinator) GetRuleChecker() *checker.RuleChecker {
641640
}
642641

643642
// GetPrepareChecker returns the prepare checker.
644-
func (c *Coordinator) GetPrepareChecker() *prepareChecker {
643+
func (c *Coordinator) GetPrepareChecker() *preparecheck.Checker {
645644
return c.prepareChecker
646645
}
647646

pkg/schedule/prepare_checker.go renamed to pkg/schedule/preparecheck/prepare_checker.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 TiKV Project Authors.
1+
// Copyright 2025 TiKV Project Authors.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package schedule
15+
package preparecheck
1616

1717
import (
1818
"time"
@@ -25,23 +25,27 @@ import (
2525
"github.com/tikv/pd/pkg/utils/syncutil"
2626
)
2727

28-
// prepareChecker is used to check if the coordinator has finished cluster information preparation.
29-
type prepareChecker struct {
28+
// collectTimeout is the timeout for collecting regions.
29+
const collectTimeout = 5 * time.Minute
30+
31+
// Checker is used to check if the coordinator has finished cluster information preparation.
32+
type Checker struct {
3033
syncutil.RWMutex
3134
start time.Time
3235
totalRegionCountFn func() (int, error)
3336
prepared bool
3437
}
3538

36-
func newPrepareChecker(totalRegionCountFn func() (int, error)) *prepareChecker {
37-
return &prepareChecker{
39+
// NewChecker creates a new Checker.
40+
func NewChecker(totalRegionCountFn func() (int, error)) *Checker {
41+
return &Checker{
3842
start: time.Now(),
3943
totalRegionCountFn: totalRegionCountFn,
4044
}
4145
}
4246

43-
// Before starting up the scheduler, we need to take the proportion of the regions on each store into consideration.
44-
func (checker *prepareChecker) Check(c *core.BasicCluster) bool {
47+
// Check is used to check if the coordinator has finished cluster information preparation.
48+
func (checker *Checker) Check(c *core.BasicCluster) bool {
4549
checker.Lock()
4650
defer checker.Unlock()
4751
if checker.prepared {
@@ -79,7 +83,7 @@ func (checker *prepareChecker) Check(c *core.BasicCluster) bool {
7983
}
8084

8185
// IsPrepared returns whether the coordinator is prepared.
82-
func (checker *prepareChecker) IsPrepared() bool {
86+
func (checker *Checker) IsPrepared() bool {
8387
if checker == nil {
8488
return false
8589
}
@@ -89,14 +93,14 @@ func (checker *prepareChecker) IsPrepared() bool {
8993
}
9094

9195
// SetPrepared is for test purpose
92-
func (checker *prepareChecker) SetPrepared() {
96+
func (checker *Checker) SetPrepared() {
9397
checker.Lock()
9498
defer checker.Unlock()
9599
checker.prepared = true
96100
}
97101

98102
// ResetPrepared is for test purpose
99-
func (checker *prepareChecker) ResetPrepared() {
103+
func (checker *Checker) ResetPrepared() {
100104
checker.Lock()
101105
defer checker.Unlock()
102106
checker.prepared = false

pkg/schedule/schedulers/scheduler_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/tikv/pd/pkg/schedule/labeler"
3232
"github.com/tikv/pd/pkg/schedule/operator"
3333
"github.com/tikv/pd/pkg/schedule/plan"
34+
"github.com/tikv/pd/pkg/schedule/preparecheck"
3435
"github.com/tikv/pd/pkg/schedule/types"
3536
"github.com/tikv/pd/pkg/storage/endpoint"
3637
"github.com/tikv/pd/pkg/utils/logutil"
@@ -57,11 +58,11 @@ type Controller struct {
5758
// which will only be initialized and used in the microservice env now.
5859
schedulerHandlers map[string]http.Handler
5960
opController *operator.Controller
60-
prepareChecker *sche.PrepareChecker
61+
prepareChecker *preparecheck.Checker
6162
}
6263

6364
// NewController creates a scheduler controller.
64-
func NewController(ctx context.Context, cluster sche.SchedulerCluster, storage endpoint.ConfigStorage, opController *operator.Controller, prepareChecker *sche.PrepareChecker) *Controller {
65+
func NewController(ctx context.Context, cluster sche.SchedulerCluster, storage endpoint.ConfigStorage, opController *operator.Controller, prepareChecker *preparecheck.Checker) *Controller {
6566
return &Controller{
6667
ctx: ctx,
6768
cluster: cluster,

tests/server/api/api_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,8 @@ func TestDeleteAllRegionCacheScheduling(t *testing.T) {
13351335
testutil.Eventually(re, func() bool {
13361336
return rc.GetCoordinator() != nil
13371337
})
1338-
rc.HandleRegionHeartbeat(regionInfo)
1338+
err = rc.HandleRegionHeartbeat(regionInfo)
1339+
re.NoError(err)
13391340
testutil.Eventually(re, func() bool {
13401341
return rc.GetCoordinator().GetPrepareChecker().IsPrepared()
13411342
})
@@ -1353,7 +1354,8 @@ func TestDeleteAllRegionCacheScheduling(t *testing.T) {
13531354
re.Equal(0, int(rc.GetOperatorController().OperatorCount(operator.OpSplit)))
13541355

13551356
// Simulate continuous heartbeat and verify scheduling recovery
1356-
rc.HandleRegionHeartbeat(regionInfo)
1357+
err = rc.HandleRegionHeartbeat(regionInfo)
1358+
re.NoError(err)
13571359

13581360
testutil.Eventually(re, func() bool {
13591361
count := rc.GetOperatorController().OperatorCount(operator.OpSplit)

tests/server/cluster/cluster_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,8 @@ func TestPatrolRegionConfigChange(t *testing.T) {
20642064
endKey := []byte(strconv.Itoa(i * 2))
20652065
tests.MustPutRegion(re, tc, uint64(i), uint64(i%3+1), startKey, endKey)
20662066
}
2067+
fname := testutil.InitTempFileLogger("debug")
2068+
defer os.RemoveAll(fname)
20672069
checkLog(re, fname, "coordinator starts patrol regions")
20682070

20692071
// test change patrol region interval

0 commit comments

Comments
 (0)