-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Consistent ClusterState throughout Snapshot API Calls #51464
Merged
original-brownbear
merged 5 commits into
elastic:master
from
original-brownbear:consistent-cs-for-snapshot-status-apis
Jan 27, 2020
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a691424
Use Consistent ClusterState throughout Snapshot API Calls
original-brownbear 08dfd9b
Merge remote-tracking branch 'elastic/master' into consistent-cs-for-…
original-brownbear f2efe16
CR: pass around SnapshotsInProgress
original-brownbear bb2ded5
Merge remote-tracking branch 'elastic/master' into consistent-cs-for-…
original-brownbear 2bfe8f5
CR: nullables
original-brownbear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,13 +174,14 @@ public void getRepositoryData(final String repositoryName, final ActionListener< | |
/** | ||
* Retrieves snapshot from repository | ||
* | ||
* @param state cluster state | ||
* @param repositoryName repository name | ||
* @param snapshotId snapshot id | ||
* @return snapshot | ||
* @throws SnapshotMissingException if snapshot is not found | ||
*/ | ||
public SnapshotInfo snapshot(final String repositoryName, final SnapshotId snapshotId) { | ||
List<SnapshotsInProgress.Entry> entries = currentSnapshots(repositoryName, Collections.singletonList(snapshotId.getName())); | ||
public SnapshotInfo snapshot(ClusterState state, final String repositoryName, final SnapshotId snapshotId) { | ||
List<SnapshotsInProgress.Entry> entries = currentSnapshots(state, repositoryName, Collections.singletonList(snapshotId.getName())); | ||
if (!entries.isEmpty()) { | ||
return inProgressSnapshot(entries.iterator().next()); | ||
} | ||
|
@@ -190,18 +191,20 @@ public SnapshotInfo snapshot(final String repositoryName, final SnapshotId snaps | |
/** | ||
* Returns a list of snapshots from repository sorted by snapshot creation date | ||
* | ||
* @param state cluster state | ||
* @param repositoryName repository name | ||
* @param snapshotIds snapshots for which to fetch snapshot information | ||
* @param ignoreUnavailable if true, snapshots that could not be read will only be logged with a warning, | ||
* if false, they will throw an error | ||
* @return list of snapshots | ||
*/ | ||
public List<SnapshotInfo> snapshots(final String repositoryName, final List<SnapshotId> snapshotIds, final boolean ignoreUnavailable) { | ||
public List<SnapshotInfo> snapshots(ClusterState state, String repositoryName, List<SnapshotId> snapshotIds, | ||
boolean ignoreUnavailable) { | ||
final Set<SnapshotInfo> snapshotSet = new HashSet<>(); | ||
final Set<SnapshotId> snapshotIdsToIterate = new HashSet<>(snapshotIds); | ||
// first, look at the snapshots in progress | ||
final List<SnapshotsInProgress.Entry> entries = | ||
currentSnapshots(repositoryName, snapshotIdsToIterate.stream().map(SnapshotId::getName).collect(Collectors.toList())); | ||
currentSnapshots(state, repositoryName, snapshotIdsToIterate.stream().map(SnapshotId::getName).collect(Collectors.toList())); | ||
for (SnapshotsInProgress.Entry entry : entries) { | ||
snapshotSet.add(inProgressSnapshot(entry)); | ||
snapshotIdsToIterate.remove(entry.snapshot().getSnapshotId()); | ||
|
@@ -230,12 +233,13 @@ public List<SnapshotInfo> snapshots(final String repositoryName, final List<Snap | |
/** | ||
* Returns a list of currently running snapshots from repository sorted by snapshot creation date | ||
* | ||
* @param state cluster state | ||
* @param repositoryName repository name | ||
* @return list of snapshots | ||
*/ | ||
public List<SnapshotInfo> currentSnapshots(final String repositoryName) { | ||
public static List<SnapshotInfo> currentSnapshots(ClusterState state, String repositoryName) { | ||
List<SnapshotInfo> snapshotList = new ArrayList<>(); | ||
List<SnapshotsInProgress.Entry> entries = currentSnapshots(repositoryName, Collections.emptyList()); | ||
List<SnapshotsInProgress.Entry> entries = currentSnapshots(state, repositoryName, Collections.emptyList()); | ||
for (SnapshotsInProgress.Entry entry : entries) { | ||
snapshotList.add(inProgressSnapshot(entry)); | ||
} | ||
|
@@ -677,8 +681,8 @@ private static SnapshotInfo inProgressSnapshot(SnapshotsInProgress.Entry entry) | |
* @param snapshots list of snapshots that will be used as a filter, empty list means no snapshots are filtered | ||
* @return list of metadata for currently running snapshots | ||
*/ | ||
public List<SnapshotsInProgress.Entry> currentSnapshots(final String repository, final List<String> snapshots) { | ||
SnapshotsInProgress snapshotsInProgress = clusterService.state().custom(SnapshotsInProgress.TYPE); | ||
public static List<SnapshotsInProgress.Entry> currentSnapshots(ClusterState state, String repository, List<String> snapshots) { | ||
SnapshotsInProgress snapshotsInProgress = state.custom(SnapshotsInProgress.TYPE); | ||
if (snapshotsInProgress == null || snapshotsInProgress.entries().isEmpty()) { | ||
return Collections.emptyList(); | ||
} | ||
|
@@ -1222,7 +1226,8 @@ public void deleteSnapshot(final String repositoryName, final String snapshotNam | |
// if nothing found by the same name, then look in the cluster state for current in progress snapshots | ||
long repoGenId = repositoryData.getGenId(); | ||
if (matchedEntry.isPresent() == false) { | ||
Optional<SnapshotsInProgress.Entry> matchedInProgress = currentSnapshots(repositoryName, Collections.emptyList()).stream() | ||
Optional<SnapshotsInProgress.Entry> matchedInProgress = currentSnapshots( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making the fact that we're using a potentially racy CS here, leading to some needless snapshot delete failures, obvious was the main motivation behind this change actually (a bigger change to deletes making use of this cleanup is coming in #51463). |
||
clusterService.state(), repositoryName, Collections.emptyList()).stream() | ||
.filter(s -> s.snapshot().getSnapshotId().getName().equals(snapshotName)).findFirst(); | ||
if (matchedInProgress.isPresent()) { | ||
matchedEntry = matchedInProgress.map(s -> s.snapshot().getSnapshotId()); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just pass down
SnapshotsInProgress
? Makes it a bit clearer what the dependencies areThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure sounds good :) => f2efe16