-
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
Merged
original-brownbear
merged 4 commits into
elastic:master
from
original-brownbear:dry-up-inputstream-to-bytesreference
Jul 2, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d07e40b
Dry up Reading InputStream to BytesReference
original-brownbear 6464f34
fix import
original-brownbear 083ca36
Merge remote-tracking branch 'elastic/master' into dry-up-inputstream…
original-brownbear caace70
CR: remove senseless copying
original-brownbear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ | |
import org.elasticsearch.common.collect.Tuple; | ||
import org.elasticsearch.common.component.AbstractLifecycleComponent; | ||
import org.elasticsearch.common.compress.NotXContentException; | ||
import org.elasticsearch.common.io.Streams; | ||
import org.elasticsearch.common.io.stream.BytesStreamOutput; | ||
import org.elasticsearch.common.lucene.Lucene; | ||
import org.elasticsearch.common.lucene.store.InputStreamIndexInput; | ||
|
@@ -61,10 +62,8 @@ | |
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.common.xcontent.XContentFactory; | ||
import org.elasticsearch.common.xcontent.XContentHelper; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.core.internal.io.Streams; | ||
import org.elasticsearch.index.mapper.MapperService; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.index.snapshots.IndexShardRestoreFailedException; | ||
|
@@ -645,32 +644,23 @@ public RepositoryData getRepositoryData() { | |
final String snapshotsIndexBlobName = INDEX_FILE_PREFIX + Long.toString(indexGen); | ||
|
||
RepositoryData repositoryData; | ||
try (InputStream blob = blobContainer().readBlob(snapshotsIndexBlobName)) { | ||
BytesStreamOutput out = new BytesStreamOutput(); | ||
Streams.copy(blob, out); | ||
// EMPTY is safe here because RepositoryData#fromXContent calls namedObject | ||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, | ||
LoggingDeprecationHandler.INSTANCE, out.bytes(), XContentType.JSON)) { | ||
repositoryData = RepositoryData.snapshotsFromXContent(parser, indexGen); | ||
} catch (NotXContentException e) { | ||
logger.warn("[{}] index blob is not valid x-content [{} bytes]", snapshotsIndexBlobName, out.bytes().length()); | ||
throw e; | ||
} | ||
// EMPTY is safe here because RepositoryData#fromXContent calls namedObject | ||
try (InputStream blob = blobContainer().readBlob(snapshotsIndexBlobName); | ||
XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, | ||
LoggingDeprecationHandler.INSTANCE, blob)) { | ||
repositoryData = RepositoryData.snapshotsFromXContent(parser, indexGen); | ||
} | ||
|
||
// now load the incompatible snapshot ids, if they exist | ||
try (InputStream blob = blobContainer().readBlob(INCOMPATIBLE_SNAPSHOTS_BLOB)) { | ||
BytesStreamOutput out = new BytesStreamOutput(); | ||
Streams.copy(blob, out); | ||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, | ||
LoggingDeprecationHandler.INSTANCE, out.bytes(), XContentType.JSON)) { | ||
repositoryData = repositoryData.incompatibleSnapshotsFromXContent(parser); | ||
} | ||
try (InputStream blob = blobContainer().readBlob(INCOMPATIBLE_SNAPSHOTS_BLOB); | ||
XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, | ||
LoggingDeprecationHandler.INSTANCE, blob)) { | ||
repositoryData = repositoryData.incompatibleSnapshotsFromXContent(parser); | ||
} catch (NoSuchFileException e) { | ||
if (isReadOnly()) { | ||
logger.debug("[{}] Incompatible snapshots blob [{}] does not exist, the likely " + | ||
"reason is that there are no incompatible snapshots in the repository", | ||
metadata.name(), INCOMPATIBLE_SNAPSHOTS_BLOB); | ||
"reason is that there are no incompatible snapshots in the repository", | ||
metadata.name(), INCOMPATIBLE_SNAPSHOTS_BLOB); | ||
} else { | ||
// write an empty incompatible-snapshots blob - we do this so that there | ||
// is a blob present, which helps speed up some cloud-based repositories | ||
|
@@ -778,11 +768,7 @@ long latestIndexBlobId() throws IOException { | |
|
||
// package private for testing | ||
long readSnapshotIndexLatestBlob() throws IOException { | ||
try (InputStream blob = blobContainer().readBlob(INDEX_LATEST_BLOB)) { | ||
BytesStreamOutput out = new BytesStreamOutput(); | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. We expect this file to be very small so using |
||
} | ||
|
||
private long listBlobsToGetLatestIndexId() throws IOException { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.