Skip to content
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

Add Sequence Numbers and enforce Primary Terms #14651

Closed
wants to merge 11 commits into from

Conversation

bleskes
Copy link
Contributor

@bleskes bleskes commented Nov 10, 2015

This PR (against the feature/seq_no branch) adds a counter to each write operation on a shard. This sequence numbers is indexed into lucene using doc values, for now (we will probably require indexing to support range searchers in the future).

On top of this, primary term semantics are enforced and shards will refuse write operation coming from an older primary.

Other notes:

  • The add SequenceServiceNumber is just a skeleton and will be replaced with much heavier one, once we have all the building blocks (i.e., checkpoints).
  • I completely ignored recovery - for this we will need checkpoints as well.
  • A new based class is introduced for all single doc write operations. This is handy to unify common logic (like toXContent).
  • For now, we don't use seq# as versioning. We could in the future.

Relates to #10708

/**
* A based class for the response of a write operation that involves are a single doc
*/
public abstract class DocWriteResponse extends ReplicationResponse implements ToXContent {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this somehow implement Writeable here or rather at the parent and make all the members final?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to keep the same patterns as before to keep the change small. Will give it a shot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look and this impossible without changing our network infra as well. This inherits from TransportResponse which implements Streamable, i.e., the readFrom has different semantics and returns void.

@s1monw
Copy link
Contributor

s1monw commented Nov 10, 2015

looks great I left some comments

import java.io.IOException;

/**
* A based class for the response of a write operation that involves are a single doc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits: "based class" -> "base class" and "involves are a" -> "involves a"

@bleskes
Copy link
Contributor Author

bleskes commented Nov 13, 2015

@jasontedor can you take another look?

this.version = version;
}

public DocWriteResponse() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have a comment that it's for serialization?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do. Also made it protected.

@clintongormley clintongormley changed the title Add Sequence Numbers and an enforce Primary Terms Add Sequence Numbers and enforce Primary Terms Nov 16, 2015
}

/**
* Returns the sequence number assigned for this change. Returns -1L if the operation wasn't
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would be clearer if the -1L that are now scattered in a few places (e.g., UpdateResponse, among a few others) were changed to refer to some constant field?


try {
indexShard.incrementOperationCounter(primaryTerm - 1);
fail("you can not increment the operation counter with an older primary term");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. :)

@jasontedor
Copy link
Member

@bleskes I have a few nits, and some concerns about the -1s. It seems to be that there are at least two distinct uses of -1 (uninitialized, and no-op) and I wonder if they should be separated and use some constant fields? Otherwise, LGTM.

@bleskes
Copy link
Contributor Author

bleskes commented Nov 19, 2015

@jasontedor +1 to the -1 :) . pushed another round. Also rebased on latest master so we can sue the writeZLong thing.

@jasontedor
Copy link
Member

LGTM.

bleskes added a commit that referenced this pull request Nov 19, 2015
Adds a counter to each write operation on a shard. This sequence numbers is indexed into lucene using doc values, for now (we will probably require indexing to support range searchers in the future).

On top of this, primary term semantics are enforced and shards will refuse write operation coming from an older primary.

Other notes:
- The add SequenceServiceNumber is just a skeleton and will be replaced with much heavier one, once we have all the building blocks (i.e., checkpoints).
- I completely ignored recovery - for this we will need checkpoints as well.
- A new based class is introduced for all single doc write operations. This is handy to unify common logic (like toXContent).
- For now, we don't use seq# as versioning. We could in the future.

Relates to #10708
Closes #14651
@bleskes
Copy link
Contributor Author

bleskes commented Nov 19, 2015

Merged into feature/seq_no. Thanks @jasontedor.

@bleskes bleskes closed this Nov 19, 2015
@bleskes bleskes deleted the seq_no_counter branch November 19, 2015 14:36
bleskes added a commit to bleskes/elasticsearch that referenced this pull request Mar 25, 2016
Primary terms is a way to make sure that operations replicated from stale primary are rejected by shards following a newly elected primary.

Original PRs adding this to the seq# feature branch elastic#14062 , elastic#14651 . Unlike those PR, here we take a different approach (based on newer code in master) where the primary terms are stored in the meta data only (and not in `ShardRouting` objects).

Relates to elastic#17038

Closes elastic#17044
@clintongormley clintongormley added :Engine :Distributed/Engine Anything around managing Lucene and the Translog in an open shard. and removed :Sequence IDs labels Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed/Engine Anything around managing Lucene and the Translog in an open shard. >enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants