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 to share code between do_put and do_exchange calls #5728

Merged
merged 1 commit into from
May 7, 2024

Conversation

opensourcegeek
Copy link
Contributor

Which issue does this PR close?

Extends on work done for #3462 - internal refactor

Rationale for this change

Internal refactor to allow sharing of the code between do_put and do_exchange methods in arrow-flight

What changes are included in this PR?

Refactored the poll_fn repetitions to use separate fallible streams for request and response streams.

Are there any user-facing changes?

No

@github-actions github-actions bot added arrow Changes to the arrow crate arrow-flight Changes to the arrow-flight crate labels May 6, 2024
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @opensourcegeek -- this looks like nice progress

@@ -704,3 +679,75 @@ impl FlightClient {
request
}
}

struct FallibleRequestStream {
Copy link
Contributor

Choose a reason for hiding this comment

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

looks good to me 👍

Perhaps we could add some comments about what this struct is doing and what it is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did refactor it so that this is generic and not tied to request stream itself, is it worth moving this bit of code to some internal_utils module? Happy to leave it where it is atm

fn poll_next(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<Option<Self::Item>> {
let pinned = self.get_mut();
let mut request_streams = pinned.request_streams.as_mut();
match request_streams.poll_next_unpin(cx) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can avoid a level of nesting using the ready! macro here

so like

match ready!(request_streams.poll_next_unpin(cx) {
  Some(Ok(data)) => ...
  Some(Err(e)) => ...
  None => ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did expand the macro from original code for my own understanding, I'll tidy it up. Thanks

return Poll::Ready(Some(Err(err)));
};

match pinned.response_streams.poll_next_unpin(cx) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise here, calling ready!() can probably simplify this a bit

@opensourcegeek opensourcegeek force-pushed the feat/3462-refactor branch 3 times, most recently from 6a8fc13 to 3806b5a Compare May 7, 2024 05:39
@opensourcegeek opensourcegeek marked this pull request as ready for review May 7, 2024 05:40
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @opensourcegeek -- I think this is a very nice improvement to me. 🙏

match ready!(request_streams.poll_next_unpin(cx)) {
Some(Ok(data)) => Poll::Ready(Some(data)),
Some(Err(e)) => {
// unwrap() here is safe, ownership of sender will
Copy link
Contributor

Choose a reason for hiding this comment

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

Another potential improvement might be to do something like

if let Some(sender) = pinned.sender.take() {
  sender.send();
}

And that way avoid a panic

However, I see this unwrap is simply moved here from elsewhere in the PR so I think we can improve it in the future

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good point, it would've taken less time to swap the code than writing the justification comments.

@alamb alamb merged commit e3f1c96 into apache:master May 7, 2024
12 checks passed
@@ -704,3 +674,99 @@ impl FlightClient {
request
}
}

/// Wrapper around fallible stream such that when
Copy link
Contributor

Choose a reason for hiding this comment

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

BTW I especially appreciate the understandable comments in this PR 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate arrow-flight Changes to the arrow-flight crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants