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

chore: refactor poll_reserve logic to be a seperate function #7610

Closed

Conversation

mw2000
Copy link
Contributor

@mw2000 mw2000 commented Apr 12, 2024

Separating the poll_reserve logic out into a new function on the ExExHandle level that the manager can call.

Fixes: #7570

@mw2000
Copy link
Contributor Author

mw2000 commented Apr 12, 2024

Ahh just saw #7609 from mattsse. Apologies for the duplicate effort

@mattsse
Copy link
Collaborator

mattsse commented Apr 12, 2024

ah I forgot that there was an issue for this already -.-

do you want to continue this following my docs on #7609?

@onbjerg onbjerg changed the title chore: refactored poll_reserve logic to be a seperate function chore: refactor poll_reserve logic to be a seperate function Apr 13, 2024
@mw2000
Copy link
Contributor Author

mw2000 commented Apr 13, 2024

@mattsse yeah would love to!

@mw2000
Copy link
Contributor Author

mw2000 commented Apr 16, 2024

@mattsse solved most of your Todos. Not the most confident on the PR, but would love more insight/context. Also would love if there's any tests you suggest I can add for this to make it airtight

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

also ptal @shekhirin @onbjerg

crates/exex/src/manager.rs Outdated Show resolved Hide resolved
Comment on lines 313 to 324
// it is a logic error for this to ever underflow since the manager manages the
// notification IDs
let notification_id = exex
.next_notification_id
.checked_sub(self.min_id)
.expect("exex expected notification ID outside the manager's range");
if let Some(notification) = self.buffer.get(notification_id) {
debug!(exex.id, notification_id, "sent notification to exex");
if let Poll::Ready(Err(err)) = exex.send(notification) {
// the channel was closed, which is irrecoverable for the manager
return Poll::Ready(Err(err.into()))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is no longer accurate here, sending should only happen after we ensured there's capacity

Copy link
Member

Choose a reason for hiding this comment

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

yes, we should not send notifications in 2 places in the loop, just the first when a slot in the channel has been reserved is needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now senfing when Poll:Ready(Ok()) is matched

match reserve_result {
Poll::Ready(Ok(())) => {
// try send next notification to exex if we have it
let notification_id = exex.next_notification_id;
Copy link
Collaborator

Choose a reason for hiding this comment

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

not exactly sure about this, the previous logic looks different.

match reserve_result {
Poll::Ready(Ok(())) => {
// try send next notification to exex if we have it
let notification_id = exex.next_notification_id;
Copy link
Member

Choose a reason for hiding this comment

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

this is incorrect, you need to restore the previous logic for getting the notification id - the notification id is not a 1:1 index into the buffer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I changed this so we also don't send the notification twice, and moved previous logic from outside the loop in here.

Comment on lines 90 to 88
/// Sends a slot in the `PollSender` channel and sends the notification if the slot was
/// successfully reserved.
Copy link
Member

Choose a reason for hiding this comment

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

please correct this comment - it just sends the notification, it does not do anything w slots or reservations

crates/exex/src/manager.rs Outdated Show resolved Hide resolved
Comment on lines 281 to 282
for idx in (0..self.exex_handles.len()).rev() {
let mut exex = self.exex_handles.swap_remove(idx);
Copy link
Member

Choose a reason for hiding this comment

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

please format this so it is correctly indented

let _ = self.finished_height.send(Some(finished_height));
}

// only return pending if the buffer is not empty
Copy link
Member

Choose a reason for hiding this comment

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

this returns Poll::Pending if the buffer is empty, so the comment is not accurate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this to returning pending only when it is not empty and Poll:Ready(Ok()) otherwise

@mw2000
Copy link
Contributor Author

mw2000 commented Apr 18, 2024

Hey guys, appreciate the comments. This gives a lot of context, thank you. I'll push an update to this today/tmrw

@mattsse mattsse added A-meta Changes in the contributor workflow and planning A-exex Execution Extensions and removed A-meta Changes in the contributor workflow and planning labels Apr 23, 2024
@onbjerg
Copy link
Member

onbjerg commented Apr 24, 2024

Hey @mw2000, what's the status on this? Something I can help with? 😄

@mw2000
Copy link
Contributor Author

mw2000 commented Apr 25, 2024

@onbjerg Added the changes that you and @mattsse discussed here. I think this one looks better, but I haven't been able to unit test it. Can you suggest what I can do to make sure the implementation is good? I think i understand high level what's happening, but would love to have tests that i can then run my implementation against.

Comment on lines 350 to 364
if !self.buffer.is_empty() {
return Poll::Pending;
} else {
return Poll::Ready(Ok(()));
}
Copy link
Member

@onbjerg onbjerg Apr 25, 2024

Choose a reason for hiding this comment

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

this might immediately return Poll::Ready(Ok(())) once the manager is spawned, since the buffer is empty from the beginning

i think what we want is to have the entire inner body of poll be in a loop {} and only return Poll::Pending if the buffer is not empty. we should never return Poll::Ready(Ok(())) since this terminates the manager

see the comments at the bottom of the manager file in #7609

@github-actions github-actions bot added the S-stale This issue/PR is stale and will close with no further activity label May 18, 2024
@github-actions github-actions bot closed this May 29, 2024
@mattsse mattsse reopened this May 29, 2024
@mattsse mattsse added M-prevent-stale Prevents old inactive issues/PRs from being closed due to inactivity and removed S-stale This issue/PR is stale and will close with no further activity labels May 29, 2024
@mattsse
Copy link
Collaborator

mattsse commented May 29, 2024

reopened because this would be nice to have

@Rjected
Copy link
Member

Rjected commented Jun 5, 2024

hey, I think something went wrong with merging or rebasing, since the diff is now huge, maybe it needs to be merged with main again?

@mw2000
Copy link
Contributor Author

mw2000 commented Jun 5, 2024

@Rjected yeah let me fix that, sorry picked this up after a while

@mw2000 mw2000 force-pushed the mw2000/poll-reserve-to-exexhandle branch 2 times, most recently from 3490c1a to a2f152a Compare June 5, 2024 20:06
@mw2000 mw2000 marked this pull request as draft June 5, 2024 20:07
@mw2000 mw2000 force-pushed the mw2000/poll-reserve-to-exexhandle branch from a2f152a to 217703e Compare June 5, 2024 20:09
@mw2000
Copy link
Contributor Author

mw2000 commented Jun 5, 2024

Fixed, moved this back to draft, apologies for the pings here

@mw2000 mw2000 force-pushed the mw2000/poll-reserve-to-exexhandle branch 4 times, most recently from 96ac3a3 to ef8c7eb Compare June 5, 2024 21:08
@mw2000 mw2000 force-pushed the mw2000/poll-reserve-to-exexhandle branch from ef8c7eb to 4ddf85c Compare June 5, 2024 21:20
@mw2000
Copy link
Contributor Author

mw2000 commented Jun 5, 2024

Opening this back up.

With the progress on the repo since the last time i took a crack at this issue, it looks like I don't need to add much beyond the poll reserve function itself. Feel free to close unmerged if not needed anymore.

@mw2000 mw2000 marked this pull request as ready for review June 5, 2024 21:21
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

ah sorry about this, yeah this is no longer required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exex Execution Extensions M-prevent-stale Prevents old inactive issues/PRs from being closed due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add poll_reserve to ExExHandle
4 participants