Skip to content

Commit

Permalink
*: enable error check for mcs, keyspace and labeler (#8288)
Browse files Browse the repository at this point in the history
ref #1919

Signed-off-by: Ryan Leung <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
rleungx and ti-chi-bot[bot] authored Jun 14, 2024
1 parent 463aee9 commit c1d422e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,6 @@ 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/labeler/labeler.go|pkg/mcs/tso/server/config.go|pkg/tso/admin.go|pkg/mcs/tso/server/grpc_service.go|pkg/schedule/schedulers/split_bucket.go|server/api/plugin_disable.go|server/api/plugin_disable.go|server/api/operator.go|server/api/region.go|pkg/schedule/schedulers/balance_leader.go|pkg/mcs/resourcemanager/server/server.go|pkg/mcs/scheduling/server/grpc_service.go|pkg/mcs/resourcemanager/server/.*\.go|plugin/scheduler_example/evict_leader.go|server/api/.*\.go|pkg/replication/replication_mode.go|pkg/mcs/scheduling/server/server.go|pkg/storage/endpoint/gc_safe_point.go|server/.*\.go|pkg/schedule/schedulers/.*\.go|pkg/schedule/placement/rule.go|pkg/mcs/utils/util.go|pkg/keyspace/tso_keyspace_group.go|pkg/tso/allocator_manager.go|pkg/core/store_stats.go|pkg/autoscaling/handler.go|pkg/core/store_stats.go|pkg/keyspace/keyspace.go|pkg/storage/hot_region_storage.go|pkg/syncer/server.go)
- path: (pkg/tso/admin.go|pkg/schedule/schedulers/split_bucket.go|server/api/plugin_disable.go|server/api/plugin_disable.go|server/api/operator.go|server/api/region.go|pkg/schedule/schedulers/balance_leader.go|plugin/scheduler_example/evict_leader.go|server/api/.*\.go|pkg/replication/replication_mode.go|pkg/storage/endpoint/gc_safe_point.go|server/.*\.go|pkg/schedule/schedulers/.*\.go|pkg/schedule/placement/rule.go|pkg/tso/allocator_manager.go|pkg/core/store_stats.go|pkg/core/store_stats.go|pkg/storage/hot_region_storage.go|pkg/syncer/server.go)
linters:
- errcheck
8 changes: 4 additions & 4 deletions pkg/autoscaling/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 6 additions & 1 deletion pkg/keyspace/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,12 @@ func (manager *Manager) splitKeyspaceRegion(id uint32, waitRegionSplit bool) (er
}
defer func() {
if err != nil {
cl.GetRegionLabeler().DeleteLabelRule(keyspaceRule.ID)
if err := cl.GetRegionLabeler().DeleteLabelRule(keyspaceRule.ID); err != nil {
log.Warn("[keyspace] failed to delete region label for keyspace",
zap.Uint32("keyspace-id", id),
zap.Error(err),
)
}
}
}()

Expand Down
2 changes: 1 addition & 1 deletion pkg/keyspace/tso_keyspace_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func (m *GroupManager) UpdateKeyspaceForGroup(userKind endpoint.UserKind, groupI
failpoint.Inject("externalAllocNode", func(val failpoint.Value) {
failpointOnce.Do(func() {
addrs := val.(string)
m.SetNodesForKeyspaceGroup(utils.DefaultKeyspaceGroupID, strings.Split(addrs, ","))
_ = m.SetNodesForKeyspaceGroup(utils.DefaultKeyspaceGroupID, strings.Split(addrs, ","))
})
})
m.Lock()
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcs/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 4 additions & 2 deletions pkg/schedule/labeler/labeler.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ func (l *RegionLabeler) getAndCheckRule(id string, now time.Time) *LabelRule {
return rule
}
if len(rule.Labels) == 0 {
l.DeleteLabelRuleLocked(id)
if err := l.DeleteLabelRuleLocked(id); err != nil {
log.Error("failed to delete label rule", zap.String("rule-key", id), zap.Error(err))
}
return nil
}
l.SaveLabelRuleLocked(rule)
_ = l.SaveLabelRuleLocked(rule)
return rule
}

Expand Down

0 comments on commit c1d422e

Please sign in to comment.