From 91c764b68aad5a9848493b3d3dc81119b1178a4b Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Mon, 24 Oct 2022 11:30:00 +0200 Subject: Move related non-local variables to same translation unit to ensure ordered dynamic initialization. --- vdslib/src/vespa/vdslib/state/CMakeLists.txt | 1 + vdslib/src/vespa/vdslib/state/clusterstate.cpp | 10 ++++++---- vdslib/src/vespa/vdslib/state/globals.cpp | 24 ++++++++++++++++++++++++ vdslib/src/vespa/vdslib/state/globals.h | 13 +++++++++++++ vdslib/src/vespa/vdslib/state/state.cpp | 8 -------- 5 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 vdslib/src/vespa/vdslib/state/globals.cpp create mode 100644 vdslib/src/vespa/vdslib/state/globals.h diff --git a/vdslib/src/vespa/vdslib/state/CMakeLists.txt b/vdslib/src/vespa/vdslib/state/CMakeLists.txt index 8d4e994da93..49f1c942724 100644 --- a/vdslib/src/vespa/vdslib/state/CMakeLists.txt +++ b/vdslib/src/vespa/vdslib/state/CMakeLists.txt @@ -1,6 +1,7 @@ # Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. vespa_add_library(vdslib_state OBJECT SOURCES + globals.cpp nodetype.cpp node.cpp state.cpp diff --git a/vdslib/src/vespa/vdslib/state/clusterstate.cpp b/vdslib/src/vespa/vdslib/state/clusterstate.cpp index e58389e1475..e9159eef631 100644 --- a/vdslib/src/vespa/vdslib/state/clusterstate.cpp +++ b/vdslib/src/vespa/vdslib/state/clusterstate.cpp @@ -1,5 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "clusterstate.h" +#include "globals.h" #include #include @@ -13,6 +14,11 @@ LOG_SETUP(".vdslib.state.cluster"); using vespalib::IllegalArgumentException; +using storage::lib::clusterstate::_G_defaultSDState; +using storage::lib::clusterstate::_G_defaultDDState; +using storage::lib::clusterstate::_G_defaultSUState; +using storage::lib::clusterstate::_G_defaultDUState; + namespace storage::lib { ClusterState::ClusterState() @@ -266,10 +272,6 @@ ClusterState::getNodeCount(const NodeType& type) const } namespace { - NodeState _G_defaultSDState(NodeType::STORAGE, State::DOWN); - NodeState _G_defaultDDState(NodeType::DISTRIBUTOR, State::DOWN); - NodeState _G_defaultSUState(NodeType::STORAGE, State::UP); - NodeState _G_defaultDUState(NodeType::DISTRIBUTOR, State::UP); [[noreturn]] void throwUnknownType(const Node & node) __attribute__((noinline)); void throwUnknownType(const Node & node) { throw vespalib::IllegalStateException("Unknown node type " + node.getType().toString(), VESPA_STRLOC); diff --git a/vdslib/src/vespa/vdslib/state/globals.cpp b/vdslib/src/vespa/vdslib/state/globals.cpp new file mode 100644 index 00000000000..08c314e70f9 --- /dev/null +++ b/vdslib/src/vespa/vdslib/state/globals.cpp @@ -0,0 +1,24 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "globals.h" + +namespace storage::lib { + +const State State::UNKNOWN("Unknown", "-", 0, true, true, false, false, false); +const State State::MAINTENANCE("Maintenance", "m", 1, false, false, true, true, false); +const State State::DOWN("Down", "d", 2, false, false, true, true, true); +const State State::STOPPING("Stopping", "s", 3, true, true, false, false, true); +const State State::INITIALIZING("Initializing", "i", 4, true, true, false, false, true); +const State State::RETIRED("Retired", "r", 5, false, false, true, true, false); +const State State::UP("Up", "u", 6, true, true, true, true, true); + +} + +namespace storage::lib::clusterstate { + +NodeState _G_defaultSDState(NodeType::STORAGE, State::DOWN); +NodeState _G_defaultDDState(NodeType::DISTRIBUTOR, State::DOWN); +NodeState _G_defaultSUState(NodeType::STORAGE, State::UP); +NodeState _G_defaultDUState(NodeType::DISTRIBUTOR, State::UP); + +} diff --git a/vdslib/src/vespa/vdslib/state/globals.h b/vdslib/src/vespa/vdslib/state/globals.h new file mode 100644 index 00000000000..e3a88e6abfa --- /dev/null +++ b/vdslib/src/vespa/vdslib/state/globals.h @@ -0,0 +1,13 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "state.h" +#include "nodestate.h" + +namespace storage::lib::clusterstate { + +extern NodeState _G_defaultSDState; +extern NodeState _G_defaultDDState; +extern NodeState _G_defaultSUState; +extern NodeState _G_defaultDUState; + +} diff --git a/vdslib/src/vespa/vdslib/state/state.cpp b/vdslib/src/vespa/vdslib/state/state.cpp index e8f243b1a1e..ffa25c5a543 100644 --- a/vdslib/src/vespa/vdslib/state/state.cpp +++ b/vdslib/src/vespa/vdslib/state/state.cpp @@ -6,14 +6,6 @@ namespace storage::lib { -const State State::UNKNOWN("Unknown", "-", 0, true, true, false, false, false); -const State State::MAINTENANCE("Maintenance", "m", 1, false, false, true, true, false); -const State State::DOWN("Down", "d", 2, false, false, true, true, true); -const State State::STOPPING("Stopping", "s", 3, true, true, false, false, true); -const State State::INITIALIZING("Initializing", "i", 4, true, true, false, false, true); -const State State::RETIRED("Retired", "r", 5, false, false, true, true, false); -const State State::UP("Up", "u", 6, true, true, true, true, true); - const State& State::get(vespalib::stringref serialized) { -- cgit v1.2.3