Skip to content

Fix Azure InputStream#read method #96034

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

Merged
merged 4 commits into from
May 11, 2023
Merged

Conversation

fcofdez
Copy link
Contributor

@fcofdez fcofdez commented May 11, 2023

No description provided.

@fcofdez fcofdez added >bug :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v8.9.0 labels May 11, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

@elasticsearchmachine
Copy link
Collaborator

Hi @fcofdez, I've created a changelog YAML for you.

Copy link
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

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

LGTM.

@fcofdez fcofdez added v8.8.0 v7.17.11 auto-backport Automatically create backport pull requests when merged labels May 11, 2023
@@ -714,7 +714,14 @@ private ByteBuf copyBuffer(ByteBuffer buffer) {
@Override
public int read() throws IOException {
byte[] b = new byte[1];
return read(b, 0, 1);
var bytesRead = read(b, 0, 1);
if (bytesRead > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it return strictly 1 byte?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it should

Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest then to make the first condition == to surface the issue with exception if more returned (out of paranoia)

Copy link
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

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

LGTM again, but 2 minor comments on the test.

container.writeBlob(blobName, new ByteArrayInputStream(data), data.length, true);
try (var inputStream = container.readBlob(blobName)) {
for (byte blobByte : data) {
assertThat(blobByte, is(equalTo((byte) inputStream.read())));
Copy link
Contributor

Choose a reason for hiding this comment

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

One detail here: can we expand blobByte instead of narrowing the result of inputStream.read()? That would validate the & 0xff works correctly.

Suggested change
assertThat(blobByte, is(equalTo((byte) inputStream.read())));
assertThat((int) blobByte, is(equalTo(inputStream.read())));

for (byte blobByte : data) {
assertThat(blobByte, is(equalTo((byte) inputStream.read())));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add:

assertThat(inputStream.read(), is(equalTo(-1)))

@fcofdez fcofdez merged commit 63e26ad into elastic:main May 11, 2023
@fcofdez
Copy link
Contributor Author

fcofdez commented May 11, 2023

Thanks for the reviews!

@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.8
7.17

fcofdez added a commit to fcofdez/elasticsearch that referenced this pull request May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >bug :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v7.17.11 v8.8.0 v8.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants