From e7c9d1514bd385d045b14aae4b51c1aec51be3aa Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Fri, 28 Jun 2024 17:53:55 +0800 Subject: [PATCH] *: set errcheck exclude func (#8346) close tikv/pd#1919 Signed-off-by: okJiang <819421878@qq.com> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- .golangci.yml | 11 +++++--- cmd/pd-server/main.go | 6 ++--- pkg/autoscaling/handler.go | 8 +++--- pkg/core/region.go | 4 +-- pkg/mcs/metastorage/server/grpc_service.go | 2 +- .../resourcemanager/server/grpc_service.go | 2 +- pkg/mcs/resourcemanager/server/server.go | 5 +--- pkg/mcs/resourcemanager/server/testutil.go | 4 +-- pkg/mcs/scheduling/server/cluster.go | 10 +++---- pkg/mcs/scheduling/server/grpc_service.go | 2 +- pkg/mcs/scheduling/server/server.go | 4 +-- pkg/mcs/scheduling/server/testutil.go | 5 +--- pkg/mcs/tso/server/grpc_service.go | 2 +- pkg/mcs/tso/server/server.go | 4 +-- pkg/mcs/utils/util.go | 2 +- pkg/schedule/schedulers/balance_leader.go | 12 ++++++--- pkg/schedule/schedulers/balance_witness.go | 4 +-- pkg/schedule/schedulers/evict_leader.go | 22 ++++++++-------- pkg/schedule/schedulers/evict_slow_store.go | 8 +++--- pkg/schedule/schedulers/evict_slow_trend.go | 8 +++--- pkg/schedule/schedulers/grant_hot_region.go | 14 +++++----- pkg/schedule/schedulers/grant_leader.go | 22 ++++++++-------- pkg/schedule/schedulers/hot_region_config.go | 18 ++++++------- pkg/schedule/schedulers/scatter_range.go | 10 +++---- pkg/schedule/schedulers/shuffle_hot_region.go | 8 +++--- .../schedulers/shuffle_region_config.go | 8 +++--- pkg/schedule/schedulers/split_bucket.go | 20 ++++++++------ pkg/tso/admin.go | 14 +++++----- pkg/utils/apiutil/apiutil.go | 6 ++--- plugin/scheduler_example/evict_leader.go | 18 ++++++------- server/api/admin.go | 26 +++++++++---------- server/api/router.go | 2 +- server/api/store.go | 5 +++- server/cluster/cluster.go | 12 ++++----- 34 files changed, 155 insertions(+), 153 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c70c0996cb3..68cc82bd373 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -198,6 +198,14 @@ linters-settings: severity: warning disabled: false exclude: [""] + errcheck: + exclude-functions: + - (*github.com/unrolled/render.Render).JSON + - (*github.com/unrolled/render.Render).Data + - (*github.com/unrolled/render.Render).Text + - (net/http.ResponseWriter).Write + - github.com/pingcap/log.Sync + - (github.com/tikv/pd/pkg/ratelimit.Runner).RunTask issues: exclude-rules: - path: (_test\.go|pkg/mock/.*\.go|tests/.*\.go) @@ -207,6 +215,3 @@ issues: - path: (pd-analysis|pd-api-bench|pd-backup|pd-ctl|pd-heartbeat-bench|pd-recover|pd-simulator|pd-tso-bench|pd-ut|regions-dump|stores-dump) linters: - errcheck - - path: (pkg/schedule/schedulers/split_bucket.go|server/api/.*\.go|pkg/schedule/schedulers/balance_leader.go) - linters: - - errcheck diff --git a/cmd/pd-server/main.go b/cmd/pd-server/main.go index 2de5b702253..553b93ed0ef 100644 --- a/cmd/pd-server/main.go +++ b/cmd/pd-server/main.go @@ -235,9 +235,7 @@ func start(cmd *cobra.Command, args []string, services ...string) { log.Fatal("initialize logger error", errs.ZapError(err)) } // Flushing any buffered log entries - defer func() { - _ = log.Sync() - }() + defer log.Sync() memory.InitMemoryHook() if len(services) != 0 { versioninfo.Log(server.APIServiceMode) @@ -301,6 +299,6 @@ func start(cmd *cobra.Command, args []string, services ...string) { } func exit(code int) { - _ = log.Sync() + log.Sync() os.Exit(code) } diff --git a/pkg/autoscaling/handler.go b/pkg/autoscaling/handler.go index 7bffa8ec156..ea248fdcc55 100644 --- a/pkg/autoscaling/handler.go +++ b/pkg/autoscaling/handler.go @@ -41,22 +41,22 @@ func NewHTTPHandler(svr *server.Server, rd *render.Render) *HTTPHandler { func (h *HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { rc := h.svr.GetRaftCluster() if rc == nil { - _ = h.rd.JSON(w, http.StatusInternalServerError, errs.ErrNotBootstrapped.FastGenByArgs().Error()) + h.rd.JSON(w, http.StatusInternalServerError, errs.ErrNotBootstrapped.FastGenByArgs().Error()) return } data, err := io.ReadAll(r.Body) r.Body.Close() if err != nil { - _ = h.rd.JSON(w, http.StatusInternalServerError, err.Error()) + h.rd.JSON(w, http.StatusInternalServerError, err.Error()) return } strategy := Strategy{} if err := json.Unmarshal(data, &strategy); err != nil { - _ = h.rd.JSON(w, http.StatusBadRequest, err.Error()) + h.rd.JSON(w, http.StatusBadRequest, err.Error()) return } plan := calculate(rc, h.svr.GetPDServerConfig(), &strategy) - _ = h.rd.JSON(w, http.StatusOK, plan) + h.rd.JSON(w, http.StatusOK, plan) } diff --git a/pkg/core/region.go b/pkg/core/region.go index 77eb016ccdf..c83f4387eab 100644 --- a/pkg/core/region.go +++ b/pkg/core/region.go @@ -747,7 +747,7 @@ func GenerateRegionGuideFunc(enableLog bool) RegionGuideFunc { regionID := region.GetID() if logRunner != nil { debug = func(msg string, fields ...zap.Field) { - _ = logRunner.RunTask( + logRunner.RunTask( regionID, "DebugLog", func() { @@ -756,7 +756,7 @@ func GenerateRegionGuideFunc(enableLog bool) RegionGuideFunc { ) } info = func(msg string, fields ...zap.Field) { - _ = logRunner.RunTask( + logRunner.RunTask( regionID, "InfoLog", func() { diff --git a/pkg/mcs/metastorage/server/grpc_service.go b/pkg/mcs/metastorage/server/grpc_service.go index 7969173f11f..c3ecfa572a1 100644 --- a/pkg/mcs/metastorage/server/grpc_service.go +++ b/pkg/mcs/metastorage/server/grpc_service.go @@ -47,7 +47,7 @@ type dummyRestService struct{} func (dummyRestService) ServeHTTP(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNotImplemented) - _, _ = w.Write([]byte("not implemented")) + w.Write([]byte("not implemented")) } // Service is the gRPC service for meta storage. diff --git a/pkg/mcs/resourcemanager/server/grpc_service.go b/pkg/mcs/resourcemanager/server/grpc_service.go index d503893061d..93243eb05be 100644 --- a/pkg/mcs/resourcemanager/server/grpc_service.go +++ b/pkg/mcs/resourcemanager/server/grpc_service.go @@ -49,7 +49,7 @@ type dummyRestService struct{} func (dummyRestService) ServeHTTP(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNotImplemented) - _, _ = w.Write([]byte("not implemented")) + w.Write([]byte("not implemented")) } // Service is the gRPC service for resource manager. diff --git a/pkg/mcs/resourcemanager/server/server.go b/pkg/mcs/resourcemanager/server/server.go index 06e1b61d757..708a11344d4 100644 --- a/pkg/mcs/resourcemanager/server/server.go +++ b/pkg/mcs/resourcemanager/server/server.go @@ -397,10 +397,7 @@ func CreateServerWrapper(cmd *cobra.Command, args []string) { log.Fatal("initialize logger error", errs.ZapError(err)) } // Flushing any buffered log entries - defer func() { - _ = log.Sync() - }() - + log.Sync() versioninfo.Log(serviceName) log.Info("resource manager config", zap.Reflect("config", cfg)) diff --git a/pkg/mcs/resourcemanager/server/testutil.go b/pkg/mcs/resourcemanager/server/testutil.go index 9b96def27ff..0277e5e8a8f 100644 --- a/pkg/mcs/resourcemanager/server/testutil.go +++ b/pkg/mcs/resourcemanager/server/testutil.go @@ -32,9 +32,7 @@ func NewTestServer(ctx context.Context, re *require.Assertions, cfg *Config) (*S re.NoError(err) log.ReplaceGlobals(cfg.Logger, cfg.LogProps) // Flushing any buffered log entries - defer func() { - _ = log.Sync() - }() + log.Sync() s := CreateServer(ctx, cfg) if err = s.Run(); err != nil { diff --git a/pkg/mcs/scheduling/server/cluster.go b/pkg/mcs/scheduling/server/cluster.go index 4062ed38fd6..b18db7c0798 100644 --- a/pkg/mcs/scheduling/server/cluster.go +++ b/pkg/mcs/scheduling/server/cluster.go @@ -624,7 +624,7 @@ func (c *Cluster) processRegionHeartbeat(ctx *core.MetaProcessContext, region *c // Due to some config changes need to update the region stats as well, // so we do some extra checks here. if hasRegionStats && c.regionStats.RegionStatsNeedUpdate(region) { - _ = ctx.TaskRunner.RunTask( + ctx.TaskRunner.RunTask( regionID, ratelimit.ObserveRegionStatsAsync, func() { @@ -636,7 +636,7 @@ func (c *Cluster) processRegionHeartbeat(ctx *core.MetaProcessContext, region *c } // region is not updated to the subtree. if origin.GetRef() < 2 { - _ = ctx.TaskRunner.RunTask( + ctx.TaskRunner.RunTask( regionID, ratelimit.UpdateSubTree, func() { @@ -660,7 +660,7 @@ func (c *Cluster) processRegionHeartbeat(ctx *core.MetaProcessContext, region *c tracer.OnSaveCacheFinished() return err } - _ = ctx.TaskRunner.RunTask( + ctx.TaskRunner.RunTask( regionID, ratelimit.UpdateSubTree, func() { @@ -669,7 +669,7 @@ func (c *Cluster) processRegionHeartbeat(ctx *core.MetaProcessContext, region *c ratelimit.WithRetained(retained), ) tracer.OnUpdateSubTreeFinished() - _ = ctx.TaskRunner.RunTask( + ctx.TaskRunner.RunTask( regionID, ratelimit.HandleOverlaps, func() { @@ -679,7 +679,7 @@ func (c *Cluster) processRegionHeartbeat(ctx *core.MetaProcessContext, region *c } tracer.OnSaveCacheFinished() // handle region stats - _ = ctx.TaskRunner.RunTask( + ctx.TaskRunner.RunTask( regionID, ratelimit.CollectRegionStatsAsync, func() { diff --git a/pkg/mcs/scheduling/server/grpc_service.go b/pkg/mcs/scheduling/server/grpc_service.go index 93af46356b7..77d9a722d23 100644 --- a/pkg/mcs/scheduling/server/grpc_service.go +++ b/pkg/mcs/scheduling/server/grpc_service.go @@ -53,7 +53,7 @@ type dummyRestService struct{} func (dummyRestService) ServeHTTP(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNotImplemented) - _, _ = w.Write([]byte("not implemented")) + w.Write([]byte("not implemented")) } // ConfigProvider is used to get scheduling config from the given diff --git a/pkg/mcs/scheduling/server/server.go b/pkg/mcs/scheduling/server/server.go index fa129cb54ec..8eb9e49d964 100644 --- a/pkg/mcs/scheduling/server/server.go +++ b/pkg/mcs/scheduling/server/server.go @@ -596,9 +596,7 @@ func CreateServerWrapper(cmd *cobra.Command, args []string) { log.Fatal("initialize logger error", errs.ZapError(err)) } // Flushing any buffered log entries - defer func() { - _ = log.Sync() - }() + log.Sync() versioninfo.Log(serviceName) log.Info("scheduling service config", zap.Reflect("config", cfg)) diff --git a/pkg/mcs/scheduling/server/testutil.go b/pkg/mcs/scheduling/server/testutil.go index a7d6ae0e0a0..aba88945434 100644 --- a/pkg/mcs/scheduling/server/testutil.go +++ b/pkg/mcs/scheduling/server/testutil.go @@ -33,10 +33,7 @@ func NewTestServer(ctx context.Context, re *require.Assertions, cfg *config.Conf re.NoError(err) log.ReplaceGlobals(cfg.Logger, cfg.LogProps) // Flushing any buffered log entries - defer func() { - _ = log.Sync() - }() - + log.Sync() s := CreateServer(ctx, cfg) if err = s.Run(); err != nil { return nil, nil, err diff --git a/pkg/mcs/tso/server/grpc_service.go b/pkg/mcs/tso/server/grpc_service.go index a8abb0bc8fd..7dd9c6b5605 100644 --- a/pkg/mcs/tso/server/grpc_service.go +++ b/pkg/mcs/tso/server/grpc_service.go @@ -49,7 +49,7 @@ type dummyRestService struct{} func (dummyRestService) ServeHTTP(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNotImplemented) - _, _ = w.Write([]byte("not implemented")) + w.Write([]byte("not implemented")) } // ConfigProvider is used to get tso config from the given diff --git a/pkg/mcs/tso/server/server.go b/pkg/mcs/tso/server/server.go index 558fde8f474..60ce2917ed5 100644 --- a/pkg/mcs/tso/server/server.go +++ b/pkg/mcs/tso/server/server.go @@ -468,9 +468,7 @@ func CreateServerWrapper(cmd *cobra.Command, args []string) { log.Fatal("initialize logger error", errs.ZapError(err)) } // Flushing any buffered log entries - defer func() { - _ = log.Sync() - }() + log.Sync() versioninfo.Log(serviceName) log.Info("TSO service config", zap.Reflect("config", cfg)) diff --git a/pkg/mcs/utils/util.go b/pkg/mcs/utils/util.go index b70b050617e..fb78f0b4be3 100644 --- a/pkg/mcs/utils/util.go +++ b/pkg/mcs/utils/util.go @@ -324,6 +324,6 @@ func StopGRPCServer(s server) { // Exit exits the program with the given code. func Exit(code int) { - _ = log.Sync() + log.Sync() os.Exit(code) } diff --git a/pkg/schedule/schedulers/balance_leader.go b/pkg/schedule/schedulers/balance_leader.go index 24471e1980d..c4b9cd6ab5e 100644 --- a/pkg/schedule/schedulers/balance_leader.go +++ b/pkg/schedule/schedulers/balance_leader.go @@ -86,10 +86,14 @@ func (conf *balanceLeaderSchedulerConfig) Update(data []byte) (int, any) { newConfig, _ := json.Marshal(conf) if !bytes.Equal(oldConfig, newConfig) { if !conf.validateLocked() { - json.Unmarshal(oldConfig, conf) + if err := json.Unmarshal(oldConfig, conf); err != nil { + return http.StatusInternalServerError, err.Error() + } return http.StatusBadRequest, "invalid batch size which should be an integer between 1 and 10" } - conf.persistLocked() + if err := conf.persistLocked(); err != nil { + log.Warn("failed to save balance-leader-scheduler config", errs.ZapError(err)) + } log.Info("balance-leader-scheduler config is updated", zap.ByteString("old", oldConfig), zap.ByteString("new", newConfig)) return http.StatusOK, "Config is updated." } @@ -161,12 +165,12 @@ func (handler *balanceLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http data, _ := io.ReadAll(r.Body) r.Body.Close() httpCode, v := handler.config.Update(data) - _ = handler.rd.JSON(w, httpCode, v) + handler.rd.JSON(w, httpCode, v) } func (handler *balanceLeaderHandler) ListConfig(w http.ResponseWriter, _ *http.Request) { conf := handler.config.Clone() - _ = handler.rd.JSON(w, http.StatusOK, conf) + handler.rd.JSON(w, http.StatusOK, conf) } type balanceLeaderScheduler struct { diff --git a/pkg/schedule/schedulers/balance_witness.go b/pkg/schedule/schedulers/balance_witness.go index 0cf69d67e28..0225d948815 100644 --- a/pkg/schedule/schedulers/balance_witness.go +++ b/pkg/schedule/schedulers/balance_witness.go @@ -151,12 +151,12 @@ func (handler *balanceWitnessHandler) UpdateConfig(w http.ResponseWriter, r *htt data, _ := io.ReadAll(r.Body) r.Body.Close() httpCode, v := handler.config.Update(data) - _ = handler.rd.JSON(w, httpCode, v) + handler.rd.JSON(w, httpCode, v) } func (handler *balanceWitnessHandler) ListConfig(w http.ResponseWriter, _ *http.Request) { conf := handler.config.Clone() - _ = handler.rd.JSON(w, http.StatusOK, conf) + handler.rd.JSON(w, http.StatusOK, conf) } type balanceWitnessScheduler struct { diff --git a/pkg/schedule/schedulers/evict_leader.go b/pkg/schedule/schedulers/evict_leader.go index 63ca6013584..8f56643f384 100644 --- a/pkg/schedule/schedulers/evict_leader.go +++ b/pkg/schedule/schedulers/evict_leader.go @@ -373,7 +373,7 @@ func (handler *evictLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R if _, exists = handler.config.StoreIDWithRanges[id]; !exists { if err := handler.config.cluster.PauseLeaderTransfer(id); err != nil { handler.config.RUnlock() - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) return } } @@ -390,28 +390,28 @@ func (handler *evictLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R err := handler.config.BuildWithArgs(args) if err != nil { - _ = handler.rd.JSON(w, http.StatusBadRequest, err.Error()) + handler.rd.JSON(w, http.StatusBadRequest, err.Error()) return } err = handler.config.Persist() if err != nil { handler.config.removeStore(id) - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) return } - _ = handler.rd.JSON(w, http.StatusOK, "The scheduler has been applied to the store.") + handler.rd.JSON(w, http.StatusOK, "The scheduler has been applied to the store.") } func (handler *evictLeaderHandler) ListConfig(w http.ResponseWriter, _ *http.Request) { conf := handler.config.Clone() - _ = handler.rd.JSON(w, http.StatusOK, conf) + handler.rd.JSON(w, http.StatusOK, conf) } func (handler *evictLeaderHandler) DeleteConfig(w http.ResponseWriter, r *http.Request) { idStr := mux.Vars(r)["store_id"] id, err := strconv.ParseUint(idStr, 10, 64) if err != nil { - _ = handler.rd.JSON(w, http.StatusBadRequest, err.Error()) + handler.rd.JSON(w, http.StatusBadRequest, err.Error()) return } @@ -422,26 +422,26 @@ func (handler *evictLeaderHandler) DeleteConfig(w http.ResponseWriter, r *http.R err = handler.config.Persist() if err != nil { handler.config.resetStore(id, keyRanges) - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) return } if last { if err := handler.config.removeSchedulerCb(EvictLeaderName); err != nil { if errors.ErrorEqual(err, errs.ErrSchedulerNotFound.FastGenByArgs()) { - _ = handler.rd.JSON(w, http.StatusNotFound, err.Error()) + handler.rd.JSON(w, http.StatusNotFound, err.Error()) } else { handler.config.resetStore(id, keyRanges) - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) } return } resp = lastStoreDeleteInfo } - _ = handler.rd.JSON(w, http.StatusOK, resp) + handler.rd.JSON(w, http.StatusOK, resp) return } - _ = handler.rd.JSON(w, http.StatusNotFound, errs.ErrScheduleConfigNotExist.FastGenByArgs().Error()) + handler.rd.JSON(w, http.StatusNotFound, errs.ErrScheduleConfigNotExist.FastGenByArgs().Error()) } func newEvictLeaderHandler(config *evictLeaderSchedulerConfig) http.Handler { diff --git a/pkg/schedule/schedulers/evict_slow_store.go b/pkg/schedule/schedulers/evict_slow_store.go index 8989cd5de3f..9b13e292c87 100644 --- a/pkg/schedule/schedulers/evict_slow_store.go +++ b/pkg/schedule/schedulers/evict_slow_store.go @@ -160,7 +160,7 @@ func (handler *evictSlowStoreHandler) UpdateConfig(w http.ResponseWriter, r *htt } recoveryDurationGapFloat, ok := input["recovery-duration"].(float64) if !ok { - _ = handler.rd.JSON(w, http.StatusInternalServerError, errors.New("invalid argument for 'recovery-duration'").Error()) + handler.rd.JSON(w, http.StatusInternalServerError, errors.New("invalid argument for 'recovery-duration'").Error()) return } handler.config.Lock() @@ -169,17 +169,17 @@ func (handler *evictSlowStoreHandler) UpdateConfig(w http.ResponseWriter, r *htt recoveryDurationGap := uint64(recoveryDurationGapFloat) handler.config.RecoveryDurationGap = recoveryDurationGap if err := handler.config.persistLocked(); err != nil { - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) handler.config.RecoveryDurationGap = prevRecoveryDurationGap return } log.Info("evict-slow-store-scheduler update 'recovery-duration' - unit: s", zap.Uint64("prev", prevRecoveryDurationGap), zap.Uint64("cur", recoveryDurationGap)) - _ = handler.rd.JSON(w, http.StatusOK, "Config updated.") + handler.rd.JSON(w, http.StatusOK, "Config updated.") } func (handler *evictSlowStoreHandler) ListConfig(w http.ResponseWriter, _ *http.Request) { conf := handler.config.Clone() - _ = handler.rd.JSON(w, http.StatusOK, conf) + handler.rd.JSON(w, http.StatusOK, conf) } type evictSlowStoreScheduler struct { diff --git a/pkg/schedule/schedulers/evict_slow_trend.go b/pkg/schedule/schedulers/evict_slow_trend.go index 393a48aa282..da3dbc24e95 100644 --- a/pkg/schedule/schedulers/evict_slow_trend.go +++ b/pkg/schedule/schedulers/evict_slow_trend.go @@ -246,7 +246,7 @@ func (handler *evictSlowTrendHandler) UpdateConfig(w http.ResponseWriter, r *htt } recoveryDurationGapFloat, ok := input["recovery-duration"].(float64) if !ok { - _ = handler.rd.JSON(w, http.StatusInternalServerError, errors.New("invalid argument for 'recovery-duration'").Error()) + handler.rd.JSON(w, http.StatusInternalServerError, errors.New("invalid argument for 'recovery-duration'").Error()) return } handler.config.Lock() @@ -255,17 +255,17 @@ func (handler *evictSlowTrendHandler) UpdateConfig(w http.ResponseWriter, r *htt recoveryDurationGap := uint64(recoveryDurationGapFloat) handler.config.RecoveryDurationGap = recoveryDurationGap if err := handler.config.persistLocked(); err != nil { - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) handler.config.RecoveryDurationGap = prevRecoveryDurationGap return } log.Info("evict-slow-trend-scheduler update 'recovery-duration' - unit: s", zap.Uint64("prev", prevRecoveryDurationGap), zap.Uint64("cur", recoveryDurationGap)) - _ = handler.rd.JSON(w, http.StatusOK, "Config updated.") + handler.rd.JSON(w, http.StatusOK, "Config updated.") } func (handler *evictSlowTrendHandler) ListConfig(w http.ResponseWriter, _ *http.Request) { conf := handler.config.Clone() - _ = handler.rd.JSON(w, http.StatusOK, conf) + handler.rd.JSON(w, http.StatusOK, conf) } type evictSlowTrendScheduler struct { diff --git a/pkg/schedule/schedulers/grant_hot_region.go b/pkg/schedule/schedulers/grant_hot_region.go index 56ed7cd730e..8dac759793c 100644 --- a/pkg/schedule/schedulers/grant_hot_region.go +++ b/pkg/schedule/schedulers/grant_hot_region.go @@ -210,39 +210,39 @@ func (handler *grantHotRegionHandler) UpdateConfig(w http.ResponseWriter, r *htt } ids, ok := input["store-id"].(string) if !ok { - _ = handler.rd.JSON(w, http.StatusBadRequest, errs.ErrSchedulerConfig) + handler.rd.JSON(w, http.StatusBadRequest, errs.ErrSchedulerConfig) return } storeIDs := make([]uint64, 0) for _, v := range strings.Split(ids, ",") { id, err := strconv.ParseUint(v, 10, 64) if err != nil { - _ = handler.rd.JSON(w, http.StatusBadRequest, errs.ErrBytesToUint64) + handler.rd.JSON(w, http.StatusBadRequest, errs.ErrBytesToUint64) return } storeIDs = append(storeIDs, id) } leaderID, err := strconv.ParseUint(input["store-leader-id"].(string), 10, 64) if err != nil { - _ = handler.rd.JSON(w, http.StatusBadRequest, errs.ErrBytesToUint64) + handler.rd.JSON(w, http.StatusBadRequest, errs.ErrBytesToUint64) return } if !handler.config.setStore(leaderID, storeIDs) { - _ = handler.rd.JSON(w, http.StatusBadRequest, errs.ErrSchedulerConfig) + handler.rd.JSON(w, http.StatusBadRequest, errs.ErrSchedulerConfig) return } if err = handler.config.Persist(); err != nil { handler.config.SetStoreLeaderID(0) - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) return } - _ = handler.rd.JSON(w, http.StatusOK, nil) + handler.rd.JSON(w, http.StatusOK, nil) } func (handler *grantHotRegionHandler) ListConfig(w http.ResponseWriter, _ *http.Request) { conf := handler.config.Clone() - _ = handler.rd.JSON(w, http.StatusOK, conf) + handler.rd.JSON(w, http.StatusOK, conf) } func newGrantHotRegionHandler(config *grantHotRegionSchedulerConfig) http.Handler { diff --git a/pkg/schedule/schedulers/grant_leader.go b/pkg/schedule/schedulers/grant_leader.go index ad0b1a09b79..4752ef3e61d 100644 --- a/pkg/schedule/schedulers/grant_leader.go +++ b/pkg/schedule/schedulers/grant_leader.go @@ -284,7 +284,7 @@ func (handler *grantLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R if _, exists = handler.config.StoreIDWithRanges[id]; !exists { if err := handler.config.cluster.PauseLeaderTransfer(id); err != nil { handler.config.RUnlock() - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) return } } @@ -301,28 +301,28 @@ func (handler *grantLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R err := handler.config.BuildWithArgs(args) if err != nil { - _ = handler.rd.JSON(w, http.StatusBadRequest, err.Error()) + handler.rd.JSON(w, http.StatusBadRequest, err.Error()) return } err = handler.config.Persist() if err != nil { handler.config.removeStore(id) - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) return } - _ = handler.rd.JSON(w, http.StatusOK, "The scheduler has been applied to the store.") + handler.rd.JSON(w, http.StatusOK, "The scheduler has been applied to the store.") } func (handler *grantLeaderHandler) ListConfig(w http.ResponseWriter, _ *http.Request) { conf := handler.config.Clone() - _ = handler.rd.JSON(w, http.StatusOK, conf) + handler.rd.JSON(w, http.StatusOK, conf) } func (handler *grantLeaderHandler) DeleteConfig(w http.ResponseWriter, r *http.Request) { idStr := mux.Vars(r)["store_id"] id, err := strconv.ParseUint(idStr, 10, 64) if err != nil { - _ = handler.rd.JSON(w, http.StatusBadRequest, err.Error()) + handler.rd.JSON(w, http.StatusBadRequest, err.Error()) return } @@ -333,26 +333,26 @@ func (handler *grantLeaderHandler) DeleteConfig(w http.ResponseWriter, r *http.R err = handler.config.Persist() if err != nil { handler.config.resetStore(id, keyRanges) - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) return } if last { if err := handler.config.removeSchedulerCb(GrantLeaderName); err != nil { if errors.ErrorEqual(err, errs.ErrSchedulerNotFound.FastGenByArgs()) { - _ = handler.rd.JSON(w, http.StatusNotFound, err.Error()) + handler.rd.JSON(w, http.StatusNotFound, err.Error()) } else { handler.config.resetStore(id, keyRanges) - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) } return } resp = lastStoreDeleteInfo } - _ = handler.rd.JSON(w, http.StatusOK, resp) + handler.rd.JSON(w, http.StatusOK, resp) return } - _ = handler.rd.JSON(w, http.StatusNotFound, errs.ErrScheduleConfigNotExist.FastGenByArgs().Error()) + handler.rd.JSON(w, http.StatusNotFound, errs.ErrScheduleConfigNotExist.FastGenByArgs().Error()) } func newGrantLeaderHandler(config *grantLeaderSchedulerConfig) http.Handler { diff --git a/pkg/schedule/schedulers/hot_region_config.go b/pkg/schedule/schedulers/hot_region_config.go index d71e5e984bd..517edb1d637 100644 --- a/pkg/schedule/schedulers/hot_region_config.go +++ b/pkg/schedule/schedulers/hot_region_config.go @@ -379,7 +379,7 @@ func (conf *hotRegionSchedulerConfig) handleGetConfig(w http.ResponseWriter, _ * conf.RLock() defer conf.RUnlock() rd := render.New(render.Options{IndentJSON: true}) - _ = rd.JSON(w, http.StatusOK, conf.getValidConf()) + rd.JSON(w, http.StatusOK, conf.getValidConf()) } func isPriorityValid(priorities []string) (map[string]bool, error) { @@ -434,20 +434,20 @@ func (conf *hotRegionSchedulerConfig) handleSetConfig(w http.ResponseWriter, r * data, err := io.ReadAll(r.Body) r.Body.Close() if err != nil { - _ = rd.JSON(w, http.StatusInternalServerError, err.Error()) + rd.JSON(w, http.StatusInternalServerError, err.Error()) return } if err := json.Unmarshal(data, conf); err != nil { - _ = rd.JSON(w, http.StatusInternalServerError, err.Error()) + rd.JSON(w, http.StatusInternalServerError, err.Error()) return } if err := conf.validateLocked(); err != nil { // revert to old version if err2 := json.Unmarshal(oldc, conf); err2 != nil { - _ = rd.JSON(w, http.StatusInternalServerError, err2.Error()) + rd.JSON(w, http.StatusInternalServerError, err2.Error()) } else { - _ = rd.JSON(w, http.StatusBadRequest, err.Error()) + rd.JSON(w, http.StatusBadRequest, err.Error()) } return } @@ -457,22 +457,22 @@ func (conf *hotRegionSchedulerConfig) handleSetConfig(w http.ResponseWriter, r * log.Warn("failed to persist config", zap.Error(err)) } log.Info("hot-region-scheduler config is updated", zap.String("old", string(oldc)), zap.String("new", string(newc))) - _ = rd.Text(w, http.StatusOK, "Config is updated.") + rd.Text(w, http.StatusOK, "Config is updated.") return } m := make(map[string]any) if err := json.Unmarshal(data, &m); err != nil { - _ = rd.JSON(w, http.StatusInternalServerError, err.Error()) + rd.JSON(w, http.StatusInternalServerError, err.Error()) return } ok := reflectutil.FindSameFieldByJSON(conf, m) if ok { - _ = rd.Text(w, http.StatusOK, "Config is the same with origin, so do nothing.") + rd.Text(w, http.StatusOK, "Config is the same with origin, so do nothing.") return } - _ = rd.Text(w, http.StatusBadRequest, "Config item is not found.") + rd.Text(w, http.StatusBadRequest, "Config item is not found.") } func (conf *hotRegionSchedulerConfig) persistLocked() error { diff --git a/pkg/schedule/schedulers/scatter_range.go b/pkg/schedule/schedulers/scatter_range.go index a7fadf703eb..ebee66dc207 100644 --- a/pkg/schedule/schedulers/scatter_range.go +++ b/pkg/schedule/schedulers/scatter_range.go @@ -255,7 +255,7 @@ func (handler *scatterRangeHandler) UpdateConfig(w http.ResponseWriter, r *http. name, ok := input["range-name"].(string) if ok { if name != handler.config.GetRangeName() { - _ = handler.rd.JSON(w, http.StatusInternalServerError, errors.New("Cannot change the range name, please delete this schedule").Error()) + handler.rd.JSON(w, http.StatusInternalServerError, errors.New("Cannot change the range name, please delete this schedule").Error()) return } args = append(args, name) @@ -278,19 +278,19 @@ func (handler *scatterRangeHandler) UpdateConfig(w http.ResponseWriter, r *http. } err := handler.config.BuildWithArgs(args) if err != nil { - _ = handler.rd.JSON(w, http.StatusBadRequest, err.Error()) + handler.rd.JSON(w, http.StatusBadRequest, err.Error()) return } err = handler.config.Persist() if err != nil { - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) } - _ = handler.rd.JSON(w, http.StatusOK, nil) + handler.rd.JSON(w, http.StatusOK, nil) } func (handler *scatterRangeHandler) ListConfig(w http.ResponseWriter, _ *http.Request) { conf := handler.config.Clone() - _ = handler.rd.JSON(w, http.StatusOK, conf) + handler.rd.JSON(w, http.StatusOK, conf) } func newScatterRangeHandler(config *scatterRangeSchedulerConfig) http.Handler { diff --git a/pkg/schedule/schedulers/shuffle_hot_region.go b/pkg/schedule/schedulers/shuffle_hot_region.go index 0b9021267cb..726138e8f7a 100644 --- a/pkg/schedule/schedulers/shuffle_hot_region.go +++ b/pkg/schedule/schedulers/shuffle_hot_region.go @@ -234,7 +234,7 @@ func (handler *shuffleHotRegionHandler) UpdateConfig(w http.ResponseWriter, r *h } limit, ok := input["limit"].(float64) if !ok { - _ = handler.rd.JSON(w, http.StatusBadRequest, "invalid limit") + handler.rd.JSON(w, http.StatusBadRequest, "invalid limit") return } handler.config.Lock() @@ -243,16 +243,16 @@ func (handler *shuffleHotRegionHandler) UpdateConfig(w http.ResponseWriter, r *h handler.config.Limit = uint64(limit) err := handler.config.persistLocked() if err != nil { - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) handler.config.Limit = previous return } - _ = handler.rd.JSON(w, http.StatusOK, nil) + handler.rd.JSON(w, http.StatusOK, nil) } func (handler *shuffleHotRegionHandler) ListConfig(w http.ResponseWriter, _ *http.Request) { conf := handler.config.Clone() - _ = handler.rd.JSON(w, http.StatusOK, conf) + handler.rd.JSON(w, http.StatusOK, conf) } func newShuffleHotRegionHandler(config *shuffleHotRegionSchedulerConfig) http.Handler { diff --git a/pkg/schedule/schedulers/shuffle_region_config.go b/pkg/schedule/schedulers/shuffle_region_config.go index 6a4a698aa5b..bce64f743b8 100644 --- a/pkg/schedule/schedulers/shuffle_region_config.go +++ b/pkg/schedule/schedulers/shuffle_region_config.go @@ -79,7 +79,7 @@ func (conf *shuffleRegionSchedulerConfig) ServeHTTP(w http.ResponseWriter, r *ht func (conf *shuffleRegionSchedulerConfig) handleGetRoles(w http.ResponseWriter, _ *http.Request) { rd := render.New(render.Options{IndentJSON: true}) - _ = rd.JSON(w, http.StatusOK, conf.GetRoles()) + rd.JSON(w, http.StatusOK, conf.GetRoles()) } func (conf *shuffleRegionSchedulerConfig) handleSetRoles(w http.ResponseWriter, r *http.Request) { @@ -90,7 +90,7 @@ func (conf *shuffleRegionSchedulerConfig) handleSetRoles(w http.ResponseWriter, } for _, r := range roles { if slice.NoneOf(allRoles, func(i int) bool { return allRoles[i] == r }) { - _ = rd.Text(w, http.StatusBadRequest, "invalid role:"+r) + rd.Text(w, http.StatusBadRequest, "invalid role:"+r) return } } @@ -101,10 +101,10 @@ func (conf *shuffleRegionSchedulerConfig) handleSetRoles(w http.ResponseWriter, conf.Roles = roles if err := conf.persist(); err != nil { conf.Roles = old // revert - _ = rd.Text(w, http.StatusInternalServerError, err.Error()) + rd.Text(w, http.StatusInternalServerError, err.Error()) return } - _ = rd.Text(w, http.StatusOK, "Config is updated.") + rd.Text(w, http.StatusOK, "Config is updated.") } func (conf *shuffleRegionSchedulerConfig) persist() error { diff --git a/pkg/schedule/schedulers/split_bucket.go b/pkg/schedule/schedulers/split_bucket.go index 2a22d695953..9b049bf6ba1 100644 --- a/pkg/schedule/schedulers/split_bucket.go +++ b/pkg/schedule/schedulers/split_bucket.go @@ -23,6 +23,8 @@ import ( "github.com/gorilla/mux" "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" sche "github.com/tikv/pd/pkg/schedule/core" "github.com/tikv/pd/pkg/schedule/operator" "github.com/tikv/pd/pkg/schedule/plan" @@ -112,7 +114,7 @@ type splitBucketHandler struct { func (h *splitBucketHandler) ListConfig(w http.ResponseWriter, _ *http.Request) { conf := h.conf.Clone() - _ = h.rd.JSON(w, http.StatusOK, conf) + h.rd.JSON(w, http.StatusOK, conf) } func (h *splitBucketHandler) UpdateConfig(w http.ResponseWriter, r *http.Request) { @@ -123,33 +125,35 @@ func (h *splitBucketHandler) UpdateConfig(w http.ResponseWriter, r *http.Request data, err := io.ReadAll(r.Body) defer r.Body.Close() if err != nil { - _ = rd.JSON(w, http.StatusInternalServerError, err.Error()) + rd.JSON(w, http.StatusInternalServerError, err.Error()) return } if err := json.Unmarshal(data, h.conf); err != nil { - _ = rd.JSON(w, http.StatusInternalServerError, err.Error()) + rd.JSON(w, http.StatusInternalServerError, err.Error()) return } newc, _ := json.Marshal(h.conf) if !bytes.Equal(oldc, newc) { - h.conf.persistLocked() - _ = rd.Text(w, http.StatusOK, "Config is updated.") + if err := h.conf.persistLocked(); err != nil { + log.Warn("failed to save config", errs.ZapError(err)) + } + rd.Text(w, http.StatusOK, "Config is updated.") return } m := make(map[string]any) if err := json.Unmarshal(data, &m); err != nil { - _ = rd.JSON(w, http.StatusInternalServerError, err.Error()) + rd.JSON(w, http.StatusInternalServerError, err.Error()) return } ok := reflectutil.FindSameFieldByJSON(h.conf, m) if ok { - _ = rd.Text(w, http.StatusOK, "Config is the same with origin, so do nothing.") + rd.Text(w, http.StatusOK, "Config is the same with origin, so do nothing.") return } - _ = rd.Text(w, http.StatusBadRequest, "Config item is not found.") + rd.Text(w, http.StatusBadRequest, "Config item is not found.") } func newSplitBucketHandler(conf *splitBucketSchedulerConfig) http.Handler { diff --git a/pkg/tso/admin.go b/pkg/tso/admin.go index 6626d1d2714..bc9fd1f853d 100644 --- a/pkg/tso/admin.go +++ b/pkg/tso/admin.go @@ -73,12 +73,12 @@ func (h *AdminHandler) ResetTS(w http.ResponseWriter, r *http.Request) { } tsValue, ok := input["tso"].(string) if !ok || len(tsValue) == 0 { - _ = h.rd.JSON(w, http.StatusBadRequest, "invalid tso value") + h.rd.JSON(w, http.StatusBadRequest, "invalid tso value") return } ts, err := strconv.ParseUint(tsValue, 10, 64) if err != nil { - _ = h.rd.JSON(w, http.StatusBadRequest, "invalid tso value") + h.rd.JSON(w, http.StatusBadRequest, "invalid tso value") return } @@ -86,7 +86,7 @@ func (h *AdminHandler) ResetTS(w http.ResponseWriter, r *http.Request) { forceUseLargerVal, contains := input["force-use-larger"] if contains { if forceUseLarger, ok = forceUseLargerVal.(bool); !ok { - _ = h.rd.JSON(w, http.StatusBadRequest, "invalid force-use-larger value") + h.rd.JSON(w, http.StatusBadRequest, "invalid force-use-larger value") return } } @@ -97,17 +97,17 @@ func (h *AdminHandler) ResetTS(w http.ResponseWriter, r *http.Request) { if err = handler.ResetTS(ts, ignoreSmaller, skipUpperBoundCheck, 0); err != nil { if err == errs.ErrServerNotStarted { - _ = h.rd.JSON(w, http.StatusInternalServerError, err.Error()) + h.rd.JSON(w, http.StatusInternalServerError, err.Error()) } else if err == errs.ErrEtcdTxnConflict { // If the error is ErrEtcdTxnConflict, it means there is a temporary failure. // Return 503 to let the client retry. // Ref: https://datatracker.ietf.org/doc/html/rfc7231#section-6.6.4 - _ = h.rd.JSON(w, http.StatusServiceUnavailable, + h.rd.JSON(w, http.StatusServiceUnavailable, fmt.Sprintf("It's a temporary failure with error %s, please retry.", err.Error())) } else { - _ = h.rd.JSON(w, http.StatusForbidden, err.Error()) + h.rd.JSON(w, http.StatusForbidden, err.Error()) } return } - _ = h.rd.JSON(w, http.StatusOK, "Reset ts successfully.") + h.rd.JSON(w, http.StatusOK, "Reset ts successfully.") } diff --git a/pkg/utils/apiutil/apiutil.go b/pkg/utils/apiutil/apiutil.go index 2503ba9aecf..20465d8376c 100644 --- a/pkg/utils/apiutil/apiutil.go +++ b/pkg/utils/apiutil/apiutil.go @@ -116,14 +116,14 @@ func TagJSONError(err error) error { func ErrorResp(rd *render.Render, w http.ResponseWriter, err error) { if err == nil { log.Error("nil is given to errorResp") - _ = rd.JSON(w, http.StatusInternalServerError, "nil error") + rd.JSON(w, http.StatusInternalServerError, "nil error") return } if errCode := errcode.CodeChain(err); errCode != nil { w.Header().Set("TiDB-Error-Code", errCode.Code().CodeStr().String()) - _ = rd.JSON(w, errCode.Code().HTTPCode(), errcode.NewJSONFormat(errCode)) + rd.JSON(w, errCode.Code().HTTPCode(), errcode.NewJSONFormat(errCode)) } else { - _ = rd.JSON(w, http.StatusInternalServerError, err.Error()) + rd.JSON(w, http.StatusInternalServerError, err.Error()) } } diff --git a/plugin/scheduler_example/evict_leader.go b/plugin/scheduler_example/evict_leader.go index 1e26a97e12c..a37874a8461 100644 --- a/plugin/scheduler_example/evict_leader.go +++ b/plugin/scheduler_example/evict_leader.go @@ -259,7 +259,7 @@ func (handler *evictLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R id = (uint64)(idFloat) if _, exists = handler.config.StoreIDWitRanges[id]; !exists { if err := handler.config.cluster.PauseLeaderTransfer(id); err != nil { - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) return } } @@ -275,27 +275,27 @@ func (handler *evictLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R err := handler.config.BuildWithArgs(args) if err != nil { - _ = handler.rd.JSON(w, http.StatusBadRequest, err.Error()) + handler.rd.JSON(w, http.StatusBadRequest, err.Error()) return } err = handler.config.Persist() if err != nil { - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) return } - _ = handler.rd.JSON(w, http.StatusOK, nil) + handler.rd.JSON(w, http.StatusOK, nil) } func (handler *evictLeaderHandler) ListConfig(w http.ResponseWriter, _ *http.Request) { conf := handler.config.Clone() - _ = handler.rd.JSON(w, http.StatusOK, conf) + handler.rd.JSON(w, http.StatusOK, conf) } func (handler *evictLeaderHandler) DeleteConfig(w http.ResponseWriter, r *http.Request) { idStr := mux.Vars(r)["store_id"] id, err := strconv.ParseUint(idStr, 10, 64) if err != nil { - _ = handler.rd.JSON(w, http.StatusBadRequest, err.Error()) + handler.rd.JSON(w, http.StatusBadRequest, err.Error()) return } @@ -303,7 +303,7 @@ func (handler *evictLeaderHandler) DeleteConfig(w http.ResponseWriter, r *http.R defer handler.config.mu.Unlock() _, exists := handler.config.StoreIDWitRanges[id] if !exists { - _ = handler.rd.JSON(w, http.StatusInternalServerError, errors.New("the config does not exist")) + handler.rd.JSON(w, http.StatusInternalServerError, errors.New("the config does not exist")) return } delete(handler.config.StoreIDWitRanges, id) @@ -312,7 +312,7 @@ func (handler *evictLeaderHandler) DeleteConfig(w http.ResponseWriter, r *http.R handler.config.mu.Unlock() if err := handler.config.Persist(); err != nil { handler.config.mu.Lock() - _ = handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) + handler.rd.JSON(w, http.StatusInternalServerError, err.Error()) return } handler.config.mu.Lock() @@ -321,7 +321,7 @@ func (handler *evictLeaderHandler) DeleteConfig(w http.ResponseWriter, r *http.R if len(handler.config.StoreIDWitRanges) == 0 { resp = noStoreInSchedulerInfo } - _ = handler.rd.JSON(w, http.StatusOK, resp) + handler.rd.JSON(w, http.StatusOK, resp) } func newEvictLeaderHandler(config *evictLeaderSchedulerConfig) http.Handler { diff --git a/server/api/admin.go b/server/api/admin.go index dd81985b514..2184dc66aa6 100644 --- a/server/api/admin.go +++ b/server/api/admin.go @@ -150,30 +150,30 @@ func (h *adminHandler) SavePersistFile(w http.ResponseWriter, r *http.Request) { func (h *adminHandler) MarkSnapshotRecovering(w http.ResponseWriter, _ *http.Request) { if err := h.svr.MarkSnapshotRecovering(); err != nil { - _ = h.rd.Text(w, http.StatusInternalServerError, err.Error()) + h.rd.Text(w, http.StatusInternalServerError, err.Error()) return } - _ = h.rd.Text(w, http.StatusOK, "") + h.rd.Text(w, http.StatusOK, "") } func (h *adminHandler) IsSnapshotRecovering(w http.ResponseWriter, r *http.Request) { marked, err := h.svr.IsSnapshotRecovering(r.Context()) if err != nil { - _ = h.rd.Text(w, http.StatusInternalServerError, err.Error()) + h.rd.Text(w, http.StatusInternalServerError, err.Error()) return } type resStruct struct { Marked bool `json:"marked"` } - _ = h.rd.JSON(w, http.StatusOK, &resStruct{Marked: marked}) + h.rd.JSON(w, http.StatusOK, &resStruct{Marked: marked}) } func (h *adminHandler) UnmarkSnapshotRecovering(w http.ResponseWriter, r *http.Request) { if err := h.svr.UnmarkSnapshotRecovering(r.Context()); err != nil { - _ = h.rd.Text(w, http.StatusInternalServerError, err.Error()) + h.rd.Text(w, http.StatusInternalServerError, err.Error()) return } - _ = h.rd.Text(w, http.StatusOK, "") + h.rd.Text(w, http.StatusOK, "") } // RecoverAllocID recover base alloc id @@ -185,34 +185,34 @@ func (h *adminHandler) RecoverAllocID(w http.ResponseWriter, r *http.Request) { } idValue, ok := input["id"].(string) if !ok || len(idValue) == 0 { - _ = h.rd.Text(w, http.StatusBadRequest, "invalid id value") + h.rd.Text(w, http.StatusBadRequest, "invalid id value") return } newID, err := strconv.ParseUint(idValue, 10, 64) if err != nil { - _ = h.rd.Text(w, http.StatusBadRequest, err.Error()) + h.rd.Text(w, http.StatusBadRequest, err.Error()) return } marked, err := h.svr.IsSnapshotRecovering(r.Context()) if err != nil { - _ = h.rd.Text(w, http.StatusInternalServerError, err.Error()) + h.rd.Text(w, http.StatusInternalServerError, err.Error()) return } if !marked { - _ = h.rd.Text(w, http.StatusForbidden, "can only recover alloc id when recovering mark marked") + h.rd.Text(w, http.StatusForbidden, "can only recover alloc id when recovering mark marked") return } leader := h.svr.GetLeader() if leader == nil { - _ = h.rd.Text(w, http.StatusServiceUnavailable, errs.ErrLeaderNil.FastGenByArgs().Error()) + h.rd.Text(w, http.StatusServiceUnavailable, errs.ErrLeaderNil.FastGenByArgs().Error()) return } if err = h.svr.RecoverAllocID(r.Context(), newID); err != nil { - _ = h.rd.Text(w, http.StatusInternalServerError, err.Error()) + h.rd.Text(w, http.StatusInternalServerError, err.Error()) } - _ = h.rd.Text(w, http.StatusOK, "") + h.rd.Text(w, http.StatusOK, "") } func (h *adminHandler) DeleteRegionCacheInSchedulingServer(id ...uint64) error { diff --git a/server/api/router.go b/server/api/router.go index 553332e96af..7aef165b267 100644 --- a/server/api/router.go +++ b/server/api/router.go @@ -388,7 +388,7 @@ func createRouter(prefix string, svr *server.Server) *mux.Router { // Deprecated: use /pd/api/v1/ping instead. rootRouter.HandleFunc("/ping", func(http.ResponseWriter, *http.Request) {}).Methods(http.MethodGet) - rootRouter.Walk(func(route *mux.Route, _ *mux.Router, _ []*mux.Route) error { + _ = rootRouter.Walk(func(route *mux.Route, _ *mux.Router, _ []*mux.Route) error { serviceLabel := route.GetName() methods, _ := route.GetMethods() path, _ := route.GetPathTemplate() diff --git a/server/api/store.go b/server/api/store.go index ba8c71c1020..4bf4af1496b 100644 --- a/server/api/store.go +++ b/server/api/store.go @@ -26,6 +26,7 @@ import ( "github.com/pingcap/errcode" "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/pingcap/log" "github.com/tikv/pd/pkg/core/storelimit" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/response" @@ -358,7 +359,9 @@ func (h *storeHandler) SetStoreLimit(w http.ResponseWriter, r *http.Request) { if typ == storelimit.RemovePeer { key = fmt.Sprintf("remove-peer-%v", storeID) } - h.handler.SetStoreLimitTTL(key, ratePerMin, time.Duration(ttl)*time.Second) + if err := h.handler.SetStoreLimitTTL(key, ratePerMin, time.Duration(ttl)*time.Second); err != nil { + log.Warn("failed to set store limit", errs.ZapError(err)) + } continue } if err := h.handler.SetStoreLimit(storeID, ratePerMin, typ); err != nil { diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index 94713386e08..93be9d1c076 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -1058,7 +1058,7 @@ func (c *RaftCluster) processRegionHeartbeat(ctx *core.MetaProcessContext, regio // region stats needs to be collected in API mode. // We need to think of a better way to reduce this part of the cost in the future. if hasRegionStats && c.regionStats.RegionStatsNeedUpdate(region) { - _ = ctx.MiscRunner.RunTask( + ctx.MiscRunner.RunTask( regionID, ratelimit.ObserveRegionStatsAsync, func() { @@ -1070,7 +1070,7 @@ func (c *RaftCluster) processRegionHeartbeat(ctx *core.MetaProcessContext, regio } // region is not updated to the subtree. if origin.GetRef() < 2 { - _ = ctx.TaskRunner.RunTask( + ctx.TaskRunner.RunTask( regionID, ratelimit.UpdateSubTree, func() { @@ -1098,7 +1098,7 @@ func (c *RaftCluster) processRegionHeartbeat(ctx *core.MetaProcessContext, regio tracer.OnSaveCacheFinished() return err } - _ = ctx.TaskRunner.RunTask( + ctx.TaskRunner.RunTask( regionID, ratelimit.UpdateSubTree, func() { @@ -1109,7 +1109,7 @@ func (c *RaftCluster) processRegionHeartbeat(ctx *core.MetaProcessContext, regio tracer.OnUpdateSubTreeFinished() if !c.IsServiceIndependent(mcsutils.SchedulingServiceName) { - _ = ctx.MiscRunner.RunTask( + ctx.MiscRunner.RunTask( regionID, ratelimit.HandleOverlaps, func() { @@ -1122,7 +1122,7 @@ func (c *RaftCluster) processRegionHeartbeat(ctx *core.MetaProcessContext, regio tracer.OnSaveCacheFinished() // handle region stats - _ = ctx.MiscRunner.RunTask( + ctx.MiscRunner.RunTask( regionID, ratelimit.CollectRegionStatsAsync, func() { @@ -1136,7 +1136,7 @@ func (c *RaftCluster) processRegionHeartbeat(ctx *core.MetaProcessContext, regio tracer.OnCollectRegionStatsFinished() if c.storage != nil { if saveKV { - _ = ctx.MiscRunner.RunTask( + ctx.MiscRunner.RunTask( regionID, ratelimit.SaveRegionToKV, func() {