From b1088c7aae751c28f39ef551e1d4bf2f7599bcb3 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 2 May 2017 13:01:25 +0200 Subject: Ensure that we have gotten config at least once before starting up. --- config/src/vespa/config/helper/configfetcher.cpp | 2 +- config/src/vespa/config/helper/configfetcher.h | 3 +-- .../src/apps/filedistributor/filedistributor.cpp | 24 ++++++++++++---------- .../distributor/signalhandling.cpp | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/config/src/vespa/config/helper/configfetcher.cpp b/config/src/vespa/config/helper/configfetcher.cpp index f6e39523900..acb41abbadb 100644 --- a/config/src/vespa/config/helper/configfetcher.cpp +++ b/config/src/vespa/config/helper/configfetcher.cpp @@ -1,8 +1,8 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "configfetcher.h" #include LOG_SETUP(".config.helper.configfetcher"); -#include "configfetcher.h" namespace config { diff --git a/config/src/vespa/config/helper/configfetcher.h b/config/src/vespa/config/helper/configfetcher.h index ad7c2a8b549..ed04dc62f50 100644 --- a/config/src/vespa/config/helper/configfetcher.h +++ b/config/src/vespa/config/helper/configfetcher.h @@ -1,11 +1,10 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once +#include "configpoller.h" #include #include #include -#include "configpoller.h" - #include namespace config { diff --git a/filedistribution/src/apps/filedistributor/filedistributor.cpp b/filedistribution/src/apps/filedistributor/filedistributor.cpp index 452b951bf6b..aac12610bd1 100644 --- a/filedistribution/src/apps/filedistributor/filedistributor.cpp +++ b/filedistribution/src/apps/filedistributor/filedistributor.cpp @@ -1,25 +1,20 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root -#include - -#include -#include - -#include #include #include #include #include -#include #include #include #include #include -#include #include -#include +#include +#include +#include +#include namespace { const char* programName = "filedistributor"; @@ -182,7 +177,14 @@ public: } } + bool incompleteConfig() { + LockGuard guard(_configMutex); + return ! (_zooKeepersConfig && _fileDistributorConfig && _rpcConfig); + } void createComponents(const config::ConfigUri & configUri) { + while (incompleteConfig()) { + std::this_thread::sleep_for(10ms); + } LockGuard guard(_configMutex); _components.reset( new Components(configUri, @@ -219,8 +221,8 @@ public: (postPoneAskedToReinitializedSecs > 0 || !askedToReinitialize()) && !completeReconfigurationNeeded()) { - postPoneAskedToReinitializedSecs--; - std::this_thread::sleep_for(1s); + postPoneAskedToReinitializedSecs--; + std::this_thread::sleep_for(1s); } _components.reset(); } diff --git a/filedistribution/src/vespa/filedistribution/distributor/signalhandling.cpp b/filedistribution/src/vespa/filedistribution/distributor/signalhandling.cpp index 0465f8d7b29..9ac658ba619 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/signalhandling.cpp +++ b/filedistribution/src/vespa/filedistribution/distributor/signalhandling.cpp @@ -1,5 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include + #include "signalhandling.h" #include -- cgit v1.2.3 From a4ac50b4cfaa24f0d3252b6c536b55f95d1a2e5a Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 4 May 2017 10:56:25 +0200 Subject: Whitespace ++ --- config/src/vespa/config/helper/configfetcher.cpp | 1 + vespalib/src/vespa/vespalib/util/signalhandler.cpp | 5 ++--- vespalib/src/vespa/vespalib/util/signalhandler.h | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/config/src/vespa/config/helper/configfetcher.cpp b/config/src/vespa/config/helper/configfetcher.cpp index acb41abbadb..0a4b95e9153 100644 --- a/config/src/vespa/config/helper/configfetcher.cpp +++ b/config/src/vespa/config/helper/configfetcher.cpp @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "configfetcher.h" + #include LOG_SETUP(".config.helper.configfetcher"); diff --git a/vespalib/src/vespa/vespalib/util/signalhandler.cpp b/vespalib/src/vespa/vespalib/util/signalhandler.cpp index f16ef55fc30..c0456ca9cef 100644 --- a/vespalib/src/vespa/vespalib/util/signalhandler.cpp +++ b/vespalib/src/vespa/vespalib/util/signalhandler.cpp @@ -12,8 +12,7 @@ namespace { class Shutdown { public: - ~Shutdown(void) - { + ~Shutdown() { SignalHandler::shutdown(); } }; @@ -106,7 +105,7 @@ SignalHandler::unhook() void -SignalHandler::shutdown(void) +SignalHandler::shutdown() { for (std::vector::iterator it = _handlers.begin(), ite = _handlers.end(); diff --git a/vespalib/src/vespa/vespalib/util/signalhandler.h b/vespalib/src/vespa/vespalib/util/signalhandler.h index 3ac7926531f..a5a474bb471 100644 --- a/vespalib/src/vespa/vespalib/util/signalhandler.h +++ b/vespalib/src/vespa/vespalib/util/signalhandler.h @@ -59,8 +59,9 @@ private: * initialization. **/ SignalHandler(int signal); - SignalHandler(const SignalHandler &); // not defined - SignalHandler &operator=(const SignalHandler &); // not defined + + SignalHandler(const SignalHandler &) = delete; + SignalHandler &operator=(const SignalHandler &) = delete; public: static SignalHandler HUP; @@ -103,8 +104,7 @@ public: **/ void unhook(); - static void - shutdown(void); + static void shutdown(); }; } // vespalib -- cgit v1.2.3 From c3ca3db96ee29df4b3ba5d4285a4be3187198e41 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 4 May 2017 14:30:24 +0200 Subject: incompleteConfig -> isConfigComplete and invert logic and move to Main. --- .../src/apps/filedistributor/filedistributor.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/filedistribution/src/apps/filedistributor/filedistributor.cpp b/filedistribution/src/apps/filedistributor/filedistributor.cpp index aac12610bd1..222f157b8e4 100644 --- a/filedistribution/src/apps/filedistributor/filedistributor.cpp +++ b/filedistribution/src/apps/filedistributor/filedistributor.cpp @@ -177,14 +177,11 @@ public: } } - bool incompleteConfig() { + bool isConfigComplete() { LockGuard guard(_configMutex); - return ! (_zooKeepersConfig && _fileDistributorConfig && _rpcConfig); + return (_zooKeepersConfig && _fileDistributorConfig && _rpcConfig); } void createComponents(const config::ConfigUri & configUri) { - while (incompleteConfig()) { - std::this_thread::sleep_for(10ms); - } LockGuard guard(_configMutex); _components.reset( new Components(configUri, @@ -259,8 +256,7 @@ bool exists(const std::string& optionName, const boost::program_options::variabl return map.find(optionName) != map.end(); } -void ensureExists(const std::string& optionName, const boost::program_options::variables_map& map \ - ) { +void ensureExists(const std::string& optionName, const boost::program_options::variables_map& map ) { if (!exists(optionName, map)) { throw ProgramOptionException("Error: Missing option " + optionName); } @@ -284,6 +280,9 @@ FileDistributorApplication::Main() { configFetcher.subscribeGenerationChanges(&distributor); configFetcher.start(); + while (! distributor.isConfigComplete() ) { + std::this_thread::sleep_for(10ms); + } distributor.run(_configUri); EV_STOPPING(programName, "Clean exit"); -- cgit v1.2.3