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

[native] Replace fixed test worker port with ephemeral ports #22748

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion presto-docs/src/main/sphinx/installation/deployment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ These properties require some explanation:

* ``http-server.http.port``:
Specifies the port for the HTTP server. Presto uses HTTP for all
communication, internal and external.
communication, internal and external. If the value is set to 0 an ephemeral port is used.

* ``query.max-memory``:
The maximum amount of distributed memory that a query may use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ To enable SSL/TLS for Presto internal communication, do the following:
http-server.https.keystore.path=<keystore path>
http-server.https.keystore.key=<keystore password>

Note: setting the ``http-server.https.port`` to ``0`` results in the use of an ephemeral port.

6. Change the discovery uri to HTTPS.

.. code-block:: none
Expand Down
111 changes: 73 additions & 38 deletions presto-native-execution/presto_cpp/main/PrestoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,35 +297,6 @@ void PrestoServer::run() {
address_);

initializeCoordinatorDiscoverer();
if (coordinatorDiscoverer_ != nullptr) {
announcer_ = std::make_unique<Announcer>(
address_,
httpsPort.has_value(),
httpsPort.has_value() ? httpsPort.value() : httpPort,
coordinatorDiscoverer_,
nodeVersion_,
environment_,
nodeId_,
nodeLocation_,
systemConfig->prestoNativeSidecar(),
catalogNames,
systemConfig->announcementMaxFrequencyMs(),
sslContext_);
updateAnnouncerDetails();
announcer_->start();

uint64_t heartbeatFrequencyMs = systemConfig->heartbeatFrequencyMs();
if (heartbeatFrequencyMs > 0) {
heartbeatManager_ = std::make_unique<PeriodicHeartbeatManager>(
address_,
httpsPort.has_value() ? httpsPort.value() : httpPort,
coordinatorDiscoverer_,
sslContext_,
[server = this]() { return server->fetchNodeStatus(); },
heartbeatFrequencyMs);
heartbeatManager_->start();
}
}

const bool reusePort = SystemConfig::instance()->httpServerReusePort();
auto httpConfig =
Expand Down Expand Up @@ -490,14 +461,6 @@ void PrestoServer::run() {
registerSidecarEndpoints();
}

std::string taskUri;
if (httpsPort.has_value()) {
taskUri = fmt::format(kTaskUriFormat, kHttps, address_, httpsPort.value());
} else {
taskUri = fmt::format(kTaskUriFormat, kHttp, address_, httpPort);
}

taskManager_->setBaseUri(taskUri);
taskManager_->setNodeId(nodeId_);
taskManager_->setOldTaskCleanUpMs(systemConfig->oldTaskCleanUpMs());

Expand Down Expand Up @@ -587,9 +550,81 @@ void PrestoServer::run() {

addMemoryCheckerPeriodicTask();

auto setTaskUriCb = [&](bool useHttps, int port) {
std::string taskUri;
if (useHttps) {
taskUri = fmt::format(kTaskUriFormat, kHttps, address_, port);
} else {
taskUri = fmt::format(kTaskUriFormat, kHttp, address_, port);
}
taskManager_->setBaseUri(taskUri);
};

auto startAnnouncerAndHeartbeatManagerCb = [&](bool useHttps, int port) {
if (coordinatorDiscoverer_ != nullptr) {
announcer_ = std::make_unique<Announcer>(
address_,
useHttps,
port,
coordinatorDiscoverer_,
nodeVersion_,
environment_,
nodeId_,
nodeLocation_,
systemConfig->prestoNativeSidecar(),
catalogNames,
systemConfig->announcementMaxFrequencyMs(),
sslContext_);
updateAnnouncerDetails();
announcer_->start();

uint64_t heartbeatFrequencyMs = systemConfig->heartbeatFrequencyMs();
if (heartbeatFrequencyMs > 0) {
heartbeatManager_ = std::make_unique<PeriodicHeartbeatManager>(
address_,
port,
coordinatorDiscoverer_,
sslContext_,
[server = this]() { return server->fetchNodeStatus(); },
heartbeatFrequencyMs);
heartbeatManager_->start();
}
}
};

// Start everything. After the return from the following call we are shutting
// down.
httpServer_->start(getHttpServerFilters());
httpServer_->start(getHttpServerFilters(), [&](proxygen::HTTPServer* server) {
const auto addresses = server->addresses();
for (auto address : addresses) {
PRESTO_STARTUP_LOG(INFO) << fmt::format(
"Server listening at {}:{} - https {}",
address.address.getIPAddress().str(),
address.address.getPort(),
address.sslConfigs.size() != 0);
// We could be bound to both http and https ports.
// If set, we must use the https port and skip http.
if (httpsPort.has_value() && address.sslConfigs.size() == 0) {
continue;
}
startAnnouncerAndHeartbeatManagerCb(
httpsPort.has_value(), address.address.getPort());
setTaskUriCb(httpsPort.has_value(), address.address.getPort());
break;
}

if (coordinatorDiscoverer_ != nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Leave an empty line?

VELOX_CHECK_NOT_NULL(
announcer_,
"The announcer is expected to have been created but wasn't.");
const auto heartbeatFrequencyMs = systemConfig->heartbeatFrequencyMs();
if (heartbeatFrequencyMs > 0) {
VELOX_CHECK_NOT_NULL(
heartbeatManager_,
"The heartbeat manager is expected to have been created but wasn't.");
}
}
});

if (announcer_ != nullptr) {
PRESTO_SHUTDOWN_LOG(INFO) << "Stopping announcer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,12 @@ public static Optional<BiFunction<Integer, URI, Process>> getExternalWorkerLaunc
Files.createDirectories(dir);
Path tempDirectoryPath = Files.createTempDirectory(dir, "worker");
log.info("Temp directory for Worker #%d: %s", workerIndex, tempDirectoryPath.toString());
int port = 1234 + workerIndex;

// Write config file
// Write config file - use an ephemeral port for the worker.
String configProperties = format("discovery.uri=%s%n" +
"presto.version=testversion%n" +
"system-memory-gb=4%n" +
"http-server.http.port=%d", discoveryUri, port);
"http-server.http.port=0%n", discoveryUri);

if (isCoordinatorSidecarEnabled) {
configProperties = format("%s%n" +
Expand Down
Loading