forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Snapshot Finalization Method (elastic#76005) (elastic#76594)
This refactors the signature of snapshot finalization. For one it allows removing a TODO about being dependent on mutable `SnapshotInfo` which was not great but more importantly this sets up a follow-up where state can be shared between the cluster state update at the end of finalization and subsequent old-shard-generation cleanup so that we can resolve another open TODO about leaking shard generation files in some cases.
- Loading branch information
1 parent
b509b9f
commit eadfeac
Showing
16 changed files
with
233 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
server/src/main/java/org/elasticsearch/repositories/FinalizeSnapshotContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.repositories; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.Metadata; | ||
import org.elasticsearch.core.Tuple; | ||
import org.elasticsearch.snapshots.SnapshotInfo; | ||
import org.elasticsearch.snapshots.SnapshotsService; | ||
|
||
/** | ||
* Context for finalizing a snapshot. | ||
*/ | ||
public final class FinalizeSnapshotContext extends ActionListener.Delegating< | ||
Tuple<RepositoryData, SnapshotInfo>, | ||
Tuple<RepositoryData, SnapshotInfo>> { | ||
|
||
private final ShardGenerations updatedShardGenerations; | ||
|
||
private final long repositoryStateId; | ||
|
||
private final Metadata clusterMetadata; | ||
|
||
private final SnapshotInfo snapshotInfo; | ||
|
||
private final Version repositoryMetaVersion; | ||
|
||
/** | ||
* @param updatedShardGenerations updated shard generations | ||
* @param repositoryStateId the unique id identifying the state of the repository when the snapshot began | ||
* @param clusterMetadata cluster metadata | ||
* @param snapshotInfo SnapshotInfo instance to write for this snapshot | ||
* @param repositoryMetaVersion version of the updated repository metadata to write | ||
* @param listener listener to be invoked with the new {@link RepositoryData} and {@link SnapshotInfo} after completing | ||
* the snapshot | ||
*/ | ||
public FinalizeSnapshotContext( | ||
ShardGenerations updatedShardGenerations, | ||
long repositoryStateId, | ||
Metadata clusterMetadata, | ||
SnapshotInfo snapshotInfo, | ||
Version repositoryMetaVersion, | ||
ActionListener<Tuple<RepositoryData, SnapshotInfo>> listener | ||
) { | ||
super(listener); | ||
this.updatedShardGenerations = updatedShardGenerations; | ||
this.repositoryStateId = repositoryStateId; | ||
this.clusterMetadata = clusterMetadata; | ||
this.snapshotInfo = snapshotInfo; | ||
this.repositoryMetaVersion = repositoryMetaVersion; | ||
} | ||
|
||
public long repositoryStateId() { | ||
return repositoryStateId; | ||
} | ||
|
||
public ShardGenerations updatedShardGenerations() { | ||
return updatedShardGenerations; | ||
} | ||
|
||
public SnapshotInfo snapshotInfo() { | ||
return snapshotInfo; | ||
} | ||
|
||
public Version repositoryMetaVersion() { | ||
return repositoryMetaVersion; | ||
} | ||
|
||
public Metadata clusterMetadata() { | ||
return clusterMetadata; | ||
} | ||
|
||
public ClusterState updatedClusterState(ClusterState state) { | ||
return SnapshotsService.stateWithoutSuccessfulSnapshot(state, snapshotInfo.snapshot()); | ||
} | ||
|
||
@Override | ||
public void onResponse(Tuple<RepositoryData, SnapshotInfo> repositoryData) { | ||
delegate.onResponse(repositoryData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.