Skip to content

Commit 0f335ac

Browse files
author
Ali Beyad
committed
Removes legacy format in RepositoryData
1 parent 58d6b9d commit 0f335ac

File tree

3 files changed

+27
-47
lines changed

3 files changed

+27
-47
lines changed

core/src/main/java/org/elasticsearch/repositories/RepositoryData.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,17 @@ public final class RepositoryData implements ToXContent {
5858
* The snapshots that each index belongs to.
5959
*/
6060
private final Map<IndexId, Set<SnapshotId>> indexSnapshots;
61-
/**
62-
* Whether the repository data is in the legacy (pre 5.0) format
63-
*/
64-
private final boolean legacyFormat;
6561

66-
private RepositoryData(List<SnapshotId> snapshotIds, Map<IndexId, Set<SnapshotId>> indexSnapshots, boolean legacyFormat) {
62+
public RepositoryData(List<SnapshotId> snapshotIds, Map<IndexId, Set<SnapshotId>> indexSnapshots) {
6763
this.snapshotIds = Collections.unmodifiableList(snapshotIds);
6864
this.indices = Collections.unmodifiableMap(indexSnapshots.keySet()
6965
.stream()
7066
.collect(Collectors.toMap(IndexId::getName, Function.identity())));
7167
this.indexSnapshots = Collections.unmodifiableMap(indexSnapshots);
72-
this.legacyFormat = legacyFormat;
73-
}
74-
75-
public RepositoryData(List<SnapshotId> snapshotIds, Map<IndexId, Set<SnapshotId>> indexSnapshots) {
76-
this(snapshotIds, indexSnapshots, false);
7768
}
7869

7970
protected RepositoryData copy() {
80-
return new RepositoryData(snapshotIds, indexSnapshots, legacyFormat);
71+
return new RepositoryData(snapshotIds, indexSnapshots);
8172
}
8273

8374
/**
@@ -94,13 +85,6 @@ public Map<String, IndexId> getIndices() {
9485
return indices;
9586
}
9687

97-
/**
98-
* Returns whether the repository data format is in the legacy (pre 5.0) format or not
99-
*/
100-
public boolean isLegacyFormat() {
101-
return legacyFormat;
102-
}
103-
10488
/**
10589
* Add a snapshot and its indices to the repository; returns a new instance. If the snapshot
10690
* already exists in the repository data, this method throws an IllegalArgumentException.
@@ -272,7 +256,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
272256
return builder;
273257
}
274258

275-
public static RepositoryData fromXContent(final XContentParser parser, boolean legacyFormat) throws IOException {
259+
public static RepositoryData fromXContent(final XContentParser parser) throws IOException {
276260
List<SnapshotId> snapshots = new ArrayList<>();
277261
Map<IndexId, Set<SnapshotId>> indexSnapshots = new HashMap<>();
278262
if (parser.nextToken() == XContentParser.Token.START_OBJECT) {
@@ -321,7 +305,7 @@ public static RepositoryData fromXContent(final XContentParser parser, boolean l
321305
} else {
322306
throw new ElasticsearchParseException("start object expected");
323307
}
324-
return new RepositoryData(snapshots, indexSnapshots, legacyFormat);
308+
return new RepositoryData(snapshots, indexSnapshots);
325309
}
326310

327311
}

core/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

core/src/test/java/org/elasticsearch/repositories/RepositoryDataTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void testXContent() throws IOException {
5757
XContentBuilder builder = JsonXContent.contentBuilder();
5858
repositoryData.toXContent(builder, ToXContent.EMPTY_PARAMS);
5959
XContentParser parser = XContentType.JSON.xContent().createParser(builder.bytes());
60-
assertEquals(repositoryData, RepositoryData.fromXContent(parser, true));
60+
assertEquals(repositoryData, RepositoryData.fromXContent(parser));
6161
}
6262

6363
public void testAddSnapshots() {

0 commit comments

Comments
 (0)