Skip to content

Conversation

@ldematte
Copy link
Contributor

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.

@ldematte ldematte added >non-issue :Core/Infra/Core Core issues without another label v9.0.0 labels Oct 30, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Oct 30, 2024
@ldematte ldematte requested a review from a team October 30, 2024 12:12
@ldematte
Copy link
Contributor Author

@elasticmachine update branch

@ldematte ldematte requested a review from a team November 4, 2024 13:15
@Override
public void clusterChanged(ClusterChangedEvent event) {
if (isInitialized() || event.state().blocks().hasGlobalBlock(STATE_NOT_RECOVERED_BLOCK) == false) {
currentClusterState = event.state();
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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 isInitialized call.

Copy link
Contributor Author

@ldematte ldematte Nov 4, 2024

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.

Copy link
Contributor

@prdoyle prdoyle left a 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.

@ldematte
Copy link
Contributor Author

ldematte commented Nov 4, 2024

Do you have a use in mind?

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).
My usage is in serverless, but I'll try to find another one in the ES codebase.

@ldematte
Copy link
Contributor Author

ldematte commented Nov 4, 2024

Note to self: TransformClusterStateListener (TransformNode, really) and LocalExporter seem good candidates to use this; especially the first one, but will need some changes. Better be done in a follow-up.

@ldematte ldematte merged commit 6911227 into elastic:main Nov 4, 2024
16 checks passed
@ldematte ldematte deleted the cluster-state-supplier branch November 4, 2024 18:07
alexey-ivanov-es pushed a commit to alexey-ivanov-es/elasticsearch that referenced this pull request Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants