diff --git a/presto-native-execution/etc/node.properties b/presto-native-execution/etc/node.properties index bf6abc24b6174..1d92b7ace8087 100644 --- a/presto-native-execution/etc/node.properties +++ b/presto-native-execution/etc/node.properties @@ -1,4 +1,3 @@ node.environment=testing -node.id=e4901aae-a1c9-4ff7-97a9-5687835ad54c node.internal-address=127.0.0.1 node.location=testing-location diff --git a/presto-native-execution/presto_cpp/main/common/Configs.cpp b/presto-native-execution/presto_cpp/main/common/Configs.cpp index e7bf5f367873e..5e74a2178be1d 100644 --- a/presto-native-execution/presto_cpp/main/common/Configs.cpp +++ b/presto-native-execution/presto_cpp/main/common/Configs.cpp @@ -17,6 +17,9 @@ #include "presto_cpp/main/common/Utils.h" #include "velox/core/QueryConfig.h" +#include +#include +#include #if __has_include("filesystem") #include namespace fs = std::filesystem; @@ -648,7 +651,14 @@ std::string NodeConfig::nodeEnvironment() const { } std::string NodeConfig::nodeId() const { - return requiredProperty(kNodeId); + auto resultOpt = optionalProperty(kNodeId); + if (resultOpt.hasValue()) { + return resultOpt.value(); + } + // Generate the nodeId which must be a UUID. nodeId must be a singleton. + static auto nodeId = + boost::lexical_cast(boost::uuids::random_generator()()); + return nodeId; } std::string NodeConfig::nodeLocation() const { diff --git a/presto-native-execution/presto_cpp/main/tests/CMakeLists.txt b/presto-native-execution/presto_cpp/main/tests/CMakeLists.txt index aea7e163fa483..2f03319363cc7 100644 --- a/presto-native-execution/presto_cpp/main/tests/CMakeLists.txt +++ b/presto-native-execution/presto_cpp/main/tests/CMakeLists.txt @@ -13,6 +13,7 @@ add_executable( presto_server_test AnnouncerTest.cpp CoordinatorDiscovererTest.cpp + ConfigsTest.cpp HttpServerWrapper.cpp MutableConfigs.cpp PeriodicMemoryCheckerTest.cpp diff --git a/presto-native-execution/presto_cpp/main/tests/ConfigsTest.cpp b/presto-native-execution/presto_cpp/main/tests/ConfigsTest.cpp new file mode 100644 index 0000000000000..be121181a70fa --- /dev/null +++ b/presto-native-execution/presto_cpp/main/tests/ConfigsTest.cpp @@ -0,0 +1,31 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "presto_cpp/main/common/Configs.h" + +#include + +namespace facebook::presto { +namespace { + +TEST(NodeConfig, optionalNodeId) { + NodeConfig config; + auto nodeId = config.nodeId(); + // Same value must be returned. + EXPECT_EQ(nodeId, config.nodeId()); + EXPECT_EQ(nodeId, config.nodeId()); +} + +} // namespace +} // namespace facebook::presto