@@ -344,7 +344,6 @@ public void initializeSnapshot(SnapshotId snapshotId, List<IndexId> indices, Met
344344 // so if the repository data is of the older format, populate it with the indices entries
345345 // so we know which indices of snapshots have blob ids in the older format.
346346 private RepositoryData upgradeRepositoryData (final RepositoryData repositoryData ) throws IOException {
347- assert repositoryData .isLegacyFormat (); // should not be called on non-legacy repositories
348347 final Map <IndexId , Set <SnapshotId >> indexToSnapshots = new HashMap <>();
349348 for (final SnapshotId snapshotId : repositoryData .getSnapshotIds ()) {
350349 final SnapshotInfo snapshotInfo ;
@@ -689,8 +688,28 @@ public void endVerification(String seed) {
689688 @ Override
690689 public RepositoryData getRepositoryData () {
691690 try {
692- RepositoryData repositoryData = readIndexGen ();
693- if (repositoryData .isLegacyFormat ()) {
691+ final long indexGen = latestIndexBlobId ();
692+ final String snapshotsIndexBlobName ;
693+ final boolean legacyFormat ;
694+ if (indexGen == -1 ) {
695+ // index-N file doesn't exist, either its a fresh repository, or its in the
696+ // old format, so look for the older index file before returning an empty list
697+ snapshotsIndexBlobName = SNAPSHOTS_FILE ;
698+ legacyFormat = true ;
699+ } else {
700+ snapshotsIndexBlobName = INDEX_FILE_PREFIX + Long .toString (indexGen );
701+ legacyFormat = false ;
702+ }
703+
704+ RepositoryData repositoryData ;
705+ try (InputStream blob = snapshotsBlobContainer .readBlob (snapshotsIndexBlobName )) {
706+ BytesStreamOutput out = new BytesStreamOutput ();
707+ Streams .copy (blob , out );
708+ try (XContentParser parser = XContentHelper .createParser (out .bytes ())) {
709+ repositoryData = RepositoryData .fromXContent (parser );
710+ }
711+ }
712+ if (legacyFormat ) {
694713 // pre 5.0 repository data needs to be updated to include the indices
695714 repositoryData = upgradeRepositoryData (repositoryData );
696715 }
@@ -755,29 +774,6 @@ protected void writeIndexGen(final RepositoryData repositoryData) throws IOExcep
755774 writeAtomic (INDEX_LATEST_BLOB , genBytes );
756775 }
757776
758- RepositoryData readIndexGen () throws IOException {
759- final long indexGen = latestIndexBlobId ();
760- final String snapshotsIndexBlobName ;
761- final boolean legacyFormat ;
762- if (indexGen == -1 ) {
763- // index-N file doesn't exist, either its a fresh repository, or its in the
764- // old format, so look for the older index file before returning an empty list
765- snapshotsIndexBlobName = SNAPSHOTS_FILE ;
766- legacyFormat = true ;
767- } else {
768- snapshotsIndexBlobName = INDEX_FILE_PREFIX + Long .toString (indexGen );
769- legacyFormat = false ;
770- }
771-
772- try (InputStream blob = snapshotsBlobContainer .readBlob (snapshotsIndexBlobName )) {
773- BytesStreamOutput out = new BytesStreamOutput ();
774- Streams .copy (blob , out );
775- try (XContentParser parser = XContentHelper .createParser (out .bytes ())) {
776- return RepositoryData .fromXContent (parser , legacyFormat );
777- }
778- }
779- }
780-
781777 /**
782778 * Get the latest snapshot index blob id. Snapshot index blobs are named index-N, where N is
783779 * the next version number from when the index blob was written. Each individual index-N blob is
0 commit comments