From b9b2971f6470aed7796cf9a5827601019615b967 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Sat, 11 May 2024 15:37:07 +0800 Subject: [PATCH] use value Signed-off-by: Ryan Leung --- pkg/core/region.go | 8 ++++---- pkg/mcs/scheduling/server/grpc_service.go | 2 +- pkg/ratelimit/runner.go | 10 +++++----- server/grpc_service.go | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/core/region.go b/pkg/core/region.go index b5e84f9d9003..b1a5c58f2036 100644 --- a/pkg/core/region.go +++ b/pkg/core/region.go @@ -212,7 +212,7 @@ type RegionHeartbeatRequest interface { } // RegionFromHeartbeat constructs a Region from region heartbeat. -func RegionFromHeartbeat(heartbeat RegionHeartbeatRequest, opts ...RegionCreateOption) *RegionInfo { +func RegionFromHeartbeat(heartbeat RegionHeartbeatRequest, opts ...RegionCreateOption) RegionInfo { // Convert unit to MB. // If region isn't empty and less than 1MB, use 1MB instead. // The size of empty region will be correct by the previous RegionInfo. @@ -221,7 +221,7 @@ func RegionFromHeartbeat(heartbeat RegionHeartbeatRequest, opts ...RegionCreateO regionSize = EmptyRegionApproximateSize } - region := &RegionInfo{ + region := RegionInfo{ term: heartbeat.GetTerm(), meta: heartbeat.GetRegion(), leader: heartbeat.GetLeader(), @@ -246,7 +246,7 @@ func RegionFromHeartbeat(heartbeat RegionHeartbeatRequest, opts ...RegionCreateO } for _, opt := range opts { - opt(region) + opt(®ion) } if region.writtenKeys >= ImpossibleFlowSize || region.writtenBytes >= ImpossibleFlowSize { @@ -261,7 +261,7 @@ func RegionFromHeartbeat(heartbeat RegionHeartbeatRequest, opts ...RegionCreateO sort.Sort(peerStatsSlice(region.downPeers)) sort.Sort(peerSlice(region.pendingPeers)) - classifyVoterAndLearner(region) + classifyVoterAndLearner(®ion) return region } diff --git a/pkg/mcs/scheduling/server/grpc_service.go b/pkg/mcs/scheduling/server/grpc_service.go index 605ec73dad5e..5d8d8c23d142 100644 --- a/pkg/mcs/scheduling/server/grpc_service.go +++ b/pkg/mcs/scheduling/server/grpc_service.go @@ -159,7 +159,7 @@ func (s *Service) RegionHeartbeat(stream schedulingpb.Scheduling_RegionHeartbeat lastBind = time.Now() } region := core.RegionFromHeartbeat(request) - err = c.HandleRegionHeartbeat(region) + err = c.HandleRegionHeartbeat(®ion) if err != nil { // TODO: if we need to send the error back to API server. log.Error("failed handle region heartbeat", zap.Error(err)) diff --git a/pkg/ratelimit/runner.go b/pkg/ratelimit/runner.go index 5ba55faf7b33..e4ac4e90b9de 100644 --- a/pkg/ratelimit/runner.go +++ b/pkg/ratelimit/runner.go @@ -54,7 +54,7 @@ var TaskPool = &sync.Pool{ // Task is a task to run. type Task struct { Ctx context.Context - Opts *TaskOpts + Opts TaskOpts f func(context.Context) submittedAt time.Time } @@ -63,7 +63,7 @@ func NewTask(ctx context.Context, f func(context.Context), opts ...TaskOption) * task := TaskPool.Get().(*Task) task.Ctx = ctx task.f = f - task.Opts = &TaskOpts{} + task.Opts = TaskOpts{} task.submittedAt = time.Now() for _, opt := range opts { opt(task.Opts) @@ -74,7 +74,7 @@ func NewTask(ctx context.Context, f func(context.Context), opts ...TaskOption) * // ReleaseTask releases the task. func ReleaseTask(task *Task) { task.Ctx = nil - task.Opts = nil + task.Opts = TaskOpts{} task.f = nil task.submittedAt = time.Time{} TaskPool.Put(task) @@ -120,11 +120,11 @@ type TaskOpts struct { } // TaskOption configures TaskOp -type TaskOption func(opts *TaskOpts) +type TaskOption func(opts TaskOpts) // WithTaskName specify the task name. func WithTaskName(name string) TaskOption { - return func(opts *TaskOpts) { opts.TaskName = name } + return func(opts TaskOpts) { opts.TaskName = name } } // Start starts the runner. diff --git a/server/grpc_service.go b/server/grpc_service.go index 2b3ee232686b..2f5171bdfe6f 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -1293,7 +1293,7 @@ func (s *GrpcServer) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error continue } start := time.Now() - err = rc.HandleRegionHeartbeat(region) + err = rc.HandleRegionHeartbeat(®ion) if err != nil { regionHeartbeatCounter.WithLabelValues(storeAddress, storeLabel, "report", "err").Inc() msg := err.Error()