Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import io.javalin.Javalin;
import io.javalin.core.util.JavalinBindException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.eclipse.jetty.server.Server;
Expand Down Expand Up @@ -344,25 +345,37 @@ private int startServiceOnPort(int port) throws IOException {
// Returns port to try when trying to bind a service. Handles wrapping and skipping privileged ports.
int tryPort = port == 0 ? port : (port + attempt - 1024) % (65536 - 1024) + 1024;
try {
createApp();
app.start(tryPort);
return app.port();
} catch (Exception e) {
if (e.getMessage() != null && e.getMessage().contains("Failed to bind to")) {
if (e instanceof JavalinBindException) {
if (tryPort == 0) {
LOG.warn("Timeline server could not bind on a random free port.");
LOG.warn("Timeline server could not bind on port {}. Attempting port {} + 1.", tryPort, tryPort);
} 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);
LOG.warn("Timeline server start failed on port {}. Attempting port {} + 1.", tryPort, tryPort, e);
}
}
}
throw new IOException(String.format("Timeline server start failed on port %d, after retry %d times", port, START_SERVICE_MAX_RETRIES));
}

public int startService() throws IOException {
int realServerPort = startServiceOnPort(serverPort);
LOG.info("Starting Timeline server on port: {}", realServerPort);
this.serverPort = realServerPort;
return realServerPort;
}

private void createApp() throws IOException {
// if app needs to be recreated, stop the existing one
if (app != null) {
app.stop();
}
int maxThreads = timelineServerConf.numThreads > 0 ? timelineServerConf.numThreads : DEFAULT_NUM_THREADS;
QueuedThreadPool pool = new QueuedThreadPool(maxThreads, 8, 60_000);
pool.setDaemon(true);
Expand All @@ -381,10 +394,6 @@ public int startService() throws IOException {
app, conf, timelineServerConf, context, fs, fsViewsManager);
app.get("/", ctx -> ctx.result("Hello Hudi"));
requestHandler.register();
int realServerPort = startServiceOnPort(serverPort);
LOG.info("Starting Timeline server on port :" + realServerPort);
this.serverPort = realServerPort;
return realServerPort;
}

public void run() throws IOException {
Expand Down
Loading