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

Refactor delayed API responses #5955

Merged
merged 2 commits into from
Oct 18, 2024
Merged

Refactor delayed API responses #5955

merged 2 commits into from
Oct 18, 2024

Conversation

kozlovic
Copy link
Member

@kozlovic kozlovic commented Oct 2, 2024

This is similar to @neilalexander PR (#5948) but has a slightly different approach. We use the struct to have a next so that we can use a list since the list will be maintained ordered. The for-loop is in one level, as opposed to two, which means that pushing to the IPQ will be "immediately" popped, even if we have a timer initialized and waiting to fire.
The timer is reset (not recreated everytime) only if the added response ends-up being at the head of the list.

Added a test that verifies that it works properly.

Signed-off-by: Ivan Kozlovic [email protected]

@kozlovic kozlovic requested a review from a team as a code owner October 2, 2024 22:10
@kozlovic kozlovic marked this pull request as draft October 2, 2024 22:10
// Check that JetStream is still on. Do not exit the go routine
// since JS can be enabled/disabled. The go routine will exit
// only if server is shutdown.
js := s.getJetStream()
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 check for JS and the raft node quit channel, although working and the test checks that, may be a bit of an overkill. Does it really matter if a delayed response is sent or not after a raft group is shutdown or JS turned off? Again, code is there and test verifies it works, but we may have done without I think.

Copy link
Member

Choose a reason for hiding this comment

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

I think it makes sense that we don't send anything back after the Raft group is stopped, otherwise it might be a signal for the client/application to "try again" rather than just timing out in the rate-limited scenario.

@kozlovic kozlovic marked this pull request as ready for review October 3, 2024 15:35
This is similar to @neilalexander PR (#5948) but has a slightly
different approach. We use the struct to have a `next` so that
we can use a list since the list will be maintained ordered.
The for-loop is in one level, as opposed to two, which means
that pushing to the IPQ will be "immediately" popped, even if
we have a timer initialized and waiting to fire.
The timer is reset (not recreated everytime) only if the added
response ends-up being at the head of the list.

Added a test that verifies that it works properly.

Signed-off-by: Ivan Kozlovic <[email protected]>
@neilalexander
Copy link
Member

Rebased on top of main.

Copy link
Member

@neilalexander neilalexander left a comment

Choose a reason for hiding this comment

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

Overall looks good!

r *delayedAPIResponse
tm = time.NewTimer(time.Hour)
)
setup := func() {
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit but I suggest we call this function next instead of setup, and perhaps add a comment that r is the next response we're expecting the timer to fire for, updated only by calling next again.

Copy link
Member

Choose a reason for hiding this comment

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

In fact I've just done this myself in a new commit.

Copy link
Member Author

Choose a reason for hiding this comment

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

In one of my attempts, I had named it next(), so I would agree with that ;-).

Signed-off-by: Neil Twigg <[email protected]>
@derekcollison
Copy link
Member

This one ready?

Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

LGTM

@derekcollison derekcollison merged commit c4d4915 into main Oct 18, 2024
5 checks passed
@derekcollison derekcollison deleted the delayed_api_responses branch October 18, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants