-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
GH-37429: [C++] Add arrow::ipc::StreamDecoder::Reset() #37970
Conversation
|
cpp/src/arrow/ipc/reader.h
Outdated
/// \brief Reset the internal status. | ||
/// | ||
/// You can reuse this decoder for new stream after calling | ||
/// this. For example, you can implement endless decoder with this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I don't think the endless decoder is very useful (why would I want an endless decoder?). Perhaps we can simply remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I'll remove this example.
See #37429 for a use case of the endless decoder. It reads multiple streams with one decoder instance.
FYI: We can implement the use case by using next_required_size()
instead but we need to recreate decoder instances manually:
while (true) {
auto buffer = get_data(decoder->next_required_size());
if (!buffer) {
break;
}
decoder->Consume(buffer);
if (listener->status() == EOS) {
decoder = create_decoder(listener);
}
}
cpp/src/arrow/ipc/reader.cc
Outdated
@@ -2032,6 +2036,11 @@ Status StreamDecoder::Consume(const uint8_t* data, int64_t size) { | |||
Status StreamDecoder::Consume(std::shared_ptr<Buffer> buffer) { | |||
return impl_->Consume(std::move(buffer)); | |||
} | |||
Status StreamDecoder::Reset() { | |||
impl_ = | |||
std::make_unique<StreamDecoderImpl>(std::move(impl_->listener()), impl_->options()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: std::move
on a rvalue is probably a no-op.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry. I'll remove it.
7eb56df
to
55bd8bd
Compare
@kou That's not all: after return from OnEOS() and from OnEOS() at StreamDecoder, we'll back in old MessageReader, but after Reset() call, we've destroyed it. Since old MessageReader hadn't been reseted, MessageReader still in EOS state and will ignore all payload after EOS message. |
You can checkout our temporary workaround here: |
Why do we need to care about |
Because when we got EOS in the middle of payload. So, if we recreate StreamDecoderImpl in Listener::OnEOS(), after exiting Listener::OnEOS we will
|
We can reuse the same StreamDecoder to read multiple streams with this.
55bd8bd
to
bc689ac
Compare
Ah, I understand. |
Looks like truth! |
I'll merge this in a few days if nobody objects it. |
No objection. |
After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit cead3dd. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. It also includes information about 32 possible false positives for unstable benchmarks that are known to sometimes produce them. |
…37970) ### Rationale for this change We can reuse the same StreamDecoder to read multiple streams with this. ### What changes are included in this PR? Add StreamDecoder::Reset(). ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * Closes: apache#37429 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
…37970) ### Rationale for this change We can reuse the same StreamDecoder to read multiple streams with this. ### What changes are included in this PR? Add StreamDecoder::Reset(). ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * Closes: apache#37429 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
Rationale for this change
We can reuse the same StreamDecoder to read multiple streams with this.
What changes are included in this PR?
Add StreamDecoder::Reset().
Are these changes tested?
Yes.
Are there any user-facing changes?
Yes.