|
43 | 43 | #include "presto_cpp/main/operators/ShuffleRead.h" |
44 | 44 | #include "presto_cpp/main/types/PrestoToVeloxQueryPlan.h" |
45 | 45 | #include "presto_cpp/main/types/VeloxPlanConversion.h" |
| 46 | +#include "thrift/server/ThriftServer.h" |
46 | 47 | #include "velox/common/base/Counters.h" |
47 | 48 | #include "velox/common/base/StatsReporter.h" |
48 | 49 | #include "velox/common/caching/CacheTTLController.h" |
@@ -260,9 +261,9 @@ void PrestoServer::run() { |
260 | 261 | } |
261 | 262 |
|
262 | 263 | sslContext_ = util::createSSLContext( |
263 | | - optionalClientCertPath.value(), |
264 | | - ciphers, |
265 | | - systemConfig->httpClientHttp2Enabled()); |
| 264 | + optionalClientCertPath.value(), ciphers, util::SSLProtocol::HTTP_1_1); |
| 265 | + thriftSslContext_ = util::createSSLContext( |
| 266 | + optionalClientCertPath.value(), ciphers, util::SSLProtocol::THRIFT); |
266 | 267 | } |
267 | 268 |
|
268 | 269 | if (systemConfig->internalCommunicationJwtEnabled()) { |
@@ -619,6 +620,8 @@ void PrestoServer::run() { |
619 | 620 | } |
620 | 621 | }; |
621 | 622 |
|
| 623 | + startThriftServer(bindToNodeInternalAddressOnly, certPath, keyPath, ciphers); |
| 624 | + |
622 | 625 | // Start everything. After the return from the following call we are shutting |
623 | 626 | // down. |
624 | 627 | httpServer_->start(getHttpServerFilters(), [&](proxygen::HTTPServer* server) { |
@@ -679,6 +682,7 @@ void PrestoServer::run() { |
679 | 682 | taskManager_.reset(); |
680 | 683 | PRESTO_SHUTDOWN_LOG(INFO) << "Destroying HTTP Server"; |
681 | 684 | httpServer_.reset(); |
| 685 | + thriftServer_.reset(); |
682 | 686 |
|
683 | 687 | unregisterFileReadersAndWriters(); |
684 | 688 | unregisterFileSystems(); |
@@ -1070,6 +1074,7 @@ void PrestoServer::stop() { |
1070 | 1074 | httpServer_->stop(); |
1071 | 1075 | PRESTO_SHUTDOWN_LOG(INFO) << "HTTP Server stopped."; |
1072 | 1076 | } |
| 1077 | + shutdownThriftServer(); |
1073 | 1078 | } |
1074 | 1079 |
|
1075 | 1080 | size_t PrestoServer::numDriverThreads() const { |
@@ -1492,7 +1497,7 @@ void PrestoServer::enableWorkerStatsReporting() { |
1492 | 1497 |
|
1493 | 1498 | void PrestoServer::initVeloxPlanValidator() { |
1494 | 1499 | VELOX_CHECK_NULL(planValidator_); |
1495 | | - planValidator_ = std::make_unique<VeloxPlanValidator>(); |
| 1500 | + planValidator_ = std::make_shared<VeloxPlanValidator>(); |
1496 | 1501 | } |
1497 | 1502 |
|
1498 | 1503 | VeloxPlanValidator* PrestoServer::getVeloxPlanValidator() { |
@@ -1793,6 +1798,70 @@ void PrestoServer::createTaskManager() { |
1793 | 1798 | driverExecutor_.get(), httpSrvCpuExecutor_.get(), spillerExecutor_.get()); |
1794 | 1799 | } |
1795 | 1800 |
|
| 1801 | +void PrestoServer::startThriftServer( |
| 1802 | + bool bindToNodeInternalAddressOnly, |
| 1803 | + const std::string& certPath, |
| 1804 | + const std::string& keyPath, |
| 1805 | + const std::string& ciphers) { |
| 1806 | + auto* systemConfig = SystemConfig::instance(); |
| 1807 | + bool thriftServerEnabled = systemConfig->thriftServerEnabled(); |
| 1808 | + |
| 1809 | + if (thriftServerEnabled) { |
| 1810 | + std::unique_ptr<thrift::ThriftConfig> thriftConfig; |
| 1811 | + folly::SocketAddress thriftAddress; |
| 1812 | + int thriftPort = systemConfig->thriftServerPort(); |
| 1813 | + if (bindToNodeInternalAddressOnly) { |
| 1814 | + thriftAddress.setFromHostPort(address_, thriftPort); |
| 1815 | + } else { |
| 1816 | + thriftAddress.setFromLocalPort(thriftPort); |
| 1817 | + } |
| 1818 | + thriftConfig = std::make_unique<thrift::ThriftConfig>( |
| 1819 | + thriftAddress, certPath, keyPath, ciphers); |
| 1820 | + thriftServer_ = std::make_unique<thrift::ThriftServer>( |
| 1821 | + std::move(thriftConfig), |
| 1822 | + httpSrvIoExecutor_, |
| 1823 | + pool_, |
| 1824 | + planValidator_, |
| 1825 | + taskManager_); |
| 1826 | + |
| 1827 | + thriftServerFuture_ = |
| 1828 | + folly::via(folly::getGlobalCPUExecutor().get()) |
| 1829 | + .thenTry([this](folly::Try<folly::Unit>) { |
| 1830 | + try { |
| 1831 | + PRESTO_STARTUP_LOG(INFO) |
| 1832 | + << "Starting Thrift server asynchronously..."; |
| 1833 | + thriftServer_->start(); |
| 1834 | + PRESTO_STARTUP_LOG(INFO) |
| 1835 | + << "Thrift server started successfully"; |
| 1836 | + } catch (const std::exception& e) { |
| 1837 | + PRESTO_STARTUP_LOG(ERROR) |
| 1838 | + << "Thrift server failed to start: " << e.what(); |
| 1839 | + throw; |
| 1840 | + } |
| 1841 | + }); |
| 1842 | + } |
| 1843 | +} |
| 1844 | + |
| 1845 | +void PrestoServer::shutdownThriftServer() { |
| 1846 | + if (thriftServer_) { |
| 1847 | + PRESTO_SHUTDOWN_LOG(INFO) << "Stopping Thrift server"; |
| 1848 | + thriftServer_->stop(); |
| 1849 | + |
| 1850 | + // Wait for Thrift server thread to complete with timeout |
| 1851 | + try { |
| 1852 | + std::move(thriftServerFuture_) |
| 1853 | + .within(std::chrono::seconds(5)) // 5-second timeout |
| 1854 | + .get(); |
| 1855 | + PRESTO_SHUTDOWN_LOG(INFO) << "Thrift server stopped gracefully"; |
| 1856 | + } catch (const std::exception& e) { |
| 1857 | + PRESTO_SHUTDOWN_LOG(WARNING) |
| 1858 | + << "Thrift server shutdown timeout or error: " << e.what(); |
| 1859 | + } |
| 1860 | + |
| 1861 | + thriftServer_.reset(); |
| 1862 | + } |
| 1863 | +} |
| 1864 | + |
1796 | 1865 | void PrestoServer::reportNodeStats(proxygen::ResponseHandler* downstream) { |
1797 | 1866 | protocol::NodeStats nodeStats; |
1798 | 1867 |
|
|
0 commit comments