summaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahoo-inc.com>2017-06-09 13:16:39 +0200
committerGitHub <noreply@github.com>2017-06-09 13:16:39 +0200
commita39b8e183f2b5fe231e0048e98e6009cb0365399 (patch)
treeb50e39106da93dce6f8155ccb36193bcb6acf444 /config
parent99a2274bb2e9774993f39c0c19b41efefe6861a5 (diff)
parent2929989c55e8c01247223955ca15f03cca7fa84f (diff)
Merge pull request #2681 from yahoo/balder/restart-on-messagebus-port-change
Balder/restart on messagebus port change
Diffstat (limited to 'config')
-rw-r--r--config/src/tests/configfetcher/configfetcher.cpp3
-rw-r--r--config/src/tests/configparser/configparser.cpp1
-rw-r--r--config/src/tests/configretriever/configretriever.cpp1
-rw-r--r--config/src/tests/file_subscription/file_subscription.cpp1
-rw-r--r--config/src/tests/functiontest/functiontest.cpp1
-rw-r--r--config/src/tests/subscriber/subscriber.cpp9
-rw-r--r--config/src/vespa/config/common/configparser.cpp6
-rw-r--r--config/src/vespa/config/common/configparser.h5
-rw-r--r--config/src/vespa/config/helper/configfetcher.cpp15
-rw-r--r--config/src/vespa/config/helper/configfetcher.h10
-rw-r--r--config/src/vespa/config/print/fileconfigsnapshotreader.cpp6
-rw-r--r--config/src/vespa/config/print/fileconfigsnapshotwriter.cpp3
-rw-r--r--config/src/vespa/config/retriever/configretriever.cpp2
-rw-r--r--config/src/vespa/config/retriever/configsnapshot.cpp50
-rw-r--r--config/src/vespa/config/retriever/configsnapshot.h13
-rw-r--r--config/src/vespa/config/retriever/configsnapshot.hpp14
16 files changed, 77 insertions, 63 deletions
diff --git a/config/src/tests/configfetcher/configfetcher.cpp b/config/src/tests/configfetcher/configfetcher.cpp
index 02d90352f69..eab2e8a8c84 100644
--- a/config/src/tests/configfetcher/configfetcher.cpp
+++ b/config/src/tests/configfetcher/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 <vespa/vespalib/testkit/test_kit.h>
#include <vespa/config/helper/configfetcher.h>
+#include <vespa/vespalib/util/exception.h>
#include <fstream>
#include "config-my.h"
#include <atomic>
@@ -151,7 +152,7 @@ TEST_F("verify that config generation can be obtained from config fetcher", Conf
if (cb._configured) {
break;
}
- FastOS_Thread::Sleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));;
}
EXPECT_EQUAL(2, fetcher.getGeneration());
EXPECT_EQUAL("bar", cb._config.get()->myField);
diff --git a/config/src/tests/configparser/configparser.cpp b/config/src/tests/configparser/configparser.cpp
index 40c0a5b99bd..f9e36a11def 100644
--- a/config/src/tests/configparser/configparser.cpp
+++ b/config/src/tests/configparser/configparser.cpp
@@ -2,6 +2,7 @@
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/config/config.h>
#include <vespa/config/common/configparser.h>
+#include <vespa/config/common/exceptions.h>
#include "config-foo.h"
#include <fstream>
#include <vespa/vespalib/stllike/asciistream.h>
diff --git a/config/src/tests/configretriever/configretriever.cpp b/config/src/tests/configretriever/configretriever.cpp
index 8273eee2c73..8e2d38e3c4d 100644
--- a/config/src/tests/configretriever/configretriever.cpp
+++ b/config/src/tests/configretriever/configretriever.cpp
@@ -9,6 +9,7 @@
#include <vespa/config/retriever/simpleconfigurer.h>
#include <vespa/config/common/configholder.h>
#include <vespa/config/subscription/configsubscription.h>
+#include <vespa/config/common/exceptions.h>
#include "config-bootstrap.h"
#include "config-foo.h"
#include "config-bar.h"
diff --git a/config/src/tests/file_subscription/file_subscription.cpp b/config/src/tests/file_subscription/file_subscription.cpp
index 622610ac1b5..25d27bcf905 100644
--- a/config/src/tests/file_subscription/file_subscription.cpp
+++ b/config/src/tests/file_subscription/file_subscription.cpp
@@ -3,6 +3,7 @@
#include <vespa/config/config.h>
#include <vespa/config/common/configholder.h>
#include <vespa/config/file/filesource.h>
+#include <vespa/config/common/exceptions.h>
#include <vespa/vespalib/util/sync.h>
#include <fstream>
#include <config-my.h>
diff --git a/config/src/tests/functiontest/functiontest.cpp b/config/src/tests/functiontest/functiontest.cpp
index 28b688c189e..34429ab4016 100644
--- a/config/src/tests/functiontest/functiontest.cpp
+++ b/config/src/tests/functiontest/functiontest.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 <vespa/config/config.h>
+#include <vespa/config/common/exceptions.h>
#include "config-function-test.h"
#include <fstream>
diff --git a/config/src/tests/subscriber/subscriber.cpp b/config/src/tests/subscriber/subscriber.cpp
index 3bae5ed85b1..ce9a8fcbb6a 100644
--- a/config/src/tests/subscriber/subscriber.cpp
+++ b/config/src/tests/subscriber/subscriber.cpp
@@ -4,6 +4,7 @@
#include <vespa/config/common/misc.h>
#include <vespa/config/common/configholder.h>
#include <vespa/config/subscription/configsubscription.h>
+#include <vespa/config/common/exceptions.h>
#include <fstream>
#include "config-foo.h"
#include "config-bar.h"
@@ -281,9 +282,9 @@ TEST_MT_FFF("requireThatConfigIsReturnedWhenUpdatedDuringNextConfig", 2, MyManag
verifyConfig("foo2", f3.h1->getConfig());
verifyConfig("bar", f3.h2->getConfig());
} else {
- FastOS_Thread::Sleep(300);
+ std::this_thread::sleep_for(std::chrono::milliseconds(300));
f1.updateValue(0, createFooValue("foo2"), 2);
- FastOS_Thread::Sleep(300);
+ std::this_thread::sleep_for(std::chrono::milliseconds(300));
f1.updateGeneration(1, 2);
}
}
@@ -331,7 +332,7 @@ TEST_MT_FFF("requireThatNextConfigIsInterruptedOnClose", 2, MyManager, APIFixtur
ASSERT_TRUE(timer.MilliSecsToNow() >= 500.0);
ASSERT_TRUE(timer.MilliSecsToNow() < 60000.0);
} else {
- FastOS_Thread::Sleep(1000);
+ std::this_thread::sleep_for(std::chrono::milliseconds(1000));
f3.s.close();
}
}
@@ -514,7 +515,7 @@ TEST_MT_FF("requireThatConfigSubscriberWaitsUntilNextConfigSucceeds", 2, MyManag
verifyConfig("foo2", h1->getConfig()); // First update is skipped
} else {
TEST_BARRIER();
- FastOS_Thread::Sleep(1000);
+ std::this_thread::sleep_for(std::chrono::milliseconds(1000));
f1.updateValue(0, createFooValue("foo2"), 3);
}
}
diff --git a/config/src/vespa/config/common/configparser.cpp b/config/src/vespa/config/common/configparser.cpp
index e0a0b0138b9..c490133172f 100644
--- a/config/src/vespa/config/common/configparser.cpp
+++ b/config/src/vespa/config/common/configparser.cpp
@@ -1,11 +1,17 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "configparser.h"
+#include "exceptions.h"
#include "misc.h"
#include <vespa/vespalib/stllike/asciistream.h>
namespace config {
+void ConfigParser::throwNoDefaultValue(const vespalib::stringref & key) {
+ throw InvalidConfigException("Config parameter " + key + " has no "
+ "default value and is not specified in config", VESPA_STRLOC);
+}
+
vespalib::string
ConfigParser::deQuote(const vespalib::stringref & source)
{
diff --git a/config/src/vespa/config/common/configparser.h b/config/src/vespa/config/common/configparser.h
index 613dfc33d94..cde036281a5 100644
--- a/config/src/vespa/config/common/configparser.h
+++ b/config/src/vespa/config/common/configparser.h
@@ -1,7 +1,6 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
-#include <vespa/config/common/exceptions.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <map>
#include <set>
@@ -25,6 +24,7 @@ private:
static std::map<vespalib::string, vsvector> splitMap( const vsvector & config);
static vespalib::string deQuote(const vespalib::stringref & source);
+ static void throwNoDefaultValue(const vespalib::stringref & key);
template<typename T>
static T convert(const vsvector &);
@@ -81,8 +81,7 @@ ConfigParser::parseInternal(const vespalib::stringref & key, const V & config)
V lines = getLinesForKey(key, config);
if (lines.size() == 0) {
- throw InvalidConfigException("Config parameter " + key + " has no "
- "default value and is not specified in config", VESPA_STRLOC);
+ throwNoDefaultValue(key);
}
return convert<T>(lines);
}
diff --git a/config/src/vespa/config/helper/configfetcher.cpp b/config/src/vespa/config/helper/configfetcher.cpp
index 0a4b95e9153..1f1bfe69bb8 100644
--- a/config/src/vespa/config/helper/configfetcher.cpp
+++ b/config/src/vespa/config/helper/configfetcher.cpp
@@ -1,7 +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 <vespa/vespalib/util/thread.h>
#include <vespa/log/log.h>
LOG_SETUP(".config.helper.configfetcher");
@@ -9,7 +9,7 @@ namespace config {
ConfigFetcher::ConfigFetcher(const IConfigContext::SP & context)
: _poller(context),
- _thread(_poller),
+ _thread(std::make_unique<vespalib::Thread>(_poller)),
_closed(false),
_started(false)
{
@@ -17,20 +17,25 @@ ConfigFetcher::ConfigFetcher(const IConfigContext::SP & context)
ConfigFetcher::ConfigFetcher(const SourceSpec & spec)
: _poller(IConfigContext::SP(new ConfigContext(spec))),
- _thread(_poller),
+ _thread(std::make_unique<vespalib::Thread>(_poller)),
_closed(false),
_started(false)
{
}
void
+ConfigFetcher::subscribeGenerationChanges(IGenerationCallback * callback) {
+ _poller.subscribeGenerationChanges(callback);
+}
+
+void
ConfigFetcher::start()
{
if (!_closed) {
LOG(debug, "Polling for config");
_poller.poll();
LOG(debug, "Starting fetcher thread...");
- _thread.start();
+ _thread->start();
_started = true;
LOG(debug, "Fetcher thread started");
}
@@ -47,7 +52,7 @@ ConfigFetcher::close()
if (!_closed) {
_poller.close();
if (_started)
- _thread.join();
+ _thread->join();
}
}
diff --git a/config/src/vespa/config/helper/configfetcher.h b/config/src/vespa/config/helper/configfetcher.h
index ed04dc62f50..872937d8635 100644
--- a/config/src/vespa/config/helper/configfetcher.h
+++ b/config/src/vespa/config/helper/configfetcher.h
@@ -2,11 +2,11 @@
#pragma once
#include "configpoller.h"
-#include <vespa/config/config.h>
#include <vespa/config/common/timingvalues.h>
-#include <vespa/vespalib/util/thread.h>
#include <atomic>
+namespace vespalib { class Thread; }
+
namespace config {
/**
@@ -22,16 +22,14 @@ public:
template <typename ConfigType>
void subscribe(const std::string & configId, IFetcherCallback<ConfigType> * callback, uint64_t subscribeTimeout = DEFAULT_SUBSCRIBE_TIMEOUT);
- void subscribeGenerationChanges(IGenerationCallback * callback) {
- _poller.subscribeGenerationChanges(callback);
- }
+ void subscribeGenerationChanges(IGenerationCallback * callback);
void start();
void close();
int64_t getGeneration() const { return _poller.getGeneration(); }
private:
ConfigPoller _poller;
- vespalib::Thread _thread;
+ std::unique_ptr<vespalib::Thread> _thread;
std::atomic<bool> _closed;
std::atomic<bool> _started;
};
diff --git a/config/src/vespa/config/print/fileconfigsnapshotreader.cpp b/config/src/vespa/config/print/fileconfigsnapshotreader.cpp
index 0cc7fe9fe38..951619aee6f 100644
--- a/config/src/vespa/config/print/fileconfigsnapshotreader.cpp
+++ b/config/src/vespa/config/print/fileconfigsnapshotreader.cpp
@@ -1,10 +1,10 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <fstream>
-#include <sstream>
#include "fileconfigsnapshotreader.h"
#include "jsonconfigformatter.h"
-#include <iostream>
+#include <vespa/config/common/exceptions.h>
+#include <fstream>
+#include <sstream>
namespace config {
diff --git a/config/src/vespa/config/print/fileconfigsnapshotwriter.cpp b/config/src/vespa/config/print/fileconfigsnapshotwriter.cpp
index de5c3af065d..5717e5e9781 100644
--- a/config/src/vespa/config/print/fileconfigsnapshotwriter.cpp
+++ b/config/src/vespa/config/print/fileconfigsnapshotwriter.cpp
@@ -1,8 +1,9 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <fstream>
#include "fileconfigsnapshotwriter.h"
#include "jsonconfigformatter.h"
+#include <vespa/config/common/exceptions.h>
+#include <fstream>
namespace config {
diff --git a/config/src/vespa/config/retriever/configretriever.cpp b/config/src/vespa/config/retriever/configretriever.cpp
index 240ba3bac00..9d49ad3324e 100644
--- a/config/src/vespa/config/retriever/configretriever.cpp
+++ b/config/src/vespa/config/retriever/configretriever.cpp
@@ -1,6 +1,8 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "configretriever.h"
+#include <vespa/config/common/exceptions.h>
+
namespace config {
diff --git a/config/src/vespa/config/retriever/configsnapshot.cpp b/config/src/vespa/config/retriever/configsnapshot.cpp
index b04f44bf600..717c10d30e0 100644
--- a/config/src/vespa/config/retriever/configsnapshot.cpp
+++ b/config/src/vespa/config/retriever/configsnapshot.cpp
@@ -1,10 +1,12 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "configsnapshot.h"
-#include <vespa/vespalib/stllike/asciistream.h>
+#include <vespa/config/subscription/configsubscription.h>
+#include <vespa/config/print/configdatabuffer.h>
+#include <vespa/config/common/exceptions.h>
#include <vespa/config/common/misc.h>
#include <vespa/vespalib/data/slime/slime.h>
-#include <vespa/vespalib/data/memory.h>
+#include <vespa/vespalib/stllike/asciistream.h>
using vespalib::Slime;
using vespalib::slime::Cursor;
@@ -16,23 +18,19 @@ namespace config {
const int64_t ConfigSnapshot::SNAPSHOT_FORMAT_VERSION = 1;
ConfigSnapshot::ConfigSnapshot()
- : _valueMap(),
- _generation(0)
-{}
+ : _valueMap(),
+ _generation(0) {}
-ConfigSnapshot::~ConfigSnapshot()
-{
+ConfigSnapshot::~ConfigSnapshot() {
}
-ConfigSnapshot::ConfigSnapshot(const ConfigSnapshot & rhs) :
- _valueMap(rhs._valueMap),
- _generation(rhs._generation)
-{
+ConfigSnapshot::ConfigSnapshot(const ConfigSnapshot &rhs) :
+ _valueMap(rhs._valueMap),
+ _generation(rhs._generation) {
}
ConfigSnapshot &
-ConfigSnapshot::operator = (const ConfigSnapshot & rhs)
-{
+ConfigSnapshot::operator=(const ConfigSnapshot &rhs) {
if (&rhs != this) {
ConfigSnapshot tmp(rhs);
tmp.swap(*this);
@@ -41,25 +39,31 @@ ConfigSnapshot::operator = (const ConfigSnapshot & rhs)
}
void
-ConfigSnapshot::swap(ConfigSnapshot & rhs)
-{
+ConfigSnapshot::swap(ConfigSnapshot &rhs) {
_valueMap.swap(rhs._valueMap);
std::swap(_generation, rhs._generation);
}
-ConfigSnapshot::ConfigSnapshot(const SubscriptionList & subscriptionList, int64_t generation)
- : _valueMap(),
- _generation(generation)
-{
+ConfigSnapshot::ConfigSnapshot(const SubscriptionList &subscriptionList, int64_t generation)
+ : _valueMap(),
+ _generation(generation) {
for (SubscriptionList::const_iterator it(subscriptionList.begin()), mt(subscriptionList.end()); it != mt; it++) {
_valueMap[(*it)->getKey()] = Value((*it)->getLastGenerationChanged(), (*it)->getConfig());
}
}
-ConfigSnapshot::ConfigSnapshot(const ValueMap & valueMap, int64_t generation)
- : _valueMap(valueMap),
- _generation(generation)
-{
+ConfigSnapshot::ConfigSnapshot(const ValueMap &valueMap, int64_t generation)
+ : _valueMap(valueMap),
+ _generation(generation) {
+}
+
+ConfigSnapshot::ValueMap::const_iterator
+ConfigSnapshot::find(const ConfigKey &key) const {
+ ValueMap::const_iterator it(_valueMap.find(key));
+ if (it == _valueMap.end()) {
+ throw IllegalConfigKeyException("Unable to find config for key " + key.toString());
+ }
+ return it;
}
ConfigSnapshot
diff --git a/config/src/vespa/config/retriever/configsnapshot.h b/config/src/vespa/config/retriever/configsnapshot.h
index 4cb4eeb3e23..24a16876720 100644
--- a/config/src/vespa/config/retriever/configsnapshot.h
+++ b/config/src/vespa/config/retriever/configsnapshot.h
@@ -1,14 +1,16 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
-#include <vespa/config/subscription/configsubscription.h>
-#include <vespa/config/print/configdatabuffer.h>
+#include "configkeyset.h"
+#include <vespa/config/common/configvalue.h>
#include <vespa/vespalib/stllike/string.h>
#include <map>
-#include "configkeyset.h"
namespace config {
+class ConfigSubscription;
+class ConfigDataBuffer;
+
/**
* A ConfigSnapshot contains a map of config keys to config instances. You may
* request an instance of a config by calling the getConfig method.
@@ -16,7 +18,7 @@ namespace config {
class ConfigSnapshot
{
public:
- typedef std::vector<ConfigSubscription::SP> SubscriptionList;
+ typedef std::vector<std::shared_ptr<ConfigSubscription>> SubscriptionList;
/**
* Construct an empty config snapshot.
@@ -112,6 +114,8 @@ private:
void deserializeV2(vespalib::slime::Inspector & root);
Value deserializeValueV2(vespalib::slime::Inspector & inspector) const;
+ ValueMap::const_iterator find(const ConfigKey & key) const;
+
ValueMap _valueMap;
int64_t _generation;
};
@@ -119,4 +123,3 @@ private:
} // namespace config
#include "configsnapshot.hpp"
-
diff --git a/config/src/vespa/config/retriever/configsnapshot.hpp b/config/src/vespa/config/retriever/configsnapshot.hpp
index 395d36bb4f6..bb07431cdef 100644
--- a/config/src/vespa/config/retriever/configsnapshot.hpp
+++ b/config/src/vespa/config/retriever/configsnapshot.hpp
@@ -1,7 +1,5 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/config/common/exceptions.h>
-
namespace config {
template <typename ConfigType>
@@ -9,11 +7,7 @@ std::unique_ptr<ConfigType>
ConfigSnapshot::getConfig(const vespalib::string & configId) const
{
ConfigKey key(ConfigKey::create<ConfigType>(configId));
- ValueMap::const_iterator it(_valueMap.find(key));
- if (it == _valueMap.end()) {
- throw IllegalConfigKeyException("Unable to find config for key " + key.toString());
- }
- return it->second.second.newInstance<ConfigType>();
+ return find(key)->second.second.newInstance<ConfigType>();
}
template <typename ConfigType>
@@ -21,11 +15,7 @@ bool
ConfigSnapshot::isChanged(const vespalib::string & configId, int64_t currentGeneration) const
{
ConfigKey key(ConfigKey::create<ConfigType>(configId));
- ValueMap::const_iterator it(_valueMap.find(key));
- if (it == _valueMap.end()) {
- throw IllegalConfigKeyException("Unable to find config for key " + key.toString());
- }
- return currentGeneration < it->second.first;
+ return currentGeneration < find(key)->second.first;
}
template <typename ConfigType>