From 5dc0bc1119e3970df380a85278ea85cffc13121e Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Sat, 9 Nov 2019 16:49:34 +0100 Subject: [PATCH 1/2] Remove Broken BwC Assertion in RepositoryData This assertion doesn't actually work, we don't have any guards against setting up the actual `ShardGenerations` object upstream in `SnapshotsService` that makes this work. The reason this didn't fail in BwC tests was that in most cases BwC runs continue to run with an old version master in the 2/3 upgraded case so a situation where the master and one data node are upgraded and put a generation into the generations object didn't come up. --- .../java/org/elasticsearch/repositories/RepositoryData.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/repositories/RepositoryData.java b/server/src/main/java/org/elasticsearch/repositories/RepositoryData.java index 8589d2efdfc6d..24538c2236fbb 100644 --- a/server/src/main/java/org/elasticsearch/repositories/RepositoryData.java +++ b/server/src/main/java/org/elasticsearch/repositories/RepositoryData.java @@ -315,8 +315,6 @@ public List resolveNewIndices(final List indicesToResolve) { * Writes the snapshots metadata and the related indices metadata to x-content. */ public XContentBuilder snapshotsToXContent(final XContentBuilder builder, final boolean shouldWriteShardGens) throws IOException { - assert shouldWriteShardGens || shardGenerations.indices().isEmpty() : - "Should not build shard generations in BwC mode but saw generations [" + shardGenerations + "]"; builder.startObject(); // write the snapshots list From ea387acdf1a2936d2a14d568823855d1793cbd69 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Mon, 11 Nov 2019 15:33:10 +0100 Subject: [PATCH 2/2] CR: no gens if old sttyle --- .../java/org/elasticsearch/repositories/RepositoryData.java | 2 ++ .../java/org/elasticsearch/snapshots/SnapshotsService.java | 3 +++ 2 files changed, 5 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/repositories/RepositoryData.java b/server/src/main/java/org/elasticsearch/repositories/RepositoryData.java index 24538c2236fbb..8589d2efdfc6d 100644 --- a/server/src/main/java/org/elasticsearch/repositories/RepositoryData.java +++ b/server/src/main/java/org/elasticsearch/repositories/RepositoryData.java @@ -315,6 +315,8 @@ public List resolveNewIndices(final List indicesToResolve) { * Writes the snapshots metadata and the related indices metadata to x-content. */ public XContentBuilder snapshotsToXContent(final XContentBuilder builder, final boolean shouldWriteShardGens) throws IOException { + assert shouldWriteShardGens || shardGenerations.indices().isEmpty() : + "Should not build shard generations in BwC mode but saw generations [" + shardGenerations + "]"; builder.startObject(); // write the snapshots list diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index e942c4ac2d33c..9c5e640c72216 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -581,6 +581,9 @@ private void cleanupAfterError(Exception exception) { } private static ShardGenerations buildGenerations(SnapshotsInProgress.Entry snapshot) { + if (snapshot.useShardGenerations() == false) { + return ShardGenerations.EMPTY; + } ShardGenerations.Builder builder = ShardGenerations.builder(); final Map indexLookup = new HashMap<>(); snapshot.indices().forEach(idx -> indexLookup.put(idx.getName(), idx));