-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add ClusterStateSupplier interface + standard implementation #115931
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
Conversation
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
server/src/main/java/org/elasticsearch/cluster/ClusterStateSupplier.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/SafeClusterStateSupplier.java
Outdated
Show resolved
Hide resolved
|
@elasticmachine update branch |
| @Override | ||
| public void clusterChanged(ClusterChangedEvent event) { | ||
| if (isInitialized() || event.state().blocks().hasGlobalBlock(STATE_NOT_RECOVERED_BLOCK) == false) { | ||
| currentClusterState = event.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.
I'm not sure I quite grasp this if condition. Perhaps a comment would help?
It looks like once we've received the first event, we start ignoring STATE_NOT_RECOVERED_BLOCK. Why is that?
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.
That's the purpose. We just care about the initial recovery; after that, we consider the cluster state as available.
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.
Ok. But can STATE_NOT_RECOVERED_BLOCK happen again later, after initialization?
- If so, probably this code could use a comment explaining why we want to keep accepting new cluster states in that case but not during initialization.
- If not, then we can get rid of the
isInitializedcall.
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 it can, but we care only if the initial recovery is happened yet. I'll add a comment about that.
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.
It's hard to know whether the design makes sense without at least one use of it. Do you have a use in mind? Perhaps that could be included in this PR to make it easier to evaluate.
In general, accessing ClusterState from ClusterService directly (ClusterService#state()) is not safe, as we can't know if the state has been initialized yet. Especially if we start reading it very early (e.g. in a ctor). |
|
Note to self: |
This came up while working on serverless; we needed a "safe" way to access ClusterState, avoiding to read from it too early, with a fallback.
We saw this could be useful in more cases, so moving to server made sense.
The default implementation (which we expect to be used in most cases) implements "ready" as "is cluster state available", after the initial recovery.
I left out any binding from it; possibly, under the new DI, we might want to merge the implementation with ClusterService/add the implementation as a default listener and bind it to ClusterStateSupplier.