lw309637554 commented on a change in pull request #2142:
URL: https://github.com/apache/hudi/pull/2142#discussion_r499550041



##########
File path: 
hudi-timeline-service/src/main/java/org/apache/hudi/timeline/service/TimelineService.java
##########
@@ -98,16 +98,42 @@ public TimelineService(Config config) throws IOException {
     public Boolean help = false;
   }
 
+  private int startServiceOnPort(int port) throws IOException {
+    if (!(port == 0 || (1024 <= port && port < 65536))) {
+      throw new IllegalArgumentException(String.format("startPort should be 
between 1024 and 65535 (inclusive), "
+          + "or 0 for a random free port. but now is %s.", port));
+    }
+    int maxRetries = 16;
+    for (int offset = 0; offset < maxRetries; offset++) {
+      int tryPort = port == 0 ? port : (port + offset - 1024) % (65536 - 1024) 
+ 1024;

Review comment:
       done

##########
File path: 
hudi-timeline-service/src/main/java/org/apache/hudi/timeline/service/TimelineService.java
##########
@@ -98,16 +98,42 @@ public TimelineService(Config config) throws IOException {
     public Boolean help = false;
   }
 
+  private int startServiceOnPort(int port) throws IOException {
+    if (!(port == 0 || (1024 <= port && port < 65536))) {
+      throw new IllegalArgumentException(String.format("startPort should be 
between 1024 and 65535 (inclusive), "
+          + "or 0 for a random free port. but now is %s.", port));
+    }
+    int maxRetries = 16;
+    for (int offset = 0; offset < maxRetries; offset++) {
+      int tryPort = port == 0 ? port : (port + offset - 1024) % (65536 - 1024) 
+ 1024;
+      try {
+        app.start(tryPort);
+        return app.port();
+      } catch (Exception e) {
+        if (e.getMessage() != null && e.getMessage().contains("Failed to bind 
to")) {
+          if (tryPort == 0) {
+            LOG.warn("Timeline server could not bind on a random free port.");
+          } else {
+            LOG.warn(String.format("Timeline server could not bind on port %d. 
"
+                + "Attempting port %d + 1.",tryPort, tryPort));
+          }
+        } else {
+          LOG.warn(String.format("Timeline server start failed on port %d. 
Attempting port %d + 1.",tryPort, tryPort), e);
+        }
+      }
+    }
+    throw new IOException(String.format("Timeline server start failed on port 
%d, after retry %d time", port, maxRetries));

Review comment:
       done




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to