|
50 | 50 | import org.elasticsearch.common.collect.Tuple;
|
51 | 51 | import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
52 | 52 | import org.elasticsearch.common.compress.NotXContentException;
|
| 53 | +import org.elasticsearch.common.io.Streams; |
53 | 54 | import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
54 | 55 | import org.elasticsearch.common.lucene.Lucene;
|
55 | 56 | import org.elasticsearch.common.lucene.store.InputStreamIndexInput;
|
|
61 | 62 | import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
62 | 63 | import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
63 | 64 | import org.elasticsearch.common.xcontent.XContentFactory;
|
64 |
| -import org.elasticsearch.common.xcontent.XContentHelper; |
65 | 65 | import org.elasticsearch.common.xcontent.XContentParser;
|
66 | 66 | import org.elasticsearch.common.xcontent.XContentType;
|
67 |
| -import org.elasticsearch.core.internal.io.Streams; |
68 | 67 | import org.elasticsearch.index.mapper.MapperService;
|
69 | 68 | import org.elasticsearch.index.shard.ShardId;
|
70 | 69 | import org.elasticsearch.index.snapshots.IndexShardRestoreFailedException;
|
@@ -645,32 +644,23 @@ public RepositoryData getRepositoryData() {
|
645 | 644 | final String snapshotsIndexBlobName = INDEX_FILE_PREFIX + Long.toString(indexGen);
|
646 | 645 |
|
647 | 646 | RepositoryData repositoryData;
|
648 |
| - try (InputStream blob = blobContainer().readBlob(snapshotsIndexBlobName)) { |
649 |
| - BytesStreamOutput out = new BytesStreamOutput(); |
650 |
| - Streams.copy(blob, out); |
651 |
| - // EMPTY is safe here because RepositoryData#fromXContent calls namedObject |
652 |
| - try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, |
653 |
| - LoggingDeprecationHandler.INSTANCE, out.bytes(), XContentType.JSON)) { |
654 |
| - repositoryData = RepositoryData.snapshotsFromXContent(parser, indexGen); |
655 |
| - } catch (NotXContentException e) { |
656 |
| - logger.warn("[{}] index blob is not valid x-content [{} bytes]", snapshotsIndexBlobName, out.bytes().length()); |
657 |
| - throw e; |
658 |
| - } |
| 647 | + // EMPTY is safe here because RepositoryData#fromXContent calls namedObject |
| 648 | + try (InputStream blob = blobContainer().readBlob(snapshotsIndexBlobName); |
| 649 | + XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, |
| 650 | + LoggingDeprecationHandler.INSTANCE, blob)) { |
| 651 | + repositoryData = RepositoryData.snapshotsFromXContent(parser, indexGen); |
659 | 652 | }
|
660 | 653 |
|
661 | 654 | // now load the incompatible snapshot ids, if they exist
|
662 |
| - try (InputStream blob = blobContainer().readBlob(INCOMPATIBLE_SNAPSHOTS_BLOB)) { |
663 |
| - BytesStreamOutput out = new BytesStreamOutput(); |
664 |
| - Streams.copy(blob, out); |
665 |
| - try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, |
666 |
| - LoggingDeprecationHandler.INSTANCE, out.bytes(), XContentType.JSON)) { |
667 |
| - repositoryData = repositoryData.incompatibleSnapshotsFromXContent(parser); |
668 |
| - } |
| 655 | + try (InputStream blob = blobContainer().readBlob(INCOMPATIBLE_SNAPSHOTS_BLOB); |
| 656 | + XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, |
| 657 | + LoggingDeprecationHandler.INSTANCE, blob)) { |
| 658 | + repositoryData = repositoryData.incompatibleSnapshotsFromXContent(parser); |
669 | 659 | } catch (NoSuchFileException e) {
|
670 | 660 | if (isReadOnly()) {
|
671 | 661 | logger.debug("[{}] Incompatible snapshots blob [{}] does not exist, the likely " +
|
672 |
| - "reason is that there are no incompatible snapshots in the repository", |
673 |
| - metadata.name(), INCOMPATIBLE_SNAPSHOTS_BLOB); |
| 662 | + "reason is that there are no incompatible snapshots in the repository", |
| 663 | + metadata.name(), INCOMPATIBLE_SNAPSHOTS_BLOB); |
674 | 664 | } else {
|
675 | 665 | // write an empty incompatible-snapshots blob - we do this so that there
|
676 | 666 | // is a blob present, which helps speed up some cloud-based repositories
|
@@ -778,11 +768,7 @@ long latestIndexBlobId() throws IOException {
|
778 | 768 |
|
779 | 769 | // package private for testing
|
780 | 770 | long readSnapshotIndexLatestBlob() throws IOException {
|
781 |
| - try (InputStream blob = blobContainer().readBlob(INDEX_LATEST_BLOB)) { |
782 |
| - BytesStreamOutput out = new BytesStreamOutput(); |
783 |
| - Streams.copy(blob, out); |
784 |
| - return Numbers.bytesToLong(out.bytes().toBytesRef()); |
785 |
| - } |
| 771 | + return Numbers.bytesToLong(Streams.readFully(blobContainer().readBlob(INDEX_LATEST_BLOB)).toBytesRef()); |
786 | 772 | }
|
787 | 773 |
|
788 | 774 | private long listBlobsToGetLatestIndexId() throws IOException {
|
|
0 commit comments