-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Simplify Snapshot Delete Process #47439
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
Merged
original-brownbear
merged 4 commits into
elastic:master
from
original-brownbear:stop-senselessly-reading-snapshot-meta
Oct 3, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
54a8120
Simplify Snapshot Delete Process
original-brownbear bd224b2
Merge remote-tracking branch 'elastic/master' into stop-senselessly-r…
original-brownbear 011fcf5
Merge remote-tracking branch 'elastic/master' into stop-senselessly-r…
original-brownbear 0961fd1
CR: add test
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -27,7 +27,6 @@ | |
| import org.apache.lucene.store.IndexInput; | ||
| import org.apache.lucene.store.RateLimiter; | ||
| import org.apache.lucene.util.SetOnce; | ||
| import org.elasticsearch.ElasticsearchParseException; | ||
| import org.elasticsearch.ExceptionsHelper; | ||
| import org.elasticsearch.Version; | ||
| import org.elasticsearch.action.ActionListener; | ||
|
|
@@ -62,7 +61,6 @@ | |
| import org.elasticsearch.common.unit.ByteSizeUnit; | ||
| import org.elasticsearch.common.unit.ByteSizeValue; | ||
| import org.elasticsearch.common.util.concurrent.AbstractRunnable; | ||
| import org.elasticsearch.common.util.set.Sets; | ||
| import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; | ||
| import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
| import org.elasticsearch.common.xcontent.XContentFactory; | ||
|
|
@@ -101,17 +99,13 @@ | |
| import java.io.InputStream; | ||
| import java.nio.file.NoSuchFileException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.concurrent.Executor; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo.canonicalName; | ||
|
|
@@ -365,6 +359,8 @@ public void deleteSnapshot(SnapshotId snapshotId, long repositoryStateId, Action | |
| try { | ||
| final Map<String, BlobMetaData> rootBlobs = blobContainer().listBlobs(); | ||
| final RepositoryData repositoryData = getRepositoryData(latestGeneration(rootBlobs.keySet())); | ||
| // Cache the indices that were found before writing out the new index-N blob so that a stuck master will never | ||
|
Contributor
Author
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. This comment belongs here, it must have accidentally gotten out of place in a previous refactoring. |
||
| // delete an index that was created by another master node after writing this index-N blob. | ||
| final Map<String, BlobContainer> foundIndices = blobStore().blobContainer(indicesPath()).children(); | ||
| doDeleteShardSnapshots(snapshotId, repositoryStateId, foundIndices, rootBlobs, repositoryData, listener); | ||
| } catch (Exception ex) { | ||
|
|
@@ -390,36 +386,13 @@ private void doDeleteShardSnapshots(SnapshotId snapshotId, long repositoryStateI | |
| Map<String, BlobMetaData> rootBlobs, RepositoryData repositoryData, | ||
| ActionListener<Void> listener) throws IOException { | ||
| final RepositoryData updatedRepositoryData = repositoryData.removeSnapshot(snapshotId); | ||
| // Cache the indices that were found before writing out the new index-N blob so that a stuck master will never | ||
| // delete an index that was created by another master node after writing this index-N blob. | ||
| writeIndexGen(updatedRepositoryData, repositoryStateId); | ||
| SnapshotInfo snapshot = null; | ||
| try { | ||
| snapshot = getSnapshotInfo(snapshotId); | ||
| } catch (SnapshotMissingException ex) { | ||
| listener.onFailure(ex); | ||
| return; | ||
| } catch (IllegalStateException | SnapshotException | ElasticsearchParseException ex) { | ||
| logger.warn(() -> new ParameterizedMessage("cannot read snapshot file [{}]", snapshotId), ex); | ||
| } | ||
| final List<String> snapMetaFilesToDelete = | ||
| Arrays.asList(snapshotFormat.blobName(snapshotId.getUUID()), globalMetaDataFormat.blobName(snapshotId.getUUID())); | ||
| try { | ||
| blobContainer().deleteBlobsIgnoringIfNotExists(snapMetaFilesToDelete); | ||
| } catch (IOException e) { | ||
| logger.warn(() -> new ParameterizedMessage("[{}] Unable to delete global metadata files", snapshotId), e); | ||
| } | ||
| final var survivingIndices = updatedRepositoryData.getIndices(); | ||
| deleteIndices( | ||
| updatedRepositoryData, | ||
| Optional.ofNullable(snapshot).map(info -> info.indices().stream().filter(survivingIndices::containsKey) | ||
| .map(updatedRepositoryData::resolveIndexId).collect(Collectors.toList())).orElse(Collections.emptyList()), | ||
| repositoryData.indicesToUpdateAfterRemovingSnapshot(snapshotId), | ||
| snapshotId, | ||
| ActionListener.delegateFailure(listener, | ||
| (l, v) -> cleanupStaleBlobs(foundIndices, | ||
| Sets.difference(rootBlobs.keySet(), new HashSet<>(snapMetaFilesToDelete)).stream().collect( | ||
| Collectors.toMap(Function.identity(), rootBlobs::get)), | ||
| updatedRepositoryData, ActionListener.map(l, ignored -> null)))); | ||
| (l, v) -> cleanupStaleBlobs(foundIndices, rootBlobs, updatedRepositoryData, ActionListener.map(l, ignored -> null)))); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.