diff options
12 files changed, 170 insertions, 128 deletions
diff --git a/documentapi/src/vespa/documentapi/loadtypes/CMakeLists.txt b/documentapi/src/vespa/documentapi/loadtypes/CMakeLists.txt index 9be6458174a..9663a186ce6 100644 --- a/documentapi/src/vespa/documentapi/loadtypes/CMakeLists.txt +++ b/documentapi/src/vespa/documentapi/loadtypes/CMakeLists.txt @@ -2,5 +2,6 @@ vespa_add_library(documentapi_documentapiloadtypes OBJECT SOURCES loadtype.cpp + loadtypeset.cpp DEPENDS ) diff --git a/documentapi/src/vespa/documentapi/loadtypes/loadtype.h b/documentapi/src/vespa/documentapi/loadtypes/loadtype.h index e7ecaa3e40c..15d9c6f528b 100644 --- a/documentapi/src/vespa/documentapi/loadtypes/loadtype.h +++ b/documentapi/src/vespa/documentapi/loadtypes/loadtype.h @@ -13,13 +13,15 @@ #pragma once -#include <vespa/metrics/loadmetric.h> +#include <vespa/metrics/loadtype.h> #include <vespa/vespalib/util/linkedptr.h> #include <vespa/documentapi/messagebus/priority.h> -namespace documentapi { +namespace vespalib { + class asciistream; +} -class LoadTypeSet; +namespace documentapi { // Inherit metrics loadtype so it is easy to use load types in load metrics. class LoadType : public metrics::LoadType { @@ -37,5 +39,4 @@ private: void print(vespalib::asciistream & os) const; }; -} // documentapi - +} diff --git a/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.cpp b/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.cpp new file mode 100644 index 00000000000..d992110513f --- /dev/null +++ b/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.cpp @@ -0,0 +1,79 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "loadtypeset.h" +#include <vespa/config-load-type.h> +#include <vespa/config/config.h> + +namespace documentapi { + +void LoadTypeSet::configure(const LoadTypeConfig& config) { + // This configure does not support live reconfig + if (!_types.empty()) return; + + addLoadType(0, LoadType::DEFAULT.getName(), LoadType::DEFAULT.getPriority()); + + for (uint32_t i=0; i<config.type.size(); ++i) { + addLoadType(config.type[i].id, config.type[i].name, Priority::getPriority(config.type[i].priority)); + } +} + +LoadTypeSet::LoadTypeSet() +{ + addLoadType(0, LoadType::DEFAULT.getName(), LoadType::DEFAULT.getPriority()); +} + +LoadTypeSet::LoadTypeSet(const config::ConfigUri & configUri) +{ + std::unique_ptr<LoadTypeConfig> cfg = config::ConfigGetter<LoadTypeConfig>::getConfig(configUri.getConfigId(), configUri.getContext()); + configure(*cfg); +} + +LoadTypeSet::LoadTypeSet(const LoadTypeConfig& config) +{ + configure(config); +} + +LoadTypeSet::~LoadTypeSet() { } + +void +LoadTypeSet::addLoadType(uint32_t id, const string& name, Priority::Value priority) { + auto it(_types.find(id)); + if (it != _types.end()) { + throw config::InvalidConfigException("Load type identifiers need to be non-overlapping, 1+ and without gaps.\n", VESPA_STRLOC); + } + if (_nameMap.find(name) != _nameMap.end()) { + throw config::InvalidConfigException("Load type names need to be unique and different from the reserved name \"default\".", VESPA_STRLOC); + } + _types[id] = std::make_unique<LoadType>(id, name, priority); + _nameMap[name] = _types[id].get(); +} + +metrics::LoadTypeSet +LoadTypeSet::getMetricLoadTypes() const { + metrics::LoadTypeSet result; + for (const auto & entry : _types) { + result.push_back(metrics::LoadType(entry.first, entry.second->getName())); + } + return result; +} + +const LoadType& +LoadTypeSet::operator[](uint32_t id) const { + auto it(_types.find(id)); + return (it == _types.end() ? LoadType::DEFAULT : *it->second); +} + +const LoadType& +LoadTypeSet::operator[](const string& name) const { + auto it(_nameMap.find(name)); + + return (it == _nameMap.end() ? LoadType::DEFAULT : *it->second); +} + +const LoadType* +LoadTypeSet::findLoadType(const string& name) const { + auto it(_nameMap.find(name)); + return (it == _nameMap.end() ? 0 : it->second); +} + +} diff --git a/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.h b/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.h index 19b8ce61dbf..cdfc20591f3 100644 --- a/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.h +++ b/documentapi/src/vespa/documentapi/loadtypes/loadtypeset.h @@ -10,106 +10,59 @@ */ #pragma once -#include <vespa/config/config.h> -#include <vespa/documentapi/loadtypes/loadtype.h> -#include <vespa/metrics/loadmetric.h> -#include <vector> -#include <vespa/config-load-type.h> +#include "loadtype.h" #include <vespa/vespalib/stllike/hash_map.h> +#include <map> + +namespace config { + class ConfigUri; +} + +namespace vespa { +namespace config { +namespace content { +namespace internal { + class InternalLoadTypeType; +} +} +} +} namespace documentapi { class LoadTypeSet { - vespalib::hash_map<uint32_t, LoadType::LP> _types; - // Want order to be ~ alphabetical. + using LoadTypeConfig = const vespa::config::content::internal::InternalLoadTypeType; + vespalib::hash_map<uint32_t, std::unique_ptr<LoadType>> _types; + // Want order to be ~ alphabetical. std::map<string, LoadType*> _nameMap; - // This object cannot be copied - LoadTypeSet(const LoadTypeSet&); - LoadTypeSet& operator=(const LoadTypeSet&); - - void configure(const vespa::config::content::LoadTypeConfig& config) { - // This configure does not support live reconfig - if (!_types.empty()) return; - - addLoadType(0, LoadType::DEFAULT.getName(), LoadType::DEFAULT.getPriority()); - - for (uint32_t i=0; i<config.type.size(); ++i) { - addLoadType(config.type[i].id, config.type[i].name, Priority::getPriority(config.type[i].priority)); - } - } - + void configure(const LoadTypeConfig& config); public: typedef std::unique_ptr<LoadTypeSet> UP; typedef std::shared_ptr<LoadTypeSet> SP; - LoadTypeSet() { - addLoadType(0, LoadType::DEFAULT.getName(), LoadType::DEFAULT.getPriority()); - } - - LoadTypeSet(const config::ConfigUri & configUri) { - std::unique_ptr<vespa::config::content::LoadTypeConfig> cfg = - config::ConfigGetter<vespa::config::content::LoadTypeConfig>::getConfig(configUri.getConfigId(), configUri.getContext()); - configure(*cfg); - } - - LoadTypeSet(const vespa::config::content::LoadTypeConfig& config) { - configure(config); - } - - void addLoadType(uint32_t id, const string& name, Priority::Value priority) { - vespalib::hash_map<uint32_t, LoadType::LP>::iterator it( - _types.find(id)); - if (it != _types.end()) { - throw config::InvalidConfigException( - "Load type identifiers need to be non-overlapping, 1+ " - "and without gaps.\n", VESPA_STRLOC); - } - if (_nameMap.find(name) != _nameMap.end()) { - throw config::InvalidConfigException( - "Load type names need to be unique and different from " - "the reserved name \"default\".", VESPA_STRLOC); - } - _types[id] = LoadType::LP(new LoadType(id, name, priority)); - _nameMap[name] = _types[id].get(); - } + LoadTypeSet(const LoadTypeSet&) = delete; + LoadTypeSet& operator=(const LoadTypeSet&) = delete; - const std::map<string, LoadType*>& getLoadTypes() const - { return _nameMap; } - metrics::LoadTypeSet getMetricLoadTypes() const { - metrics::LoadTypeSet result; - for (vespalib::hash_map<uint32_t, LoadType::LP>::const_iterator it - = _types.begin(); it != _types.end(); ++it) - { - result.push_back(metrics::LoadType( - it->first, it->second->getName())); - } - return result; - } + LoadTypeSet(); + LoadTypeSet(const config::ConfigUri & configUri); + LoadTypeSet(const LoadTypeConfig& config); + ~LoadTypeSet(); - const LoadType& operator[](uint32_t id) const { - vespalib::hash_map<uint32_t, LoadType::LP>::const_iterator it( - _types.find(id)); - return (it == _types.end() ? LoadType::DEFAULT : *it->second); - } - const LoadType& operator[](const string& name) const { - std::map<string, LoadType*>::const_iterator it( - _nameMap.find(name)); + void addLoadType(uint32_t id, const string& name, Priority::Value priority); - return (it == _nameMap.end() ? LoadType::DEFAULT : *it->second); - } + const std::map<string, LoadType*>& getLoadTypes() const { return _nameMap; } + metrics::LoadTypeSet getMetricLoadTypes() const; + const LoadType& operator[](uint32_t id) const; + const LoadType& operator[](const string& name) const; uint32_t size() const { return uint32_t(_types.size()); } /** * Attempts to locate a load type with given name. Returns 0 if none found. */ - const LoadType* findLoadType(const string& name) const { - std::map<string, LoadType*>::const_iterator it( - _nameMap.find(name)); - return (it == _nameMap.end() ? 0 : it->second); - } + const LoadType* findLoadType(const string& name) const; }; } // documentapi diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/andpolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/andpolicy.cpp index def23cd9d78..97e6a1cdc4a 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/andpolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/andpolicy.cpp @@ -1,11 +1,10 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> +#include "andpolicy.h" #include <vespa/messagebus/error.h> #include <vespa/messagebus/errorcode.h> #include <vespa/messagebus/emptyreply.h> #include <vespa/messagebus/routing/routingcontext.h> #include <vespa/documentapi/messagebus/documentprotocol.h> -#include <vespa/documentapi/messagebus/policies/andpolicy.h> namespace documentapi { diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/loadbalancerpolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/loadbalancerpolicy.cpp index f30a6522337..7a467e43b3d 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/loadbalancerpolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/loadbalancerpolicy.cpp @@ -1,12 +1,10 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/documentapi/messagebus/policies/loadbalancerpolicy.h> +#include "loadbalancerpolicy.h" #include <vespa/messagebus/emptyreply.h> #include <vespa/messagebus/errorcode.h> #include <vespa/messagebus/routing/ihopdirective.h> #include <vespa/messagebus/routing/routingcontext.h> #include <vespa/messagebus/routing/verbatimdirective.h> -#include <vespa/documentapi/messagebus/documentprotocol.h> #include <vespa/log/log.h> LOG_SETUP(".loadbalancerpolicy"); diff --git a/metrics/src/vespa/metrics/loadmetric.h b/metrics/src/vespa/metrics/loadmetric.h index 3982e144846..1ab726a844c 100644 --- a/metrics/src/vespa/metrics/loadmetric.h +++ b/metrics/src/vespa/metrics/loadmetric.h @@ -18,30 +18,13 @@ #pragma once +#include "loadtype.h" #include "metricset.h" #include "summetric.h" #include <vespa/vespalib/stllike/hash_map.h> namespace metrics { -class MetricSet; - -class LoadType { -public: - using string = vespalib::string; - LoadType(uint32_t id, const string& name) : _id(id), _name(name) {} - - uint32_t getId() const { return _id; } - const string& getName() const { return _name; } - - string toString() const; -private: - uint32_t _id; - string _name; -}; - -typedef std::vector<LoadType> LoadTypeSet; - template<typename MetricType> class LoadMetric : public MetricSet { std::vector<Metric::LP> _ownerList; diff --git a/metrics/src/vespa/metrics/loadtype.h b/metrics/src/vespa/metrics/loadtype.h new file mode 100644 index 00000000000..60a50b2a69b --- /dev/null +++ b/metrics/src/vespa/metrics/loadtype.h @@ -0,0 +1,25 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include <vespa/vespalib/stllike/string.h> +#include <vector> + +namespace metrics { + +class LoadType { +public: + using string = vespalib::string; + LoadType(uint32_t id, const string& name) : _id(id), _name(name) {} + + uint32_t getId() const { return _id; } + const string& getName() const { return _name; } + + string toString() const; +private: + uint32_t _id; + string _name; +}; + +typedef std::vector<LoadType> LoadTypeSet; + +} diff --git a/storageapi/src/vespa/storageapi/messageapi/bucketcommand.cpp b/storageapi/src/vespa/storageapi/messageapi/bucketcommand.cpp index 465833a7abf..d27e971006f 100644 --- a/storageapi/src/vespa/storageapi/messageapi/bucketcommand.cpp +++ b/storageapi/src/vespa/storageapi/messageapi/bucketcommand.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 <vespa/fastos/fastos.h> -#include <vespa/storageapi/messageapi/bucketcommand.h> +#include "bucketcommand.h" +#include <ostream> namespace storage { namespace api { diff --git a/storageapi/src/vespa/storageapi/messageapi/storagecommand.cpp b/storageapi/src/vespa/storageapi/messageapi/storagecommand.cpp index 65027712905..3248142d464 100644 --- a/storageapi/src/vespa/storageapi/messageapi/storagecommand.cpp +++ b/storageapi/src/vespa/storageapi/messageapi/storagecommand.cpp @@ -1,9 +1,9 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> +#include "storagecommand.h" #include <limits> -#include <vespa/storageapi/messageapi/storagecommand.h> #include <vespa/vespalib/util/exceptions.h> +#include <ostream> namespace storage { namespace api { diff --git a/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp b/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp index 1c1342dc7f3..536135c48e6 100644 --- a/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp +++ b/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp @@ -166,7 +166,8 @@ const MessageType MessageType::SETBUCKETSTATE_REPLY( SETBUCKETSTATE_REPLY_ID, &MessageType::SETBUCKETSTATE); -const MessageType& MessageType::get(Id id) +const MessageType& +MessageType::MessageType::get(Id id) { std::map<Id, MessageType*>::const_iterator it = _codes.find(id); if (it == _codes.end()) { @@ -177,6 +178,17 @@ const MessageType& MessageType::get(Id id) return *it->second; } +void +MessageType::print(std::ostream& out, bool verbose, const std::string& indent) const +{ + (void) verbose; (void) indent; + out << "MessageType(" << _id << ", " << _name; + if (_replyOf) { + out << ", reply of " << _replyOf->getName(); + } + out << ")"; +} + StorageMessageAddress::StorageMessageAddress(const mbus::Route& route) : _route(route), _retryEnabled(false), @@ -184,12 +196,14 @@ StorageMessageAddress::StorageMessageAddress(const mbus::Route& route) _cluster(""), _type(0), _index(0xFFFF) -{ +{ } + +std::ostream & operator << (std::ostream & os, const StorageMessageAddress & addr) { + return os << addr.toString(); } static vespalib::string -createAddress(const vespalib::stringref & cluster, const lib::NodeType& type, - uint16_t index) +createAddress(const vespalib::stringref & cluster, const lib::NodeType& type, uint16_t index) { vespalib::asciistream os; os << STORAGEADDRESS_PREFIX << cluster << '/' << type.toString() << '/' << index << "/default"; diff --git a/storageapi/src/vespa/storageapi/messageapi/storagemessage.h b/storageapi/src/vespa/storageapi/messageapi/storagemessage.h index 27d87dd44ca..6d16a6546f9 100644 --- a/storageapi/src/vespa/storageapi/messageapi/storagemessage.h +++ b/storageapi/src/vespa/storageapi/messageapi/storagemessage.h @@ -279,15 +279,7 @@ public: bool operator==(const MessageType& type) const { return (_id == type._id); } bool operator!=(const MessageType& type) const { return (_id != type._id); } - void print(std::ostream& out, bool verbose, const std::string& indent) const - { - (void) verbose; (void) indent; - out << "MessageType(" << _id << ", " << _name; - if (_replyOf) { - out << ", reply of " << _replyOf->getName(); - } - out << ")"; - } + void print(std::ostream& out, bool verbose, const std::string& indent) const override; }; /** @@ -328,10 +320,7 @@ public: bool operator==(const StorageMessageAddress& other) const; vespalib::string toString() const; - friend std::ostream & operator << - (std::ostream & os, const StorageMessageAddress & addr) { - return os << addr.toString(); - } + friend std::ostream & operator << (std::ostream & os, const StorageMessageAddress & addr); private: void print(vespalib::asciistream & out) const; |