-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Introduce retention leases versioning #37951
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
jasontedor
merged 31 commits into
elastic:master
from
jasontedor:retention-leases-version
Feb 1, 2019
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
98f4239
Introduce retention leases versioning
jasontedor 38dffb5
Add Javadocs
jasontedor c715b5e
License header
jasontedor f8e8547
Relocate methods
jasontedor 4aa6b77
Merge branch 'master' into retention-leases-version
jasontedor 6ab494d
Add primary term
jasontedor 2d3772c
Merge remote-tracking branch 'elastic/master' into retention-leases-v…
jasontedor 954db81
Remove dead constructor
jasontedor 9d09989
Partition leases when calculating expiration
jasontedor 17d2095
Remove unnecessary map
jasontedor e724746
Fix test
jasontedor e8971b9
Fix spelling and imports
jasontedor f3cb4eb
Add tests and docs for supersedes
jasontedor 0a7d19b
Adjust primary term limit
jasontedor 034a840
Add missing newline
jasontedor 05b69c0
Update tests
jasontedor 600809c
Fix test
jasontedor 39023d8
Fix imports
jasontedor 80b08b3
Fix some naming
jasontedor ae0fc2a
Fix checkstyle
jasontedor 08095cb
Update server/src/test/java/org/elasticsearch/index/seqno/Replication…
jasontedor 8d9deae
Fix compilation
jasontedor fce4da6
Fix checkstyle
jasontedor 76bb46b
Inline
jasontedor 44c5e0f
Inline
jasontedor bc96632
Fix test
jasontedor becb055
Adjust docs
jasontedor 73fb8f5
Disable BWC
jasontedor 7cf145c
Merge branch 'master' into retention-leases-version
jasontedor 686d35e
Merge branch 'master' into retention-leases-version
jasontedor be0edfc
Merge remote-tracking branch 'elastic/master' into retention-leases-v…
jasontedor 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
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
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
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
49 changes: 49 additions & 0 deletions
49
server/src/main/java/org/elasticsearch/index/seqno/RetentionLeases.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,49 @@ | ||
| package org.elasticsearch.index.seqno; | ||
|
|
||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.io.stream.Writeable; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.Objects; | ||
|
|
||
| public class RetentionLeases implements Writeable { | ||
|
|
||
| private final long version; | ||
|
|
||
| public long version() { | ||
| return version; | ||
| } | ||
|
|
||
| private final Collection<RetentionLease> retentionLeases; | ||
|
|
||
| public Collection<RetentionLease> retentionLeases() { | ||
| return retentionLeases; | ||
| } | ||
|
|
||
| public static RetentionLeases EMPTY = new RetentionLeases(0, Collections.emptyList()); | ||
|
|
||
| public RetentionLeases(final long version, final Collection<RetentionLease> retentionLeases) { | ||
| if (version < 0) { | ||
| throw new IllegalArgumentException("version must be non-negative but was [" + version + "]"); | ||
| } | ||
| Objects.requireNonNull(retentionLeases); | ||
| this.version = version; | ||
| this.retentionLeases = Collections.unmodifiableCollection(new ArrayList<>(retentionLeases)); | ||
| } | ||
|
|
||
| public RetentionLeases(final StreamInput in) throws IOException { | ||
| version = in.readVLong(); | ||
| retentionLeases = in.readList(RetentionLease::new); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(final StreamOutput out) throws IOException { | ||
| out.writeVLong(version); | ||
| out.writeCollection(retentionLeases); | ||
| } | ||
|
|
||
| } |
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.
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.
We might have an issue with the primary fail-over here. Suppose the primary is syncing two new leases requests L1 and L2, both of them are processed on replica-1, but the primary crashes before any of them arrives on the replica-2. If the replica-2 is promoted, then we add two new leases: L3 and L4. Unfortunately, replica-1 will ignore these two new requests, and its leases (L1 and L2) are different from the leases on the new primary (L3 and L4). I think we can use the primary-term with the leases version to have a total ordering pair <<term, version>>. What do you think?
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.
I wish we could find a simpler way, but I can't. +1 from me on the suggestion.
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.
I also looked for a simpler way, and @ywelsch did too. I could not find anything, and neither could @ywelsch. We synced earlier and agreed that this looks like the only way forward. We need to do a refactoring to the replication tracker and index shard to push the operation primary term down into the tracker, and then we will proceed with updating this PR.
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.
thanks. great catch @dnhatn .
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.
@dnhatn is going to work on adding the retention lease infrastructure to index level replication test case infrastructure so that we can test these scenarios.
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.
@dnhatn I have updated this PR to include the primary term here. I want to add some additional testing, but this PR is ready for another review round from you.