|
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;
|
|
60 | 61 | import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
61 | 62 | import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
62 | 63 | import org.elasticsearch.common.xcontent.XContentFactory;
|
63 |
| -import org.elasticsearch.common.xcontent.XContentHelper; |
64 | 64 | import org.elasticsearch.common.xcontent.XContentParser;
|
65 | 65 | import org.elasticsearch.common.xcontent.XContentType;
|
66 |
| -import org.elasticsearch.core.internal.io.Streams; |
67 | 66 | import org.elasticsearch.index.mapper.MapperService;
|
68 | 67 | import org.elasticsearch.index.shard.ShardId;
|
69 | 68 | import org.elasticsearch.index.snapshots.IndexShardRestoreFailedException;
|
@@ -671,32 +670,23 @@ public RepositoryData getRepositoryData() {
|
671 | 670 | final String snapshotsIndexBlobName = INDEX_FILE_PREFIX + Long.toString(indexGen);
|
672 | 671 |
|
673 | 672 | RepositoryData repositoryData;
|
674 |
| - try (InputStream blob = blobContainer().readBlob(snapshotsIndexBlobName)) { |
675 |
| - BytesStreamOutput out = new BytesStreamOutput(); |
676 |
| - Streams.copy(blob, out); |
677 |
| - // EMPTY is safe here because RepositoryData#fromXContent calls namedObject |
678 |
| - try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, |
679 |
| - LoggingDeprecationHandler.INSTANCE, out.bytes(), XContentType.JSON)) { |
680 |
| - repositoryData = RepositoryData.snapshotsFromXContent(parser, indexGen); |
681 |
| - } catch (NotXContentException e) { |
682 |
| - logger.warn("[{}] index blob is not valid x-content [{} bytes]", snapshotsIndexBlobName, out.bytes().length()); |
683 |
| - throw e; |
684 |
| - } |
| 673 | + // EMPTY is safe here because RepositoryData#fromXContent calls namedObject |
| 674 | + try (InputStream blob = blobContainer().readBlob(snapshotsIndexBlobName); |
| 675 | + XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, |
| 676 | + LoggingDeprecationHandler.INSTANCE, blob)) { |
| 677 | + repositoryData = RepositoryData.snapshotsFromXContent(parser, indexGen); |
685 | 678 | }
|
686 | 679 |
|
687 | 680 | // now load the incompatible snapshot ids, if they exist
|
688 |
| - try (InputStream blob = blobContainer().readBlob(INCOMPATIBLE_SNAPSHOTS_BLOB)) { |
689 |
| - BytesStreamOutput out = new BytesStreamOutput(); |
690 |
| - Streams.copy(blob, out); |
691 |
| - try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, |
692 |
| - LoggingDeprecationHandler.INSTANCE, out.bytes(), XContentType.JSON)) { |
693 |
| - repositoryData = repositoryData.incompatibleSnapshotsFromXContent(parser); |
694 |
| - } |
| 681 | + try (InputStream blob = blobContainer().readBlob(INCOMPATIBLE_SNAPSHOTS_BLOB); |
| 682 | + XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, |
| 683 | + LoggingDeprecationHandler.INSTANCE, blob)) { |
| 684 | + repositoryData = repositoryData.incompatibleSnapshotsFromXContent(parser); |
695 | 685 | } catch (NoSuchFileException e) {
|
696 | 686 | if (isReadOnly()) {
|
697 | 687 | logger.debug("[{}] Incompatible snapshots blob [{}] does not exist, the likely " +
|
698 |
| - "reason is that there are no incompatible snapshots in the repository", |
699 |
| - metadata.name(), INCOMPATIBLE_SNAPSHOTS_BLOB); |
| 688 | + "reason is that there are no incompatible snapshots in the repository", |
| 689 | + metadata.name(), INCOMPATIBLE_SNAPSHOTS_BLOB); |
700 | 690 | } else {
|
701 | 691 | // write an empty incompatible-snapshots blob - we do this so that there
|
702 | 692 | // is a blob present, which helps speed up some cloud-based repositories
|
@@ -804,11 +794,7 @@ long latestIndexBlobId() throws IOException {
|
804 | 794 |
|
805 | 795 | // package private for testing
|
806 | 796 | long readSnapshotIndexLatestBlob() throws IOException {
|
807 |
| - try (InputStream blob = blobContainer().readBlob(INDEX_LATEST_BLOB)) { |
808 |
| - BytesStreamOutput out = new BytesStreamOutput(); |
809 |
| - Streams.copy(blob, out); |
810 |
| - return Numbers.bytesToLong(out.bytes().toBytesRef()); |
811 |
| - } |
| 797 | + return Numbers.bytesToLong(Streams.readFully(blobContainer().readBlob(INDEX_LATEST_BLOB)).toBytesRef()); |
812 | 798 | }
|
813 | 799 |
|
814 | 800 | private long listBlobsToGetLatestIndexId() throws IOException {
|
|
0 commit comments