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

Ignore shard started requests when primary term does not match #37899

Merged
merged 5 commits into from
Jan 29, 2019

Conversation

tlrx
Copy link
Member

@tlrx tlrx commented Jan 26, 2019

When a shard on a data node finished to recover, the data node sends a StartedShardEntry request to the master node. This request contains the shard id, an allocation id and the id of the node that holds the shard to start. This request is then processed by the master node which checks that the shard exists in the cluster state with the same allocation id as in the request.

This pull request changes the StartedShardEntry so that it also contains the primary term of the shard to start. This way the master node can also checks that the primary term from the start request is equal to the current shard's primary term in the cluster state, and it can ignore any shard started request that would concerns a previous instance of the shard that would have been allocated to the same node.

Such situation are likely to happen with frozen (or restored) indices and the replication of closed indices, because with replicated closed indices the shards will be initialized again after the index is closed and can potentially be re initialized again if the index is reopened as a frozen index. In such cases the lifecycle of the shards would be something like:

  • shard is STARTED
  • index is closed
  • shards is INITIALIZING (index state is CLOSED, primary term is X)
  • index is reopened
  • shards are INITIALIZING again (index state is OPENED, potentially frozen, primary term is X+1)

Adding the primary term to the shard started request will allow to discard potential StartedShardEntry requests received by the master node if the request concerns the shard with primary term X because it has been moved/reinitialized in the meanwhile under the primary term X+1.

Relates to #33888

@tlrx tlrx added >enhancement v7.0.0 :Distributed Indexing/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. v6.7.0 labels Jan 26, 2019
@tlrx tlrx requested a review from ywelsch January 26, 2019 12:10
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

@tlrx
Copy link
Member Author

tlrx commented Jan 26, 2019

All tests green (except oss-distro-docs, but it fails because of another change) but I'd like more CI runs so:

@elasticmachine test this please

@tlrx
Copy link
Member Author

tlrx commented Jan 26, 2019

Green again except oss-distro-docs, let's run it one more time: @elasticmachine test this please

@tlrx
Copy link
Member Author

tlrx commented Jan 28, 2019

Thanks @ywelsch, I updated the PR. Let me know what you think

@tlrx tlrx requested a review from ywelsch January 28, 2019 09:58
shardRouting.active());
}
if (this.shardRouting.primary()) {
assertTrue("a primary shard can't be demoted", shardRouting.primary());
if (this.shardRouting.initializing()) {
assertEquals("primary term can not be updated on an initializing primary shard: " + shardRouting, term, newPrimaryTerm);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we have the same assertion directly in IndexShard?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's already present under this form so I think we're good.

@tlrx tlrx force-pushed the use-primary-term-to-start-shards branch from 4f779c0 to 2d39807 Compare January 28, 2019 16:57
Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

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

LGTM

@tlrx
Copy link
Member Author

tlrx commented Jan 28, 2019

@elasticmachine run elasticsearch-ci/2

1 similar comment
@tlrx
Copy link
Member Author

tlrx commented Jan 29, 2019

@elasticmachine run elasticsearch-ci/2

@tlrx
Copy link
Member Author

tlrx commented Jan 29, 2019

@elasticmachine run elasticsearch-ci/default-distro

@tlrx tlrx merged commit 5d1964b into elastic:master Jan 29, 2019
@tlrx
Copy link
Member Author

tlrx commented Jan 29, 2019

Thanks @ywelsch

@tlrx tlrx deleted the use-primary-term-to-start-shards branch January 29, 2019 14:09
@tlrx tlrx mentioned this pull request Jan 30, 2019
50 tasks
tlrx added a commit that referenced this pull request Jan 31, 2019
This pull request disables BWC tests while backporting #37899 to 6.x.
tlrx added a commit that referenced this pull request Jan 31, 2019
This commit changes the StartedShardEntry so that it also contains the
primary term of the shard to start. This way the master node can also
checks that the primary term from the start request is equal to the current
shard's primary term in the cluster state, and it can ignore any shard
started request that would concerns a previous instance of the shard that
would have been allocated to the same node.

Such situation are likely to happen with frozen (or restored) indices and
the replication of closed indices, because with replicated closed indices
the shards will be initialized again after the index is closed and can
potentially be re initialized again if the index is reopened as a frozen
index. In such cases the lifecycle of the shards would be something like:
* shard is STARTED
* index is closed
* shards is INITIALIZING (index state is CLOSED, primary term is X)
* index is reopened
* shards are INITIALIZING again (index state is OPENED, potentially frozen,
primary term is X+1)

Adding the primary term to the shard started request will allow to discard
potential StartedShardEntry requests received by the master node if the
request concerns the shard with primary term X because it has been
moved/reinitialized in the meanwhile under the primary term X+1.

Relates to #33888
tlrx added a commit to tlrx/elasticsearch that referenced this pull request Jan 31, 2019
This commit adapts the version used in StartedShardEntry serialization
 after the backport of  elastic#37899 and reenables bwc tests.

Related to elastic#37899
Related to elastic#38074
tlrx added a commit that referenced this pull request Jan 31, 2019
This commit adapts the version used in StartedShardEntry serialization
 after the backport of  #37899 and reenables bwc tests.

Related to #37899
Related to #38074
@tlrx
Copy link
Member Author

tlrx commented Jan 31, 2019

Backported to 6.x in 255015d

jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Jan 31, 2019
…ersion

* elastic/master:
  Do not set up NodeAndClusterIdStateListener in test (elastic#38110)
  ML: better handle task state race condition (elastic#38040)
  Soft-deletes policy should always fetch latest leases (elastic#37940)
  Handle scheduler exceptions (elastic#38014)
  Minor logging improvements (elastic#38084)
  Fix Painless void return bug (elastic#38046)
  Update PutFollowAction serialization post-backport (elastic#37989)
  fix a few versionAdded values in ElasticsearchExceptions (elastic#37877)
  Reenable BWC tests after backport of elastic#37899 (elastic#38093)
  Mute failing test
  Mute failing test
  Fail start on obsolete indices documentation (elastic#37786)
  SQL: Implement FIRST/LAST aggregate functions (elastic#37936)
  Un-mute NoMasterNodeIT.testNoMasterActionsWriteMasterBlock
  remove unused parser fields in RemoteResponseParsers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Indexing/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. >enhancement v6.7.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants