-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Fix port range allocation with large worker IDs #44213
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
Relates to elastic#43983 The IDs gradle uses are incremented for the lifetime of the daemon which can result in port ranges that are outside the valid range. This change implements a modulo based formula to wrap the port ranges when the IDs get too large. Adresses elastic#44134 but elastic#44157 is also required to be able to close it.
Pinging @elastic/es-core-infra |
Pinging @elastic/es-distributed |
// See also: https://github.com/elastic/elasticsearch/issues/44134 | ||
final int startAt = Math.round( | ||
RandomizedTest.systemPropertyAsLong(ESTestCase.TEST_WORKER_VM_ID, 0) | ||
% 327L |
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 should be 223 to cater for adding 10300 below.
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've left two minor comments, looking good o.w.
// This is safe as long as we have fewer than 224 Gradle workers running in parallel | ||
// See also: https://github.com/elastic/elasticsearch/issues/44134 | ||
final int startAt = Math.round( | ||
RandomizedTest.systemPropertyAsLong(ESTestCase.TEST_WORKER_VM_ID, 0) |
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.
we can use Math.floorMod(long, int)
here instead that returns an int. This means that there's no need for Math.round
.
Also we should check that the long returned by RandomizedTest.systemPropertyAsLong(ESTestCase.TEST_WORKER_VM_ID, 0)
is non-negative.
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 actually needed because systemPropertyAsLong
actually returns a float
, seems like a bug in randomized testing, so Math.floorMod
won't work.
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.
you're using the value as system property, not the actual system property. This means that this will always return 0 at the moment. Sounds like we need a test here ;)
I think it would be simpler to write something like the following:
final int startAt = ESTestCase.TEST_WORKER_VM_ID.equals(ESTestCase.DEFAULT_TEST_WORKER_ID) ?
0 :
Math.floorMod(Long.parseLong(ESTestCase.TEST_WORKER_VM_ID), 223);
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 fixed it and added a test
return basePort + "-" + (basePort + 99); // upper bound is inclusive | ||
} | ||
|
||
public static MockNioTransport newMockTransport(Settings settings, Version version, ThreadPool threadPool) { | ||
settings = Settings.builder().put(TransportSettings.PORT.getKey(), getPortRange()).put(settings).build(); | ||
|
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.
undo this
@elasticmachine run elasticsearch-ci/2 and run elasticsearch-ci/1 |
@elasticmachine run elasticsearch-ci/fwc |
@elasticmachine run elasticsearch-ci/fwc |
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.
LGTM
* Fix port range allocation with large worker IDs Relates to #43983 The IDs gradle uses are incremented for the lifetime of the daemon which can result in port ranges that are outside the valid range. This change implements a modulo based formula to wrap the port ranges when the IDs get too large. Adresses #44134 but #44157 is also required to be able to close it.
* Fix port range allocation with large worker IDs Relates to #43983 The IDs gradle uses are incremented for the lifetime of the daemon which can result in port ranges that are outside the valid range. This change implements a modulo based formula to wrap the port ranges when the IDs get too large. Adresses #44134 but #44157 is also required to be able to close it.
Moves methods added in elastic#44213 and uses them to configure the port range for `ExternalTestCluster` too. These were still using `9300-9400` ( teh default ) and running into races.
Moves methods added in #44213 and uses them to configure the port range for `ExternalTestCluster` too. These were still using `9300-9400` ( teh default ) and running into races.
Moves methods added in #44213 and uses them to configure the port range for `ExternalTestCluster` too. These were still using `9300-9400` ( teh default ) and running into races.
Moves methods added in #44213 and uses them to configure the port range for `ExternalTestCluster` too. These were still using `9300-9400` ( teh default ) and running into races.
Relates to #43983
The IDs gradle uses are incremented for the lifetime of the daemon which
can result in port ranges that are outside the valid range.
This change implements a modulo based formula to wrap the port ranges
when the IDs get too large.
Adresses #44134 but #44157 is also required to be able to close it.