-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Dry up inputstream to bytesreference #43675
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
Dry up inputstream to bytesreference #43675
Conversation
original-brownbear
commented
Jun 27, 2019
- Dry up spots where we use the same pattern to get from an InputStream to a BytesReferences
* Dry up spots where we use the same pattern to get from an InputStream to a BytesReferences
Pinging @elastic/es-core-infra |
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.
Nice clean up, I left some comments
throw e; | ||
} | ||
// EMPTY is safe here because RepositoryData#fromXContent calls namedObject | ||
final BytesReference out = Streams.readFully(blobContainer().readBlob(snapshotsIndexBlobName)); |
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.
I don't think we need to fully read the blob here. Instead we could pass the InputStream directly to the XContentParser and let the blob containter bufferizes the reads?
repositoryData = repositoryData.incompatibleSnapshotsFromXContent(parser); | ||
} | ||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, | ||
Streams.readFully(blobContainer().readBlob(INCOMPATIBLE_SNAPSHOTS_BLOB)), XContentType.JSON)) { |
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.
Same here
Streams.copy(blob, out); | ||
return Numbers.bytesToLong(out.bytes().toBytesRef()); | ||
} | ||
return Numbers.bytesToLong(Streams.readFully(blobContainer().readBlob(INDEX_LATEST_BLOB)).toBytesRef()); |
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.
We expect this file to be very small so using Streams.readFully()
can makes sense here.
out.bytes(), XContentType.JSON)) { | ||
repositoryData = RepositoryData.snapshotsFromXContent(parser, latestGen); | ||
} | ||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, |
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.
Same here
Thanks @tlrx I moved to directly deserializing in the spots you pointed out now :) |
server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java
Show resolved
Hide resolved
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.
LGTM
Jenkins run elasticsearch-ci/packaging-sample |
Jenkins run elasticsearch-ci/2 |
thanks @tlrx ! (packaging sample is just red because of the build stats cluster being down -> merging) |
* Dry up Reading InputStream to BytesReference * Dry up spots where we use the same pattern to get from an InputStream to a BytesReferences