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

tests/server: reduce test time for heartbeat msg cannot be triggered #7998

Closed
wants to merge 3 commits into from

Conversation

HuSharp
Copy link
Member

@HuSharp HuSharp commented Mar 28, 2024

What problem does this PR solve?

Issue Number: Ref #7969

What is changed and how does it work?

Performance

can reduce test time from 5s+1min(wait for keepalive) to 5s

Why change?

Previous test want to mock client send region heartbeat to server, and then server will return msg to client.

But Previous test only can be triggered by keepalive

case <-keepAliveTicker.C:

So I changed region id to 0 which will send error msg

pd/server/grpc_service.go

Lines 1279 to 1284 in 5c58ddd

if region.GetID() == 0 {
regionHeartbeatCounter.WithLabelValues(storeAddress, storeLabel, "report", "invalid-region").Inc()
msg := fmt.Sprintf("invalid request region, %v", request)
s.hbStreams.SendErr(pdpb.ErrorType_UNKNOWN, msg, request.GetLeader())
continue
}

and then client will get msg by
case msg := <-s.msgCh:

Check List

Tests

  • Unit test

Release note

None.

Signed-off-by: husharp <[email protected]>
@HuSharp HuSharp requested review from lhy1024 and rleungx March 28, 2024 14:12
Copy link
Contributor

ti-chi-bot bot commented Mar 28, 2024

[REVIEW NOTIFICATION]

This pull request has not been approved.

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 28, 2024
Copy link

codecov bot commented Mar 28, 2024

Codecov Report

Merging #7998 (18e96a6) into master (67461dd) will increase coverage by 0.03%.
Report is 1 commits behind head on master.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7998      +/-   ##
==========================================
+ Coverage   77.27%   77.30%   +0.03%     
==========================================
  Files         468      468              
  Lines       60890    60890              
==========================================
+ Hits        47055    47074      +19     
+ Misses      10291    10288       -3     
+ Partials     3544     3528      -16     
Flag Coverage Δ
unittests 77.30% <ø> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@HuSharp HuSharp requested a review from JmPotato March 29, 2024 07:50
peer := &metapb.Peer{Id: peerID, StoreId: store.GetId()}
regionReq := &pdpb.RegionHeartbeatRequest{
Header: testutil.NewRequestHeader(clusterID),
Region: &metapb.Region{
Id: regionID,
// mock error msg to trigger stream.Recv()
Id: 0,
Copy link
Member

Choose a reason for hiding this comment

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

Will it skip some processes of handle region heartbeat?

Copy link
Member Author

@HuSharp HuSharp Mar 29, 2024

Choose a reason for hiding this comment

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

yes, but this regionReq wants to ensure the client can get the server's response.

  • only call SendScheduleCommand will send right msg by oc.hbStreams.SendMsg(region, cmd)
  • DispatchFromHeartBeat will not trigger SendScheduleCommand

Otherwise, we can only get the msg when the hbStream's keepalive is triggered, which for this test is no different than sending an error msg.

And the concurrent region heartbeat tests are handled (the purpose of this test) in the below code.

Copy link
Member

Choose a reason for hiding this comment

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

I don't remember what is the purpose of this test. Does it aim to test the concurrent problem or race problem?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, Seems like testing(including race) for concurrent running HandleRegionHeartbeat

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

If the heartbeat process exits earlier, will it still take effect?

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 this part is just like a ping which wants to ensure the connection between the client and server.
So I think the msg of the response is unimportant :)

And I have added some breakpoints to ensure concurrent region heartbeat has been handled.

@HuSharp HuSharp requested a review from nolouch April 2, 2024 05:23
@HuSharp HuSharp requested a review from rleungx April 7, 2024 09:08
@HuSharp
Copy link
Member Author

HuSharp commented Apr 15, 2024

@rleungx @lhy1024 friendly ping :)

@HuSharp
Copy link
Member Author

HuSharp commented May 13, 2024

@rleungx @lhy1024 friendly ping :)

@HuSharp HuSharp closed this May 20, 2024
@HuSharp HuSharp deleted the fix_handle_msg_send branch May 20, 2024 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants