sodonnel commented on a change in pull request #2550:
URL: https://github.com/apache/ozone/pull/2550#discussion_r691027164
##########
File path:
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
##########
@@ -700,6 +701,9 @@ public void bootstrapOzoneManager(String omNodeId) throws
Exception {
while (true) {
try {
basePort = 10000 + RANDOM.nextInt(1000) * 4;
+ if (!isPortAvailable(basePort)) {
Review comment:
Rather than trying incremental ports, can we just ask the OS for a free
one, eg:
private int getFreePort() {
ServerSocket ss = null;
try {
ss = new ServerSocket(0);
return ss.getLocalPort();
} catch {
...
} finally {
if (ss != null) {
ss.close();
}
}
##########
File path:
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
##########
@@ -700,6 +701,9 @@ public void bootstrapOzoneManager(String omNodeId) throws
Exception {
while (true) {
try {
basePort = 10000 + RANDOM.nextInt(1000) * 4;
+ if (!isPortAvailable(basePort)) {
Review comment:
Rather than trying incremental ports, can we just ask the OS for a free
one, eg:
```
private int getFreePort() {
ServerSocket ss = null;
try {
ss = new ServerSocket(0);
return ss.getLocalPort();
} catch {
...
} finally {
if (ss != null) {
ss.close();
}
}
```
##########
File path:
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
##########
@@ -700,6 +701,9 @@ public void bootstrapOzoneManager(String omNodeId) throws
Exception {
while (true) {
try {
basePort = 10000 + RANDOM.nextInt(1000) * 4;
+ if (!isPortAvailable(basePort)) {
Review comment:
The discussion here suggests a few problems etc with various approaches:
https://stackoverflow.com/questions/434718/sockets-discover-port-availability-using-java
##########
File path:
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
##########
@@ -700,6 +701,9 @@ public void bootstrapOzoneManager(String omNodeId) throws
Exception {
while (true) {
try {
basePort = 10000 + RANDOM.nextInt(1000) * 4;
+ if (!isPortAvailable(basePort)) {
Review comment:
I wonder if the method could give the same port back on consecutive
calls. I guess we can try it and see.
It would be great if we could just pass port zero to OM and let it start on
a free port by itself, but I guess other things need to connect to it, so they
need the port, which would be unknown. Therefore the approach we are taking
here is likely the most sensible.
##########
File path:
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
##########
@@ -966,4 +970,31 @@ public StorageContainerManager
getStorageContainerManager() {
return getStorageContainerManagers().get(0);
}
+ private int getFreePort() {
Review comment:
It would be good to reuse `SCMTestUtils.getReusableAddress()` here
rather than creating a new version in this class. It returns an
InetSocketAddress, but we can easily get the port from it.
##########
File path:
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
##########
@@ -966,4 +970,31 @@ public StorageContainerManager
getStorageContainerManager() {
return getStorageContainerManagers().get(0);
}
+ private int getFreePort() {
+ ServerSocket ss = null;
+ try {
+ ss = new ServerSocket(0);
+ return ss.getLocalPort();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (ss != null) {
+ try {
+ ss.close();
+ } catch (IOException e) {
+ LOG.error("Got exception while closing ServerSocket: " +
+ e.getMessage());
+ }
+ }
+ }
+ return -1;
+ }
+
+ private Set<Integer> getFreePortSet(int size) {
+ Set<Integer> portSet = new HashSet<>();
+ while (portSet.size() < size) {
+ portSet.add(getFreePort());
Review comment:
If getFreePort() returns -1, then it will just add it to the set, which
will cause problems later I think?
However if we switch to use `SCMTestUtils.getReusableAddress()` then we can
handle the exception it throws and try again to get an address.
##########
File path:
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
##########
@@ -966,4 +970,31 @@ public StorageContainerManager
getStorageContainerManager() {
return getStorageContainerManagers().get(0);
}
+ private int getFreePort() {
+ ServerSocket ss = null;
+ try {
+ ss = new ServerSocket(0);
+ return ss.getLocalPort();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (ss != null) {
+ try {
+ ss.close();
+ } catch (IOException e) {
+ LOG.error("Got exception while closing ServerSocket: " +
+ e.getMessage());
+ }
+ }
+ }
+ return -1;
+ }
+
+ private Set<Integer> getFreePortSet(int size) {
+ Set<Integer> portSet = new HashSet<>();
+ while (portSet.size() < size) {
+ portSet.add(getFreePort());
Review comment:
The Ratis version is nice. It actually binds the socket and keeps it
bound while it gets the rest of the requested sockets. That means it will
return a list of unique sockets for sure, while the version we are working
with, could return duplicate ports, although that is being handled via adding
the port to the set.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]