Skip to content

Commit 86fd758

Browse files
committed
methods reorg
1 parent 46b8fd6 commit 86fd758

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,7 @@ public RepositoryData addSnapshot(
461461
snapshots,
462462
newSnapshotDetails,
463463
allIndexSnapshots,
464-
ShardGenerations.builder()
465-
.putAll(this.shardGenerations)
466-
.putAll(shardGenerations)
467-
.updateIfPresent(updatedShardGenerations.deletedIndices())
468-
.build(),
464+
ShardGenerations.builder().putAll(this.shardGenerations).update(updatedShardGenerations).build(),
469465
newIndexMetaGenerations,
470466
clusterUUID
471467
);

server/src/main/java/org/elasticsearch/repositories/ShardGenerations.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.regex.Pattern;
2929
import java.util.stream.Collectors;
3030

31+
import static org.elasticsearch.repositories.FinalizeSnapshotContext.*;
32+
3133
/**
3234
* Represents the current {@link ShardGeneration} for each shard in a repository.
3335
*/
@@ -231,17 +233,11 @@ public Builder putAll(ShardGenerations shardGenerations) {
231233
return this;
232234
}
233235

234-
public Builder updateIfPresent(ShardGenerations shardGenerations) {
235-
shardGenerations.shardGenerations.forEach((indexId, gens) -> {
236-
if (generations.containsKey(indexId)) {
237-
for (int i = 0; i < gens.size(); i++) {
238-
final ShardGeneration gen = gens.get(i);
239-
if (gen != null) {
240-
generations.get(indexId).put(i, gen);
241-
}
242-
}
243-
}
244-
});
236+
public Builder update(UpdatedShardGenerations updatedShardGenerations) {
237+
putAll(updatedShardGenerations.liveIndices());
238+
// For deleted indices, we only update the generations if they are present in the existing generations, i.e.
239+
// they are referenced by other snapshots.
240+
updateIfPresent(updatedShardGenerations.deletedIndices());
245241
return this;
246242
}
247243

@@ -258,6 +254,20 @@ public Builder put(IndexId indexId, int shardId, ShardGeneration generation) {
258254
return this;
259255
}
260256

257+
private Builder updateIfPresent(ShardGenerations shardGenerations) {
258+
shardGenerations.shardGenerations.forEach((indexId, gens) -> {
259+
if (generations.containsKey(indexId)) {
260+
for (int i = 0; i < gens.size(); i++) {
261+
final ShardGeneration gen = gens.get(i);
262+
if (gen != null) {
263+
generations.get(indexId).put(i, gen);
264+
}
265+
}
266+
}
267+
});
268+
return this;
269+
}
270+
261271
private boolean noDuplicateIndicesWithSameName(IndexId newId) {
262272
for (IndexId id : generations.keySet()) {
263273
if (id.getName().equals(newId.getName()) && id.equals(newId) == false) {

server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,10 +1629,6 @@ public void testDeleteIndexBetweenSuccessAndFinalization() {
16291629
}
16301630
l.onResponse(null);
16311631
}));
1632-
})
1633-
.andThen(l -> {
1634-
// delete the snapshot that has the deleted index so it triggers cleanup of redundant shard generations
1635-
client.admin().cluster().prepareDeleteSnapshot(TEST_REQUEST_TIMEOUT, repoName, "first-snapshot").execute(l.map(r -> null));
16361632
});
16371633

16381634
deterministicTaskQueue.runAllRunnableTasks();

0 commit comments

Comments
 (0)