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 errcheck for server/*.go except server/api #8317

Merged
merged 11 commits into from
Jun 27, 2024

Conversation

okJiang
Copy link
Member

@okJiang okJiang commented Jun 21, 2024

What problem does this PR solve?

Issue Number: Ref #1919

What is changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Code changes

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

Release note

None.

okJiang added 2 commits June 21, 2024 15:30
Signed-off-by: okJiang <819421878@qq.com>
Signed-off-by: okJiang <819421878@qq.com>
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 21, 2024
cmd/pd-server/main.go Outdated Show resolved Hide resolved
@@ -232,46 +232,44 @@ func (m *ModeManager) loadDRAutoSync() error {
return nil
}

func (m *ModeManager) drSwitchToAsyncWait(availableStores []uint64) error {
func (m *ModeManager) drSwitchToAsyncWait(availableStores []uint64) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller always ignored this error, and all errors were logged within the function, so I removed it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the tests will check the return value of drSwitchToAsync.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I will revert it for the test

}

func (m *ModeManager) drSwitchToAsync(availableStores []uint64) error {
func (m *ModeManager) drSwitchToAsync(availableStores []uint64) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

okJiang added 2 commits June 21, 2024 17:20
Signed-off-by: okJiang <819421878@qq.com>
Signed-off-by: okJiang <819421878@qq.com>
@okJiang
Copy link
Member Author

okJiang commented Jun 24, 2024

/cc @JmPotato @HuSharp

@ti-chi-bot ti-chi-bot bot requested review from HuSharp and JmPotato June 24, 2024 03:32
l.RegisterRESTHandler(h)
log.Info("restful API service already registered", zap.String("prefix", prefix), zap.String("service-name", name))
if err := l.RegisterRESTHandler(h); err != nil {
log.Error("register REST handler failed", zap.String("prefix", prefix), zap.String("service-name", name), zap.Error(err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Error("register REST handler failed", zap.String("prefix", prefix), zap.String("service-name", name), zap.Error(err))
log.Error("register restful API service failed", zap.String("prefix", prefix), zap.String("service-name", name), zap.Error(err))

@@ -100,7 +100,9 @@ func (se *StorageEndpoint) LoadMinServiceGCSafePoint(now time.Time) (*ServiceSaf
}

if ssp.ExpiredAt < now.Unix() {
se.Remove(key)
if err := se.Remove(key); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to return the error here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in c01b053

s.limit.WaitN(ctx, resp.Size())
if err := s.limit.WaitN(ctx, resp.Size()); err != nil {
log.Error("failed to wait rate limit", errs.ZapError(err))
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to return?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's possible to return an error here.

After checking the source code, there are two types of errors that WaitN returns, fmt.Errorf("rate: Wait(n=%d) exceeds limiter's burst %d", n, burst) and context errors.

  • For the former. If resp.Size() exceeds the burst, then continuing to loop will still result in an error because resp.Size will keep increasing. In this case, the error won't be thrown, but adding logs will keep printing out, and the client may never receive resp. Unless we can guarantee that within maxSyncRegionBatchSize, resp.Size will never exceed the burst (20MiB).
  • For the latter, it doesn't matter, because there is a select ctx.Done() inside the loop.

If we can't guarantee that the information of maxSyncRegionBatchSize regions is definitely less than 20MiB, it's best to check if resp.Size is close to 20MiB before continuing at L275.

Signed-off-by: okJiang <819421878@qq.com>
okJiang added 2 commits June 26, 2024 11:47
Signed-off-by: okJiang <819421878@qq.com>
cmd/pd-server/main.go Outdated Show resolved Hide resolved
l.RegisterRESTHandler(h)
log.Info("restful API service registered successfully", zap.String("prefix", prefix), zap.String("service-name", name))
if err := l.RegisterRESTHandler(h); err != nil {
log.Error("register restful API service failed", zap.String("prefix", prefix), zap.String("service-name", name), zap.Error(err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is best to distinguish it from line 86.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line numbers of log will be automatically differentiated, or do you have any suggestions on how to modify the log content?

@@ -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")) // nolint:errcheck
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. Prefer using _ = w.Write([]byte("not implemented")).

@@ -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")) // nolint:errcheck
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Signed-off-by: okJiang <819421878@qq.com>
@okJiang
Copy link
Member Author

okJiang commented Jun 27, 2024

Can you take a look again? Thanks! @JmPotato @rleungx @HuSharp

cmd/pd-server/main.go Outdated Show resolved Hide resolved
Comment on lines +231 to +233
if err := stream.Send(resps); err != nil {
return errors.WithStack(err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether it is on purpose.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed forgot to consider error handling previously.

Signed-off-by: okJiang <819421878@qq.com>
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 27, 2024
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 27, 2024
Copy link
Contributor

ti-chi-bot bot commented Jun 27, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-06-27 07:06:19.518807219 +0000 UTC m=+876106.004296051: ☑️ agreed by rleungx.
  • 2024-06-27 09:37:32.08624861 +0000 UTC m=+885178.571737443: ☑️ agreed by JmPotato.

@JmPotato
Copy link
Member

/merge

Copy link
Contributor

ti-chi-bot bot commented Jun 27, 2024

@JmPotato: We have migrated to builtin LGTM and approve plugins for reviewing.

👉 Please use /approve when you want approve this pull request.

The changes announcement: Proposal: Strengthen configuration change approval.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@JmPotato
Copy link
Member

/approve

Copy link
Contributor

ti-chi-bot bot commented Jun 27, 2024

@okJiang: Your PR was out of date, I have automatically updated it for you.

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@rleungx
Copy link
Member

rleungx commented Jun 27, 2024

/approve

Copy link
Contributor

ti-chi-bot bot commented Jun 27, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JmPotato, niubell, rleungx

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Jun 27, 2024
@ti-chi-bot ti-chi-bot bot merged commit 4048cba into tikv:master Jun 27, 2024
17 checks passed
@okJiang okJiang deleted the enable-errcheck-3 branch June 27, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants