-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Introduce promoting index shard state #28004
Conversation
This commit adds a new index shard state - promoting. This state indicates that a replica is promoting to primary and primary-replica resync is in progress. Relates elastic#24841
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.
There are more places where shard states are used. We have to be careful in getting all of those. A grep for IndexShardState.STARTED
yields other places where we need to account for the newly introduced shard state, for example in IndexMemoryController, IndicesClusterStateService, IndicesStore, MockFSIndexStore.
@@ -192,7 +192,7 @@ | |||
private final GlobalCheckpointTracker globalCheckpointTracker; | |||
|
|||
protected volatile ShardRouting shardRouting; | |||
protected volatile IndexShardState state; | |||
protected final AtomicReference<IndexShardState> state; |
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.
why change this to an AtomicReference? Just because of stylistic reasons or is there more to it? Looking through the PR, I could not find a reason for this change. Every write access to it is guarded by a mutex, and read access is ok with volatile. Let's keep it a volatile variable.
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.
Yes, I will revert this.
@@ -609,6 +607,11 @@ public void relocated( | |||
} | |||
|
|||
private void verifyRelocatingState() { | |||
final IndexShardState state = state(); | |||
if (state == IndexShardState.PROMOTING) { |
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.
this is already covered by the check if (state != IndexShardState.STARTED) {
below?
Thanks @ywelsch, I will look at all other places that use |
@ywelsch, I've addressed your comments. Would you please take a look? Thank you. |
boolean resyncStarted = primaryReplicaResyncInProgress.compareAndSet(false, true); | ||
if (resyncStarted == false) { | ||
throw new IllegalStateException("cannot start resync while it's already in progress"); | ||
final IndexShardState prevState = changeState(IndexShardState.PROMOTING, "Promoting to primary"); |
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.
instead of changing the state first and then checking whether the previous state was the right one, let's only change the state if the current state matches (note that we're under the mutex here already, so it's safe to do this).
boolean resyncCompleted = primaryReplicaResyncInProgress.compareAndSet(true, false); | ||
assert resyncCompleted : "primary-replica resync finished but was not started"; | ||
synchronized (mutex) { | ||
final IndexShardState prevState = changeState(IndexShardState.STARTED, "Resync is completed"); |
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.
same comment as above, let's check state first and then change it.
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
boolean resyncCompleted = primaryReplicaResyncInProgress.compareAndSet(true, false); |
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.
as we have no corresponding state transition here now, does it mean that the shard can forever be stuck in PROMOTING state, allow no relocations?
@ywelsch Could you please give it another go. Thank you. |
I've talked to @jasontedor and @dnhatn and suggested to take another approach. I don't like adding new shard states which are somewhat replicating information that's already available in the GlobalCheckpointTracker (to be called ReplicationTracker). We could instead get rid of the RELOCATED state, whose purpose is to say that the primary is not in charge anymore of assigning sequence numbers, something which is already covered by |
Thanks @ywelsch for your suggestion. I am closing this. |
Some clarification for future readers - the reason why the
|
While the presented logic is correct for what the primary-replica resync is doing today, it's incorrect if the future primary-replica sync has the additional job of trimming / rolling back portions of the translog. |
This commit adds a new index shard state - promoting. This state
indicates that a replica is promoting to primary and primary-replica
resync is in progress.
Relates #24841