-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Introducing a translog deletion policy #24950
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
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
da516ff
wip
bleskes af64ed2
wip
bleskes bae1a2a
extract interfaces
bleskes 3abbf9c
Merge remote-tracking branch 'upstream/master' into translog_deletion…
bleskes 5b360dc
java doc tweak
bleskes 176b848
Merge remote-tracking branch 'upstream/master' into translog_deletion…
bleskes d4500aa
wip
bleskes f6a69bd
Translog tests compile
bleskes b97c69d
Translog tests pass
bleskes e1a4709
remove onTranslogRollover as it's not needed for now
bleskes 79101c3
simplification and removal of future stuff
bleskes 8380014
update java docs
bleskes 00a5ddc
tell CombinedDeletionPolicy of open mode so it can be smarter.
bleskes 46626a5
introducing IndexCommitRef
bleskes d99be8c
Merge remote-tracking branch 'upstream/master' into translog_deletion…
bleskes 1e8cf62
a little test to test translog min reference advance
bleskes b773ebf
some java docs
bleskes 460673c
Merge remote-tracking branch 'upstream/master' into translog_deletion…
bleskes b618add
feedback
bleskes 765d388
fix testWithRandomException
bleskes 7656875
Merge remote-tracking branch 'upstream/master' into translog_deletion…
bleskes 97764e5
remove unneeded params
bleskes 5c994f1
Merge remote-tracking branch 'upstream/master' into translog_deletion…
bleskes 350a770
fix delegation and add mock test
bleskes 78ce074
feedback
bleskes ece1a52
Merge remote-tracking branch 'upstream/master' into translog_deletion…
bleskes 8d12158
newView cleanup
bleskes df5f802
Merge remote-tracking branch 'upstream/master' into translog_deletion…
bleskes bcc1a11
Merge remote-tracking branch 'upstream/master' into translog_deletion…
bleskes 362427c
feedback
bleskes 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
86 changes: 86 additions & 0 deletions
86
core/src/main/java/org/elasticsearch/index/engine/CombinedDeletionPolicy.java
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 |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.index.engine; | ||
|
|
||
| import org.apache.lucene.index.IndexCommit; | ||
| import org.apache.lucene.index.IndexDeletionPolicy; | ||
| import org.apache.lucene.index.SnapshotDeletionPolicy; | ||
| import org.elasticsearch.index.translog.Translog; | ||
| import org.elasticsearch.index.translog.TranslogDeletionPolicy; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * An {@link IndexDeletionPolicy} that coordinates between Lucene's commits and the retention of translog generation files, | ||
| * making sure that all translog files that are needed to recover from the Lucene commit are not deleted. | ||
| */ | ||
| class CombinedDeletionPolicy extends IndexDeletionPolicy { | ||
|
|
||
| private final TranslogDeletionPolicy translogDeletionPolicy; | ||
| private final EngineConfig.OpenMode openMode; | ||
|
|
||
| private final SnapshotDeletionPolicy indexDeletionPolicy; | ||
|
|
||
| CombinedDeletionPolicy(SnapshotDeletionPolicy indexDeletionPolicy, TranslogDeletionPolicy translogDeletionPolicy, | ||
| EngineConfig.OpenMode openMode) { | ||
| this.indexDeletionPolicy = indexDeletionPolicy; | ||
| this.translogDeletionPolicy = translogDeletionPolicy; | ||
| this.openMode = openMode; | ||
| } | ||
|
|
||
| @Override | ||
| public void onInit(List<? extends IndexCommit> commits) throws IOException { | ||
| indexDeletionPolicy.onInit(commits); | ||
| switch (openMode) { | ||
| case CREATE_INDEX_AND_TRANSLOG: | ||
| assert commits.isEmpty() : "index is being created but we already have commits"; | ||
| break; | ||
| case OPEN_INDEX_CREATE_TRANSLOG: | ||
| assert commits.isEmpty() == false : "index is opened, but we have no commits"; | ||
| break; | ||
| case OPEN_INDEX_AND_TRANSLOG: | ||
| assert commits.isEmpty() == false : "index is opened, but we have no commits"; | ||
| setLastCommittedTranslogGeneration(commits); | ||
| break; | ||
| default: | ||
| throw new IllegalArgumentException("unknown openMode [" + openMode + "]"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onCommit(List<? extends IndexCommit> commits) throws IOException { | ||
| indexDeletionPolicy.onCommit(commits); | ||
| setLastCommittedTranslogGeneration(commits); | ||
| } | ||
|
|
||
| private void setLastCommittedTranslogGeneration(List<? extends IndexCommit> commits) throws IOException { | ||
| // when opening an existing lucene index, we currently always open the last commit. | ||
| // we therefore use the translog gen as the one that will be required for recovery | ||
| final IndexCommit indexCommit = commits.get(commits.size() - 1); | ||
| assert indexCommit.isDeleted() == false : "last commit is deleted"; | ||
| long minGen = Long.parseLong(indexCommit.getUserData().get(Translog.TRANSLOG_GENERATION_KEY)); | ||
| translogDeletionPolicy.setMinTranslogGenerationForRecovery(minGen); | ||
| } | ||
|
|
||
| public SnapshotDeletionPolicy getIndexDeletionPolicy() { | ||
| return indexDeletionPolicy; | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
nit: does this need to break into 3 lines or is this maybe a leftover?
Uh oh!
There was an error while loading. Please reload this page.
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.
sadly it doesn't fit in one line, I'll make it like this - it seems you prefer it:
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.
k