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

Tests: check node ports availability when using unicast discovery #9886

Merged
merged 1 commit into from
Feb 27, 2015

Conversation

jaymode
Copy link
Member

@jaymode jaymode commented Feb 25, 2015

Some tests failures are seen when a node attempts to use a port that is already bound
by some other process on the test machine. This commit adds a bind to test port availability
and iterates over the port range until an available port is found. This reduces the likelihood
of a test node failing to start up due to the port already being bound.

@jaymode jaymode added >test Issues or PRs that are addressing/adding tests v2.0.0-beta1 review v1.5.0 labels Feb 25, 2015
protected static int[] unicastHostPorts(int basePort, int numHosts) {
int[] unicastHostPorts = new int[numHosts];

final int maxPort = basePort + 99;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can increase the 99 range to 1000 and also change calcBasePort to ignore the scope component as it is not relevant any more. I want if we should jut remember the last based port and continue from it (round robin-ing) to make in-JVM collisions less likely

@bleskes
Copy link
Contributor

bleskes commented Feb 25, 2015

I like it. Left some comments. Thx for picking it up.

@bleskes bleskes removed the review label Feb 25, 2015
@jaymode
Copy link
Member Author

jaymode commented Feb 26, 2015

@bleskes thanks for the feedback. I implemented the changes to have a port range of 1000 and to cycle through the range.

@jaymode jaymode added the review label Feb 26, 2015
}

if (!foundPortInRange) {
throw new ElasticsearchException("could not find enough open ports in range [" + basePort + "-" + maxPort + "]");
Copy link
Contributor

Choose a reason for hiding this comment

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

can we also note how ports are required?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure something like could not find enough open ports in range [30000 - 31000]. required [8] open ports; one for each node to bind for tcp transport ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's enough to say could not find enough open ports in range [30000 - 31000]. required [8].

@bleskes
Copy link
Contributor

bleskes commented Feb 27, 2015

thx @jaymode - I wonder if we should remember the last port we used and start looking from there? now we start looking from baseport every time so it's likely the first ports we try are still not freed up?

@jaymode
Copy link
Member Author

jaymode commented Feb 27, 2015

@bleskes we start from nextPort which is a static variable. First time the class is initialized, it is set to the base port. While looking for ports, we increment nextPort for every try. On the next invocation this class will continue iterating up the port range starting from the port after the last one that was used. Do you see something else that I'm missing?

@@ -61,24 +63,25 @@ public Settings transportClient() {

public static class UnicastZen extends ClusterDiscoveryConfiguration {

private static final AtomicInteger portCounter = new AtomicInteger();
private static int nextPort = calcBasePort();
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a comment that this the next port we will try to assign and that it is advanced with every attempt?

@bleskes
Copy link
Contributor

bleskes commented Feb 27, 2015

@jaymode I see I missed it. I left some minor comments.

@jaymode
Copy link
Member Author

jaymode commented Feb 27, 2015

@bleskes updated with the feedback

@bleskes
Copy link
Contributor

bleskes commented Feb 27, 2015

LGTM thx!

Some tests failures are seen when a node attempts to use a port that is already bound
by some other process on the test machine. This commit adds a bind to test port availability
and iterates over the port range until an available port is found. This reduces the likelihood
of a test node failing to start up due to the port already being bound.
@jaymode jaymode merged commit efbda31 into elastic:master Feb 27, 2015
@jaymode jaymode removed the review label Feb 27, 2015
@jaymode jaymode deleted the fix/test_unicast_node_ports branch March 16, 2015 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>test Issues or PRs that are addressing/adding tests v1.5.0 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants