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

Implement fallible streams for FlightClient::do_put #3464

Merged
merged 8 commits into from Feb 23, 2023

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jan 5, 2023

NOTE

This is a WIP -- I want feedback on the approach before I spent more time polishing it up

Which issue does this PR close?

Part of #3462

Rationale for this change

Support sending a stream of Results to a server, aborting the connection if the input stream has an error

This is very likely what would happen if you had a execution system producing RecordBatches

What changes are included in this PR?

  1. Change signature of FlightClient::do_put to accept a stream of Result
  2. Implement error tests

Planned follow on PR

  • Give the same treatment for do_exchange

Are there any user-facing changes?

signature is changed

@github-actions github-actions bot added the arrow-flight Changes to the arrow-flight crate label Jan 5, 2023
arrow-flight/src/client.rs Outdated Show resolved Hide resolved
done: bool,
}

impl SplitStream {
Copy link
Contributor

@Dandandan Dandandan Jan 30, 2023

Choose a reason for hiding this comment

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

Instead of splitting - this stream can stop whenever the first error appears and keep that first error if any, so it can be retrieved.

}

/// returns only the OK responses from a stream of results
struct SplitStreamErr {
Copy link
Contributor

@Dandandan Dandandan Jan 31, 2023

Choose a reason for hiding this comment

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


struct FallibleStream {
    input_stream: BoxStream<'static, Result<FlightData>>,
    err: Option<FlightError>,
}

impl Stream for FallibleStream {
    type Item = FlightData;

    fn poll_next(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<Option<Self::Item>> {
        match self.input_stream.poll_next_unpin(cx) {
            std::task::Poll::Ready(res) => match res {
                Some(data) => match data {
                    Ok(ok) => std::task::Poll::Ready(Some(ok)),
                    Err(e) => {
                        self.err =  Some(e);
                        std::task::Poll::Ready(None)
                    },
                } ,
                None => std::task::Poll::Ready(None),
            },
            std::task::Poll::Pending => std::task::Poll::Pending,
        }

    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes sense @Dandandan 👍 thank you for the suggestion

@github-actions github-actions bot added the arrow Changes to the arrow crate label Feb 1, 2023

// input stream to client sends good FlightData followed by an error
let input_flight_data = test_flight_data().await;
let input_stream = futures::stream::iter(input_flight_data.clone())
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 added these two tests to show what is going on -- aka that the error provided to the client do_put call need to get to the returned stream even though the error did not come from the server

/// The setup of copying errors to result stream looks like this:
///
/// ```text
/// input: ---> (Stream of Result<FlightData>) ---- (Stream of FlightData) ---- network ----> Server
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 made some ascii art to explain what is happening here

@alamb alamb marked this pull request as ready for review February 1, 2023 21:47
@alamb
Copy link
Contributor Author

alamb commented Feb 1, 2023

I implemented the approach that @Dandandan suggested. I like it much better as I think it is clearer of what is going on. I also added some ASCII art and tests.

@viirya and @tustvold are you ok with this solution? If so I will apply the same treatment to do_exchange as well

@alamb
Copy link
Contributor Author

alamb commented Feb 8, 2023

Any thoughts @tustvold ? Is this approach ok with you?

@tustvold
Copy link
Contributor

I intend to review this tomorrow, I think there might be a way to make it simpler, making use of a oneshot instead of a mutex, or something

@tustvold
Copy link
Contributor

I took the liberty of pushing a simplified version of this in 914948b PTAL

@alamb
Copy link
Contributor Author

alamb commented Feb 13, 2023

I took the liberty of pushing a simplified version of this in 914948b PTAL

Well, it is less code, though also less comments 🤷 Seems good to me other than the possibly theunwrap 914948b#r100468130

Thank you

@tustvold tustvold added the api-change Changes to the arrow API label Feb 23, 2023
@tustvold tustvold merged commit 0373a9d into apache:master Feb 23, 2023
@ursabot
Copy link

ursabot commented Feb 23, 2023

Benchmark runs are scheduled for baseline = 47e4b61 and contender = 0373a9d. 0373a9d is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-change Changes to the arrow API 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.

None yet

5 participants