Skip to content

Conversation

@DaveCTurner
Copy link
Contributor

We often call addTemporaryStateListener with the ClusterService of a
random node, or the currently elected master. This commit adds utilities
for this common pattern.

We often call `addTemporaryStateListener` with the `ClusterService` of a
random node, or the currently elected master. This commit adds utilities
for this common pattern.
@DaveCTurner DaveCTurner added >test Issues or PRs that are addressing/adding tests :Distributed Coordination/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. auto-backport Automatically create backport pull requests when merged v8.19.0 v9.1.0 labels Mar 26, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Coordination Meta label for Distributed Coordination team label Mar 26, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination)

* belongs to the chosen node's {@link ClusterService}.
*/
public static SubscribableListener<Void> addTemporaryStateListener(Predicate<ClusterState> predicate) {
return addTemporaryStateListener(ESIntegTestCase.internalCluster().clusterService(), predicate);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, for some reason I assumed ESIntegTestCase#internalCluster() was only available in ESIntegTestCase and descendants. Realizing it's publicly available, I definitely agree we should try to keep utility methods outside of ESIntegTestCase as that class is already huge. I'll move the data stream utility methods I recently added in ESIntegTestCase to a different class sometime.

* {@link ESTestCase#SAFE_AWAIT_TIMEOUT} then the listener is completed exceptionally on the scheduler thread that belongs to
* the elected master node's {@link ClusterService}.
*/
public static SubscribableListener<Void> addMasterTemporaryStateListener(Predicate<ClusterState> predicate) {
Copy link
Contributor

Choose a reason for hiding this comment

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

++ on explicitly mentioning master in the method name. Should we mention randomNode (or something similar) in the other method? You're updating those usages anyway, so it won't result in a lot more changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Conventionally we don't say randomNode in these things (or else we'd say it almost everywhere). I'm going to stick with that, but if we changed it everywhere then that'd be ok too :)

@nielsbauman
Copy link
Contributor

Thanks, David!

@DaveCTurner DaveCTurner added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Mar 26, 2025
@elasticsearchmachine elasticsearchmachine merged commit 4009599 into elastic:main Mar 26, 2025
17 checks passed
@DaveCTurner DaveCTurner deleted the 2025/03/26/addTemporaryStateListener-utils branch March 26, 2025 10:15
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 125648

DaveCTurner added a commit that referenced this pull request Mar 26, 2025
We often call `addTemporaryStateListener` with the `ClusterService` of a
random node, or the currently elected master. This commit adds utilities
for this common pattern.
omricohenn pushed a commit to omricohenn/elasticsearch that referenced this pull request Mar 28, 2025
We often call `addTemporaryStateListener` with the `ClusterService` of a
random node, or the currently elected master. This commit adds utilities
for this common pattern.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed Coordination/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. Team:Distributed Coordination Meta label for Distributed Coordination team >test Issues or PRs that are addressing/adding tests v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants