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

Make DiscoveryNodes#mastersFirstStream deterministic #94948

Conversation

DaveCTurner
Copy link
Contributor

Today the CoordinatorTests test suite is not totally deterministic because its behaviour depends on the iteration order of the JDK's unordered collections which are not under the control of our test seed.

This commit makes DiscoveryNodes#mastersFirstStream yield the nodes in a deterministic order, which addresses one such area of unreproducibility. It's an ugly hack to do some extra work in production just for the sake of tests, but we're only sorting at most a few hundred elements here so it's not a huge deal.

Relates #94946

Today the `CoordinatorTests` test suite is not totally deterministic
because its behaviour depends on the iteration order of the JDK's
unordered collections which are not under the control of our test seed.

This commit makes `DiscoveryNodes#mastersFirstStream` yield the nodes in
a deterministic order, which addresses one such area of
unreproducibility. It's an ugly hack to do some extra work in production
just for the sake of tests, but we're only sorting at most a few hundred
elements here so it's not a huge deal.

Relates elastic#94946
@DaveCTurner DaveCTurner added >non-issue :Distributed/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. v8.8.0 labels Mar 31, 2023
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Meta label for distributed team label Mar 31, 2023
@elasticsearchmachine
Copy link
Collaborator

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

DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Mar 31, 2023
Today the `CoordinatorTests` test suite is not totally deterministic
because its behaviour depends on the iteration order of the JDK's
unordered collections which are not under the control of our test seed.

This commit makes `NodeConnectionsService#connectToNodes` iterate
through the nodes using `DiscoveryNodes#mastersFirstStream`, which is
made deterministic by elastic#94948. It's an ugly hack to do some extra work in
production just for the sake of tests, but we're only sorting at most a
few hundred elements here so it's not a huge deal.

Relates elastic#94946
@arteam arteam self-requested a review March 31, 2023 11:37
Copy link
Contributor

@arteam arteam left a comment

Choose a reason for hiding this comment

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

LGTM with one small comment!

@@ -185,11 +186,15 @@ public Map<String, DiscoveryNode> getCoordinatingOnlyNodes() {
return filteredNodes(nodes, n -> n.canContainData() == false && n.isMasterNode() == false && n.isIngestNode() == false);
}

// Ugly hack: when https://github.com/elastic/elasticsearch/issues/94946 is fixed, remove the sorting by ephemeral ID here
private final Comparator<DiscoveryNode> MASTERS_FIRST_COMPARATOR = Comparator.<DiscoveryNode>comparingInt(n -> n.isMasterNode() ? 0 : 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe static is missed here since the comparator is stateless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah oops yes I meant static

@DaveCTurner DaveCTurner added the auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Mar 31, 2023
Copy link
Contributor

@fcofdez fcofdez left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticsearchmachine elasticsearchmachine merged commit 04e4394 into elastic:main Mar 31, 2023
@DaveCTurner DaveCTurner deleted the 2023-03-31-deterministic-mastersFirstStream branch March 31, 2023 12:42
elasticsearchmachine pushed a commit that referenced this pull request Mar 31, 2023
Today the `CoordinatorTests` test suite is not totally deterministic
because its behaviour depends on the iteration order of the JDK's
unordered collections which are not under the control of our test seed.

This commit makes `NodeConnectionsService#connectToNodes` iterate
through the nodes using `DiscoveryNodes#mastersFirstStream`, which is
made deterministic by #94948. It's an ugly hack to do some extra work in
production just for the sake of tests, but we're only sorting at most a
few hundred elements here so it's not a huge deal.

Relates #94946
rjernst pushed a commit to rjernst/elasticsearch that referenced this pull request Apr 6, 2023
Today the `CoordinatorTests` test suite is not totally deterministic
because its behaviour depends on the iteration order of the JDK's
unordered collections which are not under the control of our test seed.

This commit makes `DiscoveryNodes#mastersFirstStream` yield the nodes in
a deterministic order, which addresses one such area of
unreproducibility. It's an ugly hack to do some extra work in production
just for the sake of tests, but we're only sorting at most a few hundred
elements here so it's not a huge deal.

Relates elastic#94946
rjernst pushed a commit to rjernst/elasticsearch that referenced this pull request Apr 6, 2023
…4949)

Today the `CoordinatorTests` test suite is not totally deterministic
because its behaviour depends on the iteration order of the JDK's
unordered collections which are not under the control of our test seed.

This commit makes `NodeConnectionsService#connectToNodes` iterate
through the nodes using `DiscoveryNodes#mastersFirstStream`, which is
made deterministic by elastic#94948. It's an ugly hack to do some extra work in
production just for the sake of tests, but we're only sorting at most a
few hundred elements here so it's not a huge deal.

Relates elastic#94946
saarikabhasi pushed a commit to saarikabhasi/elasticsearch that referenced this pull request Apr 10, 2023
Today the `CoordinatorTests` test suite is not totally deterministic
because its behaviour depends on the iteration order of the JDK's
unordered collections which are not under the control of our test seed.

This commit makes `DiscoveryNodes#mastersFirstStream` yield the nodes in
a deterministic order, which addresses one such area of
unreproducibility. It's an ugly hack to do some extra work in production
just for the sake of tests, but we're only sorting at most a few hundred
elements here so it's not a huge deal.

Relates elastic#94946
saarikabhasi pushed a commit to saarikabhasi/elasticsearch that referenced this pull request Apr 10, 2023
…4949)

Today the `CoordinatorTests` test suite is not totally deterministic
because its behaviour depends on the iteration order of the JDK's
unordered collections which are not under the control of our test seed.

This commit makes `NodeConnectionsService#connectToNodes` iterate
through the nodes using `DiscoveryNodes#mastersFirstStream`, which is
made deterministic by elastic#94948. It's an ugly hack to do some extra work in
production just for the sake of tests, but we're only sorting at most a
few hundred elements here so it's not a huge deal.

Relates elastic#94946
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. >non-issue Team:Distributed Meta label for distributed team v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants