Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: enable error check for mcs, keyspace and labeler #8288

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (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())

Check warning on line 44 in pkg/autoscaling/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/autoscaling/handler.go#L44

Added line #L44 was not covered by tests
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())

Check warning on line 50 in pkg/autoscaling/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/autoscaling/handler.go#L50

Added line #L50 was not covered by tests
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())

Check warning on line 56 in pkg/autoscaling/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/autoscaling/handler.go#L56

Added line #L56 was not covered by tests
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 @@
}
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),
)

Check warning on line 328 in pkg/keyspace/keyspace.go

View check run for this annotation

Codecov / codecov/patch

pkg/keyspace/keyspace.go#L324-L328

Added lines #L324 - L328 were not covered by tests
}
}
}()

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 @@

// Exit exits the program with the given code.
func Exit(code int) {
log.Sync()
_ = log.Sync()

Check warning on line 327 in pkg/mcs/utils/util.go

View check run for this annotation

Codecov / codecov/patch

pkg/mcs/utils/util.go#L327

Added line #L327 was not covered by tests
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 @@
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))

Check warning on line 205 in pkg/schedule/labeler/labeler.go

View check run for this annotation

Codecov / codecov/patch

pkg/schedule/labeler/labeler.go#L205

Added line #L205 was not covered by tests
}
return nil
}
l.SaveLabelRuleLocked(rule)
_ = l.SaveLabelRuleLocked(rule)

Check warning on line 209 in pkg/schedule/labeler/labeler.go

View check run for this annotation

Codecov / codecov/patch

pkg/schedule/labeler/labeler.go#L209

Added line #L209 was not covered by tests
return rule
}

Expand Down