Skip to content

Conversation

@jasontedor
Copy link
Member

This is a follow-up to #23941. Currently there are a number of complexities related to compression. The raw DeflaterOutputStream must be closed prior to sending bytes to ensure that EOS bytes are written. But the underlying ReleasableBytesStreamOutput cannot be closed until the bytes are sent to ensure that the bytes are not reused.

Right now we have three different stream references hanging around in TCPTransport to handle this complexity. This commit introduces CompressibleBytesOutputStream to be one stream implemenation that will behave properly with or without compression enabled.

This is a backport of #24927 to 5.6.

Closes #27525

This is a follow-up to elastic#23941. Currently there are a number of
complexities related to compression. The raw DeflaterOutputStream must
be closed prior to sending bytes to ensure that EOS bytes are written.
But the underlying ReleasableBytesStreamOutput cannot be closed until
the bytes are sent to ensure that the bytes are not reused.

Right now we have three different stream references hanging around in
TCPTransport to handle this complexity. This commit introduces
CompressibleBytesOutputStream to be one stream implemenation that will
behave properly with or without compression enabled.
@jasontedor
Copy link
Member Author

To be clear about #27525, the issue there has nothing to do with compressible streams but rather handling closing of the releasable bytes output stream when an exception is thrown before we attach the send listener that would otherwise close the stream. The reason that #24927 addresses this though is due to how it simplifies closing of the releasable bytes output stream whether or not the send listener is attached.

Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

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

I left some questions

}

@Override
public void reset() throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

can't we just throw UOE?

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 practice it probably does not matter, I think we will never call reset on these streams.

If the stream is not compressed, then resetting is fine.

If the stream is compressed, then we would already throw an unsupported operation exception (from OutputStreamStreamOutput#reset).

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 it would be good to be consistent and always throw

Copy link
Member Author

Choose a reason for hiding this comment

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

@s1monw I opened #27564.

public void close() {
if (stream == bytesStreamOutput) {
assert shouldCompress == false : "If the streams are the same we should not be compressing";
IOUtils.closeWhileHandlingException(stream);
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we not bubble up the exception here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is an artifact of the compressible bytes output stream implementing releasable which does not declare any checked exceptions. I think we should remove this and let these bubble up as you say. I opened: #27542

Copy link
Member Author

Choose a reason for hiding this comment

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

I integrated #27542, are you good with this PR now @s1monw?

Copy link
Contributor

Choose a reason for hiding this comment

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

this PR still doesn't bubble up exceptions?!

Copy link
Member Author

Choose a reason for hiding this comment

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

@s1monw I will pull #27542 in when I pull this PR in (I did it this way because this code already exists in 6.0/6.1/6.x/master and this PR is targeting 5.6 only). So: separate PRs to make the changes you are requesting to compressible bytes output stream in all branches.

Copy link
Contributor

@Tim-Brooks Tim-Brooks left a comment

Choose a reason for hiding this comment

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

LGTM

public void close() {
if (stream == bytesStreamOutput) {
assert shouldCompress == false : "If the streams are the same we should not be compressing";
IOUtils.closeWhileHandlingException(stream);
Copy link
Contributor

Choose a reason for hiding this comment

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

this PR still doesn't bubble up exceptions?!

@jasontedor jasontedor requested a review from s1monw November 29, 2017 01:33
Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

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

thanks for the extra iters

@jasontedor jasontedor merged commit de6ed75 into elastic:5.6 Nov 29, 2017
@jasontedor jasontedor deleted the backport-24927 branch November 29, 2017 14:15
@jasontedor
Copy link
Member Author

I pushed this change and backported the other changes that we discussed:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Distributed Coordination/Network Http and internode communication implementations v5.6.5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants