diff options
64 files changed, 521 insertions, 535 deletions
diff --git a/config-model-api/src/main/java/com/yahoo/config/model/api/ModelContext.java b/config-model-api/src/main/java/com/yahoo/config/model/api/ModelContext.java index c4a120fc10c..0cf8b343b6a 100644 --- a/config-model-api/src/main/java/com/yahoo/config/model/api/ModelContext.java +++ b/config-model-api/src/main/java/com/yahoo/config/model/api/ModelContext.java @@ -110,7 +110,7 @@ public interface ModelContext { @ModelFeatureFlag(owners = {"vekterli"}) default double persistenceThrottlingWsDecrementFactor() { throw new UnsupportedOperationException("TODO specify default value"); } @ModelFeatureFlag(owners = {"vekterli"}) default double persistenceThrottlingWsBackoff() { throw new UnsupportedOperationException("TODO specify default value"); } @ModelFeatureFlag(owners = {"arnej"}) default boolean useQrserverServiceName() { return true; } - @ModelFeatureFlag(owners = {"bjorncs", "baldersheim"}) default boolean enableJdiscPreshutdownCommand() { return false; } + @ModelFeatureFlag(owners = {"bjorncs", "baldersheim"}) default boolean enableJdiscPreshutdownCommand() { return true; } } /** Warning: As elsewhere in this package, do not make backwards incompatible changes that will break old config models! */ diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainer.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainer.java index 54b9a4511b0..ba5e8ed5544 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainer.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainer.java @@ -29,7 +29,6 @@ public final class ApplicationContainer extends Container implements private final boolean isHostedVespa; private final boolean enableServerOcspStapling; private final boolean useQrserverServiceName; - private final boolean enablePreshutdownCommand; public ApplicationContainer(AbstractConfigProducer<?> parent, String name, int index, DeployState deployState) { this(parent, name, false, index, deployState); @@ -40,7 +39,6 @@ public final class ApplicationContainer extends Container implements this.isHostedVespa = deployState.isHosted(); this.enableServerOcspStapling = deployState.featureFlags().enableServerOcspStapling(); this.useQrserverServiceName = deployState.featureFlags().useQrserverServiceName(); - this.enablePreshutdownCommand = deployState.featureFlags().enableJdiscPreshutdownCommand(); addComponent(new SimpleComponent("com.yahoo.container.jdisc.messagebus.NetworkMultiplexerHolder")); addComponent(new SimpleComponent("com.yahoo.container.jdisc.messagebus.NetworkMultiplexerProvider")); @@ -109,7 +107,6 @@ public final class ApplicationContainer extends Container implements @Override public Optional<String> getPreShutdownCommand() { - if (!enablePreshutdownCommand) return Optional.empty(); int preshutdownTimeoutSeconds = 360; int rpcTimeoutSeconds = preshutdownTimeoutSeconds + 10; String rpcParams = "-t " + rpcTimeoutSeconds + " tcp/localhost:" + getRpcPort() + " prepareStop d:" + preshutdownTimeoutSeconds; diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/http/JettyHttpServer.java b/config-model/src/main/java/com/yahoo/vespa/model/container/http/JettyHttpServer.java index e397e6ab399..33cbb328c52 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/http/JettyHttpServer.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/http/JettyHttpServer.java @@ -22,7 +22,6 @@ import java.util.List; public class JettyHttpServer extends SimpleComponent implements ServerConfig.Producer { private final ContainerCluster<?> cluster; - private final boolean enablePreshutdownCommand; private volatile boolean isHostedVespa; private final List<ConnectorFactory> connectorFactories = new ArrayList<>(); private final List<String> ignoredUserAgentsList = new ArrayList<>(); @@ -37,7 +36,6 @@ public class JettyHttpServer extends SimpleComponent implements ServerConfig.Pro for (String agent : deployState.featureFlags().ignoredHttpUserAgents()) { addIgnoredUserAgent(agent); } - this.enablePreshutdownCommand = deployState.featureFlags().enableJdiscPreshutdownCommand(); } public void setHostedVespa(boolean isHostedVespa) { this.isHostedVespa = isHostedVespa; } @@ -77,9 +75,7 @@ public class JettyHttpServer extends SimpleComponent implements ServerConfig.Pro .remotePortHeaders(List.of("X-Forwarded-Port", "y-rp"))); } configureJettyThreadpool(builder); - if (enablePreshutdownCommand) { - builder.stopTimeout(300); - } + builder.stopTimeout(300); } private void configureJettyThreadpool(ServerConfig.Builder builder) { diff --git a/config/src/tests/configagent/configagent.cpp b/config/src/tests/configagent/configagent.cpp index 4843b2f0647..10f321c181d 100644 --- a/config/src/tests/configagent/configagent.cpp +++ b/config/src/tests/configagent/configagent.cpp @@ -114,7 +114,7 @@ private: ConfigValue createValue(const std::string & myField, const std::string & xxhash64) { - std::vector< vespalib::string > lines; + StringVector lines; lines.push_back("myField \"" + myField + "\""); return ConfigValue(lines, xxhash64); } diff --git a/config/src/tests/configgen/map_inserter.cpp b/config/src/tests/configgen/map_inserter.cpp index 2a37d401792..bf1b856972e 100644 --- a/config/src/tests/configgen/map_inserter.cpp +++ b/config/src/tests/configgen/map_inserter.cpp @@ -1,8 +1,8 @@ // Copyright Yahoo. 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/configgen/map_inserter.h> #include <vespa/vespalib/data/slime/slime.h> +#include <vespa/config/configgen/map_inserter.hpp> using namespace config; using namespace config::internal; diff --git a/config/src/tests/configgen/vector_inserter.cpp b/config/src/tests/configgen/vector_inserter.cpp index b8611317650..80ebf0fc95f 100644 --- a/config/src/tests/configgen/vector_inserter.cpp +++ b/config/src/tests/configgen/vector_inserter.cpp @@ -1,7 +1,8 @@ // Copyright Yahoo. 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/configgen/vector_inserter.h> +#include <vespa/config/common/types.h> +#include <vespa/config/configgen/vector_inserter.hpp> #include <vespa/vespalib/data/slime/slime.h> using namespace config; @@ -27,7 +28,7 @@ TEST("require that vector of ints can be inserted") { root.addLong(3); root.addLong(2); root.addLong(6); - VectorInserter<int32_t> inserter(vector); + VectorInserter inserter(vector); root.traverse(inserter); ASSERT_EQUAL(3u, vector.size()); ASSERT_EQUAL(3, vector[0]); @@ -45,7 +46,7 @@ TEST("require that vector of struct can be inserted") { Cursor & two = root.addObject(); two.setLong("foo", 1); two.setLong("bar", 6); - VectorInserter<MyType> inserter(typeVector); + VectorInserter inserter(typeVector); root.traverse(inserter); ASSERT_EQUAL(2u, typeVector.size()); ASSERT_EQUAL(3, typeVector[0].foo); @@ -61,7 +62,7 @@ TEST("require that vector of long can be inserted") { root.addLong(3); root.addLong(2); root.addLong(6); - VectorInserter<int64_t> inserter(vector); + VectorInserter inserter(vector); root.traverse(inserter); ASSERT_EQUAL(3u, vector.size()); ASSERT_EQUAL(3, vector[0]); @@ -76,7 +77,7 @@ TEST("require that vector of double can be inserted") { root.addDouble(3.1); root.addDouble(2.4); root.addDouble(6.6); - VectorInserter<double> inserter(vector); + VectorInserter inserter(vector); root.traverse(inserter); ASSERT_EQUAL(3u, vector.size()); ASSERT_EQUAL(3.1, vector[0]); @@ -91,7 +92,7 @@ TEST("require that vector of bool can be inserted") { root.addBool(true); root.addBool(false); root.addBool(true); - VectorInserter<bool> inserter(vector); + VectorInserter inserter(vector); root.traverse(inserter); ASSERT_EQUAL(3u, vector.size()); ASSERT_TRUE(vector[0]); @@ -99,14 +100,15 @@ TEST("require that vector of bool can be inserted") { ASSERT_TRUE(vector[2]); } -TEST("require that vector of string can be inserted") { - std::vector<vespalib::string> vector; +template<typename V> +void +verify_vector_strings_can_be_inserted(V vector) { Slime slime; Cursor & root = slime.setArray(); root.addString("foo"); root.addString("bar"); root.addString("baz"); - VectorInserter<vespalib::string> inserter(vector); + VectorInserter inserter(vector); root.traverse(inserter); ASSERT_EQUAL(3u, vector.size()); ASSERT_EQUAL("foo", vector[0]); @@ -114,4 +116,9 @@ TEST("require that vector of string can be inserted") { ASSERT_EQUAL("baz", vector[2]); } +TEST("require that different vectors of strings can be inserted") { + verify_vector_strings_can_be_inserted(std::vector<vespalib::string>()); + verify_vector_strings_can_be_inserted(StringVector()); +} + TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/config/src/tests/configmanager/configmanager.cpp b/config/src/tests/configmanager/configmanager.cpp index 9bed974f628..a7171b11137 100644 --- a/config/src/tests/configmanager/configmanager.cpp +++ b/config/src/tests/configmanager/configmanager.cpp @@ -17,7 +17,7 @@ namespace { ConfigValue createValue(const std::string & myField, const std::string & md5) { - std::vector< vespalib::string > lines; + StringVector lines; lines.push_back("myField \"" + myField + "\""); return ConfigValue(lines, md5); } diff --git a/config/src/tests/configparser/configparser.cpp b/config/src/tests/configparser/configparser.cpp index 3e569a2d3fb..32043ae79dc 100644 --- a/config/src/tests/configparser/configparser.cpp +++ b/config/src/tests/configparser/configparser.cpp @@ -3,6 +3,7 @@ #include <vespa/config/common/configparser.h> #include <vespa/config/common/exceptions.h> #include <vespa/config/common/configvalue.h> +#include <vespa/config/common/misc.h> #include "config-foo.h" #include <fstream> #include <vespa/vespalib/stllike/asciistream.h> @@ -23,7 +24,7 @@ namespace { ConfigValue readConfig(const vespalib::string & fileName) { asciistream is(asciistream::createFromFile(fileName)); - return ConfigValue(is.getlines(), ""); + return ConfigValue(getlines(is), ""); } } diff --git a/config/src/vespa/config/common/configkey.cpp b/config/src/vespa/config/common/configkey.cpp index 79fa6fec81b..f81e5fbcb87 100644 --- a/config/src/vespa/config/common/configkey.cpp +++ b/config/src/vespa/config/common/configkey.cpp @@ -30,19 +30,12 @@ ConfigKey::ConfigKey(vespalib::stringref configId, { } -ConfigKey::ConfigKey() - : _configId(), - _defName(), - _defNamespace(), - _defMd5(), - _defSchema(), - _key() -{} - +ConfigKey::ConfigKey() = default; ConfigKey::ConfigKey(const ConfigKey &) = default; ConfigKey & ConfigKey::operator = (const ConfigKey &) = default; - -ConfigKey::~ConfigKey() { } +ConfigKey::ConfigKey(ConfigKey &&) noexcept = default; +ConfigKey & ConfigKey::operator = (ConfigKey &&) noexcept = default; +ConfigKey::~ConfigKey() = default; bool ConfigKey::operator<(const ConfigKey & rhs) const diff --git a/config/src/vespa/config/common/configkey.h b/config/src/vespa/config/common/configkey.h index 60db8d6e8cc..2b8d2fc70b3 100644 --- a/config/src/vespa/config/common/configkey.h +++ b/config/src/vespa/config/common/configkey.h @@ -20,8 +20,8 @@ public: ConfigKey(const ConfigKey &); ConfigKey & operator = (const ConfigKey &); - ConfigKey(ConfigKey &&) = default; - ConfigKey & operator = (ConfigKey &&) = default; + ConfigKey(ConfigKey &&) noexcept; + ConfigKey & operator = (ConfigKey &&) noexcept; ConfigKey(); ~ConfigKey(); diff --git a/config/src/vespa/config/common/configparser.cpp b/config/src/vespa/config/common/configparser.cpp index 3e18d6ae4e7..97373071ed5 100644 --- a/config/src/vespa/config/common/configparser.cpp +++ b/config/src/vespa/config/common/configparser.cpp @@ -124,10 +124,9 @@ getValueForKey(vespalib::stringref key, vespalib::stringref line, } StringVector -ConfigParser::getLinesForKey(vespalib::stringref key, - const vsvector & lines) +ConfigParser::getLinesForKey(vespalib::stringref key, Cfg lines) { - vsvector retval; + StringVector retval; for (uint32_t i = 0; i < lines.size(); i++) { vespalib::string value; @@ -140,6 +139,18 @@ ConfigParser::getLinesForKey(vespalib::stringref key, return retval; } +std::set<vespalib::string> +ConfigParser::getUniqueNonWhiteSpaceLines(Cfg config) { + std::set<vespalib::string> unique; + for (uint32_t i = 0; i < config.size(); i++) { + vespalib::string line = stripWhitespace(config[i]); + if (!line.empty()) { + unique.insert(line); + } + } + return unique; +} + void ConfigParser::stripLinesForKey(vespalib::stringref key, std::set<vespalib::string>& config) @@ -155,10 +166,10 @@ ConfigParser::stripLinesForKey(vespalib::stringref key, } } -std::map<vespalib::string, ConfigParser::vsvector> -ConfigParser::splitMap(const vsvector & config) +std::map<vespalib::string, StringVector> +ConfigParser::splitMap(Cfg config) { - std::map<vespalib::string, vsvector> items; + std::map<vespalib::string, StringVector> items; vespalib::string lastValue; @@ -178,7 +189,7 @@ ConfigParser::splitMap(const vsvector & config) vespalib::string value = config[i].substr(pos + 1); if (key != lastValue) { - items[key] = vsvector(); + items[key] = StringVector(); lastValue = key; } @@ -191,10 +202,10 @@ ConfigParser::splitMap(const vsvector & config) return items; } -std::vector<ConfigParser::vsvector> -ConfigParser::splitArray(const vsvector & config) +std::vector<StringVector> +ConfigParser::splitArray(Cfg config) { - std::vector<vsvector> items; + std::vector<StringVector> items; vespalib::string lastValue; @@ -214,7 +225,7 @@ ConfigParser::splitArray(const vsvector & config) vespalib::string value = config[i].substr(pos + 1); if (key != lastValue) { - items.push_back(vsvector()); + items.push_back(StringVector()); lastValue = key; } @@ -266,7 +277,7 @@ ConfigParser::stripWhitespace(vespalib::stringref source) } vespalib::string -ConfigParser::arrayToString(const vsvector & array) +ConfigParser::arrayToString(Cfg array) { vespalib::asciistream ost; if (array.size() == 0) { @@ -281,13 +292,13 @@ ConfigParser::arrayToString(const vsvector & array) template<> bool -ConfigParser::convert<bool>(const vsvector & config) +ConfigParser::convert<bool>(const StringVector & config) { if (config.size() != 1) { throw InvalidConfigException("Expected single line with bool value, " "got " + arrayToString(config), VESPA_STRLOC); } - std::string value = stripWhitespace(deQuote(config[0])); + vespalib::string value = stripWhitespace(deQuote(config[0])); if (value == "true") { return true; @@ -301,13 +312,13 @@ ConfigParser::convert<bool>(const vsvector & config) template<> int32_t -ConfigParser::convert<int32_t>(const vsvector & config) +ConfigParser::convert<int32_t>(const StringVector & config) { if (config.size() != 1) { throw InvalidConfigException("Expected single line with int32_t value, " "got " + arrayToString(config), VESPA_STRLOC); } - std::string value(deQuote(stripWhitespace(config[0]))); + vespalib::string value(deQuote(stripWhitespace(config[0]))); const char *startp = value.c_str(); char *endp; @@ -321,13 +332,13 @@ ConfigParser::convert<int32_t>(const vsvector & config) template<> int64_t -ConfigParser::convert<int64_t>(const vsvector & config) +ConfigParser::convert<int64_t>(const StringVector & config) { if (config.size() != 1) { throw InvalidConfigException("Expected single line with int64_t value, " "got " + arrayToString(config), VESPA_STRLOC); } - std::string value(deQuote(stripWhitespace(config[0]))); + vespalib::string value(deQuote(stripWhitespace(config[0]))); const char *startp = value.c_str(); char *endp; @@ -341,13 +352,13 @@ ConfigParser::convert<int64_t>(const vsvector & config) template<> double -ConfigParser::convert<double>(const vsvector & config) +ConfigParser::convert<double>(const StringVector & config) { if (config.size() != 1) { throw InvalidConfigException("Expected single line with double value, " "got " + arrayToString(config), VESPA_STRLOC); } - std::string value(deQuote(stripWhitespace(config[0]))); + vespalib::string value(deQuote(stripWhitespace(config[0]))); const char *startp = value.c_str(); char *endp; @@ -362,14 +373,14 @@ ConfigParser::convert<double>(const vsvector & config) template<> vespalib::string -ConfigParser::convert<vespalib::string>(const vsvector & config) +ConfigParser::convert<vespalib::string>(const StringVector & config) { if (config.size() != 1) { throw InvalidConfigException("Expected single line with string value, " "got " + arrayToString(config), VESPA_STRLOC); } - std::string value = stripWhitespace(config[0]); + vespalib::string value = stripWhitespace(config[0]); return deQuote(value); } diff --git a/config/src/vespa/config/common/configparser.h b/config/src/vespa/config/common/configparser.h index dc89930c23e..42ee684eb59 100644 --- a/config/src/vespa/config/common/configparser.h +++ b/config/src/vespa/config/common/configparser.h @@ -14,69 +14,83 @@ namespace config { */ class ConfigParser { public: - using vsvector = StringVector; + class Cfg { + public: + Cfg(const std::vector<vespalib::string> & v) + : _cfg(&v[0]), _sz(v.size()) + { } + Cfg(const std::vector<vespalib::string, vespalib::allocator_large<vespalib::string>> & v) : + _cfg(&v[0]), + _sz(v.size()) + { } + size_t size() const { return _sz; } + const vespalib::string & operator[] (size_t idx) const { return _cfg[idx]; } + private: + const vespalib::string * _cfg; + size_t _sz; + }; private: - static vsvector getLinesForKey(vespalib::stringref key, const vsvector & config); + static StringVector getLinesForKey(vespalib::stringref key, Cfg config); - static std::vector<vsvector> splitArray( const vsvector & config); - static std::map<vespalib::string, vsvector> splitMap( const vsvector & config); + static std::vector<StringVector> splitArray(Cfg config); + static std::map<vespalib::string, StringVector> splitMap(Cfg config); static vespalib::string deQuote(const vespalib::string & source); static void throwNoDefaultValue(vespalib::stringref key); template<typename T> - static T convert(const vsvector &); + static T convert(const StringVector & config); - static vespalib::string arrayToString(const vsvector &); + static vespalib::string arrayToString(Cfg config); - template<typename T, typename V> - static T parseInternal(vespalib::stringref key, const V & config); - template<typename T, typename V> - static T parseInternal(vespalib::stringref key, const V & config, T defaultValue); + template<typename T> + static T parseInternal(vespalib::stringref key, Cfg config); + template<typename T> + static T parseInternal(vespalib::stringref key, Cfg config, T defaultValue); - template<typename T, typename V> - static std::vector<T> parseArrayInternal(vespalib::stringref key, const V & config); - template<typename T, typename V> - static std::map<vespalib::string, T> parseMapInternal(vespalib::stringref key, const V & config); - template<typename T, typename V> - static T parseStructInternal(vespalib::stringref key, const V & config); + template<typename V> + static V parseArrayInternal(vespalib::stringref key, Cfg config); + template<typename T> + static std::map<vespalib::string, T> parseMapInternal(vespalib::stringref key, Cfg config); + template<typename T> + static T parseStructInternal(vespalib::stringref key, Cfg config); public: - static void stripLinesForKey(vespalib::stringref key, - std::set<vespalib::string>& config); + static void stripLinesForKey(vespalib::stringref key, std::set<vespalib::string>& config); + static std::set<vespalib::string> getUniqueNonWhiteSpaceLines(Cfg config); static vespalib::string stripWhitespace(vespalib::stringref source); template<typename T> - static T parse(vespalib::stringref key, const vsvector & config) { - return parseInternal<T, vsvector>(key, config); + static T parse(vespalib::stringref key, Cfg config) { + return parseInternal<T>(key, config); } template<typename T> - static T parse(vespalib::stringref key, const vsvector & config, T defaultValue) { + static T parse(vespalib::stringref key, Cfg config, T defaultValue) { return parseInternal(key, config, defaultValue); } - template<typename T> - static std::vector<T> parseArray(vespalib::stringref key, const vsvector & config) { - return parseArrayInternal<T, vsvector>(key, config); + template<typename V> + static V parseArray(vespalib::stringref key, Cfg config) { + return parseArrayInternal<V>(key, config); } template<typename T> - static std::map<vespalib::string, T> parseMap(vespalib::stringref key, const vsvector & config) { - return parseMapInternal<T, vsvector>(key, config); + static std::map<vespalib::string, T> parseMap(vespalib::stringref key, Cfg config) { + return parseMapInternal<T>(key, config); } template<typename T> - static T parseStruct(vespalib::stringref key, const vsvector & config) { - return parseStructInternal<T, vsvector>(key, config); + static T parseStruct(vespalib::stringref key, Cfg config) { + return parseStructInternal<T>(key, config); } }; -template<typename T, typename V> +template<typename T> T -ConfigParser::parseInternal(vespalib::stringref key, const V & config) +ConfigParser::parseInternal(vespalib::stringref key, Cfg config) { - V lines = getLinesForKey(key, config); + StringVector lines = getLinesForKey(key, config); if (lines.size() == 0) { throwNoDefaultValue(key); @@ -84,11 +98,11 @@ ConfigParser::parseInternal(vespalib::stringref key, const V & config) return convert<T>(lines); } -template<typename T, typename V> +template<typename T> T -ConfigParser::parseInternal(vespalib::stringref key, const V & config, T defaultValue) +ConfigParser::parseInternal(vespalib::stringref key, Cfg config, T defaultValue) { - V lines = getLinesForKey(key, config); + StringVector lines = getLinesForKey(key, config); if (lines.size() == 0) { return defaultValue; @@ -99,67 +113,68 @@ ConfigParser::parseInternal(vespalib::stringref key, const V & config, T default template<typename T> T -ConfigParser::convert(const vsvector & lines) { +ConfigParser::convert(const StringVector & lines) { return T(lines); } -template<typename T, typename V> +template<typename T> std::map<vespalib::string, T> -ConfigParser::parseMapInternal(vespalib::stringref key, const V & config) +ConfigParser::parseMapInternal(vespalib::stringref key, Cfg config) { - V lines = getLinesForKey(key, config); - typedef std::map<vespalib::string, V> SplittedMap; + StringVector lines = getLinesForKey(key, config); + using SplittedMap = std::map<vespalib::string, StringVector>; SplittedMap s = splitMap(lines); std::map<vespalib::string, T> retval; - for (typename SplittedMap::iterator it(s.begin()), mt(s.end()); it != mt; it++) { - retval[it->first] = convert<T>(it->second); + for (const auto & e : s) { + retval[e.first] = convert<T>(e.second); } return retval; } -template<typename T, typename V> -std::vector<T> -ConfigParser::parseArrayInternal(vespalib::stringref key, const V & config) +template<typename V> +V +ConfigParser::parseArrayInternal(vespalib::stringref key, Cfg config) { - V lines = getLinesForKey(key, config); - std::vector<V> split = splitArray(lines); + StringVector lines = getLinesForKey(key, config); + std::vector<StringVector> split = splitArray(lines); - std::vector<T> retval; + V retval; + retval.reserve(split.size()); for (uint32_t i = 0; i < split.size(); i++) { - retval.push_back(convert<T>(split[i])); + retval.push_back(convert<typename V::value_type>(split[i])); } return retval; } -template<typename T, typename V> +template<typename T> T -ConfigParser::parseStructInternal(vespalib::stringref key, const V & config) +ConfigParser::parseStructInternal(vespalib::stringref key, Cfg config) { - V lines = getLinesForKey(key, config); + StringVector lines = getLinesForKey(key, config); return convert<T>(lines); } template<> bool -ConfigParser::convert<bool>(const vsvector & config); +ConfigParser::convert<bool>(const StringVector & config); template<> int32_t -ConfigParser::convert<int32_t>(const vsvector & config); +ConfigParser::convert<int32_t>(const StringVector & config); template<> int64_t -ConfigParser::convert<int64_t>(const vsvector & config); +ConfigParser::convert<int64_t>(const StringVector & config); template<> double -ConfigParser::convert<double>(const vsvector & config); +ConfigParser::convert<double>(const StringVector & config); template<> vespalib::string -ConfigParser::convert<vespalib::string>(const vsvector & config); +ConfigParser::convert<vespalib::string>(const StringVector & config); } // config diff --git a/config/src/vespa/config/common/configstate.h b/config/src/vespa/config/common/configstate.h index a0229f85cd5..0895517343c 100644 --- a/config/src/vespa/config/common/configstate.h +++ b/config/src/vespa/config/common/configstate.h @@ -1,7 +1,6 @@ // Copyright Yahoo. 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 "misc.h" namespace config { diff --git a/config/src/vespa/config/common/misc.cpp b/config/src/vespa/config/common/misc.cpp index 7eba045a2c7..31c66cd4eb8 100644 --- a/config/src/vespa/config/common/misc.cpp +++ b/config/src/vespa/config/common/misc.cpp @@ -39,6 +39,16 @@ calculateContentXxhash64(const StringVector & fileContents) return ss.str(); } +StringVector +getlines(vespalib::asciistream & is, char delim) +{ + StringVector lines; + while (!is.eof()) { + lines.push_back(is.getline(delim)); + } + return lines; +} + bool isGenerationNewer(int64_t newGen, int64_t oldGen) { diff --git a/config/src/vespa/config/common/misc.h b/config/src/vespa/config/common/misc.h index f26ee3df850..584a7ca527b 100644 --- a/config/src/vespa/config/common/misc.h +++ b/config/src/vespa/config/common/misc.h @@ -5,6 +5,7 @@ #include <memory> namespace vespalib { + class asciistream; class Slime; namespace slime { struct Inspector; @@ -32,4 +33,6 @@ typedef std::shared_ptr<const vespalib::Slime> SlimePtr; */ void copySlimeObject(const vespalib::slime::Inspector & src, vespalib::slime::Cursor & dest); +StringVector getlines(vespalib::asciistream & is, char delim='\n'); + } diff --git a/config/src/vespa/config/common/types.h b/config/src/vespa/config/common/types.h index b59685ffaa0..7bec2666db7 100644 --- a/config/src/vespa/config/common/types.h +++ b/config/src/vespa/config/common/types.h @@ -2,12 +2,13 @@ #pragma once #include <vespa/vespalib/stllike/string.h> +#include <vespa/vespalib/stllike/allocator.h> #include <vector> #include <map> namespace config { -using StringVector = std::vector<vespalib::string>; +using StringVector = std::vector<vespalib::string, vespalib::allocator_large<vespalib::string>>; using BoolVector = std::vector<bool>; using DoubleVector = std::vector<double>; using LongVector = std::vector<int64_t>; diff --git a/config/src/vespa/config/configgen/map_inserter.h b/config/src/vespa/config/configgen/map_inserter.h index 9f596912c5f..e35ee8cb0ac 100644 --- a/config/src/vespa/config/configgen/map_inserter.h +++ b/config/src/vespa/config/configgen/map_inserter.h @@ -4,12 +4,9 @@ #include "value_converter.h" #include <vespa/vespalib/data/slime/object_traverser.h> #include <vespa/vespalib/stllike/string.h> - #include <map> -namespace config { - -namespace internal { +namespace config::internal { template<typename T, typename Converter = config::internal::ValueConverter<T> > class MapInserter : public ::vespalib::slime::ObjectTraverser { @@ -20,9 +17,4 @@ private: std::map<vespalib::string, T> & _map; }; -} // namespace internal - -} // namespace config - -#include "map_inserter.hpp" - +} diff --git a/config/src/vespa/config/configgen/map_inserter.hpp b/config/src/vespa/config/configgen/map_inserter.hpp index 6ffdb0e893b..9bd04c95b11 100644 --- a/config/src/vespa/config/configgen/map_inserter.hpp +++ b/config/src/vespa/config/configgen/map_inserter.hpp @@ -1,7 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -namespace config { -namespace internal { +#pragma once + +#include "map_inserter.h" + +namespace config::internal { template<typename T, typename Converter> MapInserter<T, Converter>::MapInserter(std::map<vespalib::string, T> & map) @@ -16,6 +19,4 @@ MapInserter<T, Converter>::field(const ::vespalib::Memory & symbol, const ::vesp _map[symbol.make_string()] = converter(inspector); } -} // namespace internal - } diff --git a/config/src/vespa/config/configgen/value_converter.cpp b/config/src/vespa/config/configgen/value_converter.cpp index 4b25c6040da..36843456b25 100644 --- a/config/src/vespa/config/configgen/value_converter.cpp +++ b/config/src/vespa/config/configgen/value_converter.cpp @@ -54,7 +54,7 @@ template<> vespalib::string convertValue(const ::vespalib::slime::Inspector & __inspector) { return __inspector.asString().make_string(); } void -requireValid(const vespalib::string & __fieldName, const ::vespalib::slime::Inspector & __inspector) { +requireValid(vespalib::stringref __fieldName, const ::vespalib::slime::Inspector & __inspector) { if (!__inspector.valid()) { throw ::config::InvalidConfigException("Value for '" + __fieldName + "' required but not found"); } diff --git a/config/src/vespa/config/configgen/value_converter.h b/config/src/vespa/config/configgen/value_converter.h index 695e798b015..c583f1595dc 100644 --- a/config/src/vespa/config/configgen/value_converter.h +++ b/config/src/vespa/config/configgen/value_converter.h @@ -7,7 +7,7 @@ namespace config::internal { -void requireValid(const vespalib::string & __fieldName, const ::vespalib::slime::Inspector & __inspector); +void requireValid(vespalib::stringref __fieldName, const ::vespalib::slime::Inspector & __inspector); template<typename T> T convertValue(const ::vespalib::slime::Inspector & __inspector) { return T(::config::ConfigPayload(__inspector)); } @@ -29,7 +29,7 @@ vespalib::string convertValue(const ::vespalib::slime::Inspector & __inspector); template<typename T> struct ValueConverter { - T operator()(const vespalib::string & __fieldName, const ::vespalib::slime::Inspector & __inspector) { + T operator()(vespalib::stringref __fieldName, const ::vespalib::slime::Inspector & __inspector) { requireValid(__fieldName, __inspector); return convertValue<T>(__inspector); } diff --git a/config/src/vespa/config/configgen/vector_inserter.h b/config/src/vespa/config/configgen/vector_inserter.h index 3c5a406ef67..4b8c7a5e0a1 100644 --- a/config/src/vespa/config/configgen/vector_inserter.h +++ b/config/src/vespa/config/configgen/vector_inserter.h @@ -5,22 +5,15 @@ #include <vespa/vespalib/data/slime/array_traverser.h> #include <vespa/vespalib/stllike/string.h> -namespace config { +namespace config::internal { -namespace internal { - -template<typename T, typename Converter = ::config::internal::ValueConverter<T> > +template<typename V, typename Converter = ::config::internal::ValueConverter<typename V::value_type> > class VectorInserter : public ::vespalib::slime::ArrayTraverser { public: - VectorInserter(std::vector<T> & vector); + VectorInserter(V & vector); void entry(size_t idx, const ::vespalib::slime::Inspector & inspector) override; private: - std::vector<T> & _vector; + V & _vector; }; -} // namespace internal - -} // namespace config - -#include "vector_inserter.hpp" - +} diff --git a/config/src/vespa/config/configgen/vector_inserter.hpp b/config/src/vespa/config/configgen/vector_inserter.hpp index ed43dda07d6..31c3c52a358 100644 --- a/config/src/vespa/config/configgen/vector_inserter.hpp +++ b/config/src/vespa/config/configgen/vector_inserter.hpp @@ -1,22 +1,23 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -namespace config { -namespace internal { +#pragma once -template<typename T, typename Converter> -VectorInserter<T, Converter>::VectorInserter(std::vector<T> & vector) +#include "vector_inserter.h" + +namespace config::internal { + +template<typename V, typename Converter> +VectorInserter<V, Converter>::VectorInserter(V & vector) : _vector(vector) {} -template<typename T, typename Converter> +template<typename V, typename Converter> void -VectorInserter<T, Converter>::entry(size_t idx, const ::vespalib::slime::Inspector & inspector) +VectorInserter<V, Converter>::entry(size_t idx, const ::vespalib::slime::Inspector & inspector) { (void) idx; Converter converter; _vector.push_back(converter(inspector)); } -} // namespace internal - } diff --git a/config/src/vespa/config/file/filesource.cpp b/config/src/vespa/config/file/filesource.cpp index 1585bd1bd53..011868f7c06 100644 --- a/config/src/vespa/config/file/filesource.cpp +++ b/config/src/vespa/config/file/filesource.cpp @@ -53,7 +53,7 @@ StringVector FileSource::readConfigFile(const vespalib::string & fileName) { asciistream is(asciistream::createFromFile(fileName)); - return is.getlines(); + return getlines(is); } void diff --git a/config/src/vespa/config/raw/rawsource.cpp b/config/src/vespa/config/raw/rawsource.cpp index f37f30bb2f7..cf551106405 100644 --- a/config/src/vespa/config/raw/rawsource.cpp +++ b/config/src/vespa/config/raw/rawsource.cpp @@ -36,7 +36,7 @@ StringVector RawSource::readConfig() { vespalib::asciistream is(_payload); - return is.getlines(); + return getlines(is); } } diff --git a/config/src/vespa/config/set/configinstancesourcefactory.cpp b/config/src/vespa/config/set/configinstancesourcefactory.cpp index 64abaada0a4..15a6125d096 100644 --- a/config/src/vespa/config/set/configinstancesourcefactory.cpp +++ b/config/src/vespa/config/set/configinstancesourcefactory.cpp @@ -14,7 +14,7 @@ public: { } void close() override { } void getConfig() override { - _holder->handle(std::make_unique<config::ConfigUpdate>(config::ConfigValue(_buffer.getlines()), true, _generation)); + _holder->handle(std::make_unique<config::ConfigUpdate>(config::ConfigValue(config::getlines(_buffer)), true, _generation)); } void reload(int64_t generation) override { _generation = generation; } diff --git a/config/src/vespa/config/set/configsetsource.cpp b/config/src/vespa/config/set/configsetsource.cpp index 94547fbe63d..41886a12d01 100644 --- a/config/src/vespa/config/set/configsetsource.cpp +++ b/config/src/vespa/config/set/configsetsource.cpp @@ -30,7 +30,7 @@ ConfigSetSource::getConfig() vespalib::asciistream ss; AsciiConfigWriter writer(ss); writer.write(*instance); - StringVector lines(ss.getlines()); + StringVector lines(getlines(ss)); vespalib::string currentXxhash64(calculateContentXxhash64(lines)); if (isGenerationNewer(_generation, _lastState.generation) && currentXxhash64.compare(_lastState.xxhash64) != 0) { diff --git a/configgen/src/main/java/com/yahoo/config/codegen/CppClassBuilder.java b/configgen/src/main/java/com/yahoo/config/codegen/CppClassBuilder.java index 149bcced29c..d3a0a79c737 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/CppClassBuilder.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/CppClassBuilder.java @@ -3,14 +3,10 @@ package com.yahoo.config.codegen; import java.io.FileWriter; import java.io.File; -import java.io.BufferedReader; import java.io.IOException; -import java.io.FileReader; import java.io.StringWriter; import java.io.Writer; import java.util.Map; -import java.util.HashMap; -import java.util.Collections; import java.util.Arrays; import java.util.StringTokenizer; import java.util.stream.Collectors; @@ -24,39 +20,31 @@ public class CppClassBuilder implements ClassBuilder { private final NormalizedDefinition nd; private final File rootDir; private final String relativePathUnderRoot; - private static final Map<String, String> vectorTypeDefs; - static { - Map<String, String> map = new HashMap<String, String>(); - map.put("bool", "BoolVector"); - map.put("int32_t", "IntVector"); - map.put("int64_t", "LongVector"); - map.put("double", "DoubleVector"); - map.put("vespalib::string", "StringVector"); - vectorTypeDefs = Collections.unmodifiableMap(map); - } - private static final Map<String, String> mapTypeDefs; - static { - Map<String, String> map = new HashMap<>(); - map.put("bool", "BoolMap"); - map.put("int32_t", "IntMap"); - map.put("int64_t", "LongMap"); - map.put("double", "DoubleMap"); - map.put("vespalib::string", "StringMap"); - mapTypeDefs = Collections.unmodifiableMap(map); - } - private static final Map<String, String> slimeTypeMap; - static { - Map<String, String> map = new HashMap<String, String>(); - map.put("bool", "Bool"); - map.put("int", "Long"); - map.put("long", "Long"); - map.put("double", "Double"); - map.put("string", "String"); - map.put("enum", "String"); - map.put("file", "String"); - map.put("reference", "String"); - slimeTypeMap = Collections.unmodifiableMap(map); - } + private static final Map<String, String> vectorTypeDefs = Map.of( + "bool", "::config::BoolVector", + "int32_t", "::config::IntVector", + "int64_t", "::config::LongVector", + "double", "::config::DoubleVector", + "vespalib::string", "::config::StringVector" + ); + private static final Map<String, String> mapTypeDefs = Map.of( + "bool", "::config::BoolMap", + "int32_t", "::config::IntMap", + "int64_t", "::config::LongMap", + "double", "::config::DoubleMap", + "vespalib::string", "::config::StringMap" + ); + + private static final Map<String, String> slimeTypeMap = Map.of( + "bool", "Bool", + "int", "Long", + "long", "Long", + "double", "Double", + "string", "String", + "enum", "String", + "file", "String", + "reference", "String" + ); public CppClassBuilder(CNode root, NormalizedDefinition nd, File rootDir, String relativePathUnderRoot) { this.root = root; @@ -69,19 +57,6 @@ public class CppClassBuilder implements ClassBuilder { generateConfig(root, nd); } - String readFile(File f) throws IOException { - if (!f.isFile()) return null; - StringBuilder sb = new StringBuilder(); - try (BufferedReader sr = new BufferedReader(new FileReader(f))) { - while (true) { - String line = sr.readLine(); - if (line == null) break; - sb.append(line).append("\n"); - } - return sb.toString(); - } - } - void writeFile(File f, String content) throws IOException { FileWriter fw = new FileWriter(f); fw.write(content); @@ -118,7 +93,7 @@ public class CppClassBuilder implements ClassBuilder { static String removeDashesAndUpperCaseAllFirstChars(String source, boolean capitalizeFirst) { // Create upper case chars after each dash - String parts[] = source.split("[-_]"); + String [] parts = source.split("[-_]"); StringBuilder sb = new StringBuilder(); for (String s : parts) { sb.append(s.substring(0, 1).toUpperCase()).append(s.substring(1)); @@ -149,7 +124,7 @@ public class CppClassBuilder implements ClassBuilder { * Class to generate noexcept specifier if default constructor, copy constructor or copy assignment is non-throwing */ private static class NoExceptSpecifier { - private boolean enabled; + private final boolean enabled; public NoExceptSpecifier(CNode node) { enabled = checkNode(node); @@ -267,9 +242,7 @@ public class CppClassBuilder implements ClassBuilder { + "#define CLOUD_CONFIG_" + defineName + "_H\n" + "\n" + "#include <vespa/config/configgen/configinstance.h>\n" - + "#include <vespa/vespalib/stllike/string.h>\n" - + "#include <vector>\n" - + "#include <map>\n" + + "#include <vespa/config/common/types.h>\n" + "\n"); w.write("namespace config {\n"); w.write(" class ConfigValue;\n"); @@ -295,7 +268,7 @@ public class CppClassBuilder implements ClassBuilder { void writeTypeDeclarations(Writer w, CNode node, String indent) throws IOException { - java.util.Set<String> declaredTypes = new java.util.HashSet<String>(); + java.util.Set<String> declaredTypes = new java.util.HashSet<>(); for (CNode child : node.getChildren()) { boolean complexType = (child instanceof InnerCNode || child instanceof LeafCNode.EnumLeaf); if (complexType && !declaredTypes.contains(child.getName())) { @@ -357,7 +330,7 @@ public class CppClassBuilder implements ClassBuilder { } void writeStructFunctionDeclarations(Writer w, String className, CNode node, String indent) throws IOException { - w.write(indent + className + "(const std::vector<vespalib::string> & __lines);\n"); + w.write(indent + className + "(const " + vectorTypeDefs.get("vespalib::string") + " & __lines);\n"); w.write(indent + className + "(const vespalib::slime::Inspector & __inspector);\n"); w.write(indent + className + "(const ::config::ConfigPayload & __payload);\n"); writeCommonFunctionDeclarations(w, className, node, indent); @@ -370,6 +343,12 @@ public class CppClassBuilder implements ClassBuilder { void writeClassAssignmentOperatorDeclaration(Writer w, String className, NoExceptSpecifier noexcept, String indent) throws IOException { w.write(indent + className + " & operator = (const " + className + " & __rhs)" + noexcept + ";\n"); } + void writeClassMoveConstructorDeclaration(Writer w, String className, NoExceptSpecifier noexcept, String indent) throws IOException { + w.write(indent + className + "(" + className + " && __rhs)" + noexcept + ";\n"); + } + void writeClassMoveOperatorDeclaration(Writer w, String className, NoExceptSpecifier noexcept, String indent) throws IOException { + w.write(indent + className + " & operator = (" + className + " && __rhs)" + noexcept + ";\n"); + } void writeConfigClassCopyConstructorDefinition(Writer w, String parent, String className, NoExceptSpecifier noexcept) throws IOException { w.write(parent + "::" + className + "(const " + className + " & __rhs)" + noexcept + " = default;\n"); @@ -377,12 +356,23 @@ public class CppClassBuilder implements ClassBuilder { void writeConfigClassAssignmentOperatorDefinition(Writer w, String parent, String className, NoExceptSpecifier noexcept) throws IOException { w.write(parent + " & " + parent + "::" + "operator =(const " + className + " & __rhs)" + noexcept + " = default;\n"); } + void writeConfigClassMoveConstructorDefinition(Writer w, String parent, String className, NoExceptSpecifier noexcept) throws IOException { + w.write(parent + "::" + className + "(" + className + " && __rhs)" + noexcept + " = default;\n"); + } + void writeConfigClassMoveOperatorDefinition(Writer w, String parent, String className, NoExceptSpecifier noexcept) throws IOException { + w.write(parent + " & " + parent + "::" + "operator =(" + className + " && __rhs)" + noexcept + " = default;\n"); + } void writeClassCopyConstructorDefinition(Writer w, String parent, CNode node) throws IOException { String typeName = getTypeName(node, false); NoExceptSpecifier noexcept = new NoExceptSpecifier(node); w.write(parent + "::" + typeName + "(const " + typeName + " & __rhs)" + noexcept + " = default;\n"); } + void writeClassMoveConstructorDefinition(Writer w, String parent, CNode node) throws IOException { + String typeName = getTypeName(node, false); + NoExceptSpecifier noexcept = new NoExceptSpecifier(node); + w.write(parent + "::" + typeName + "(" + typeName + " && __rhs)" + noexcept + " = default;\n"); + } void writeClassAssignmentOperatorDefinition(Writer w, String parent, CNode node) throws IOException { String typeName = getTypeName(node, false); @@ -391,8 +381,15 @@ public class CppClassBuilder implements ClassBuilder { w.write(parent + " & " + parent + "::" + "operator = (const " + typeName + " & __rhs)" + noexcept + " = default;\n"); } + void writeClassMoveOperatorDefinition(Writer w, String parent, CNode node) throws IOException { + String typeName = getTypeName(node, false); + NoExceptSpecifier noexcept = new NoExceptSpecifier(node); + // Write empty constructor + w.write(parent + " & " + parent + "::" + "operator = (" + typeName + " && __rhs)" + noexcept + " = default;\n"); + } + void writeDestructor(Writer w, String parent, String className) throws IOException { - w.write(parent + "~" + className + "() { } \n"); + w.write(parent + "~" + className + "() = default; \n"); } void writeCommonFunctionDeclarations(Writer w, String className, CNode node, String indent) throws IOException { @@ -400,6 +397,8 @@ public class CppClassBuilder implements ClassBuilder { w.write("" + indent + className + "() " + noexcept + ";\n"); writeClassCopyConstructorDeclaration(w, className, noexcept, indent); writeClassAssignmentOperatorDeclaration(w, className, noexcept, indent); + writeClassMoveConstructorDeclaration(w, className, noexcept, indent); + writeClassMoveOperatorDeclaration(w, className, noexcept, indent); w.write("" + indent + "~" + className + "();\n"); w.write("\n" + indent + "bool operator==(const " + className + "& __rhs) const noexcept;\n" @@ -460,7 +459,7 @@ public class CppClassBuilder implements ClassBuilder { + indent + "static const vespalib::string CONFIG_DEF_VERSION;\n" + indent + "static const vespalib::string CONFIG_DEF_NAME;\n" + indent + "static const vespalib::string CONFIG_DEF_NAMESPACE;\n" - + indent + "static const std::vector<vespalib::string> CONFIG_DEF_SCHEMA;\n" + + indent + "static const ::config::StringVector CONFIG_DEF_SCHEMA;\n" + indent + "static const int64_t CONFIG_DEF_SERIALIZE_VERSION;\n" + "\n" ); @@ -469,7 +468,7 @@ public class CppClassBuilder implements ClassBuilder { void writeComment(Writer w, String indent, String comment, boolean javadoc) throws IOException { - /** If simple one liner comment, write on one line. */ + // If simple one liner comment, write on one line. if (javadoc && comment.indexOf('\n') == -1 && comment.length() <= 80 - (indent.length() + 7)) { @@ -481,7 +480,7 @@ public class CppClassBuilder implements ClassBuilder { w.write(indent + "// " + comment + "\n"); return; } - /** If not we need to write multi line comment. */ + // If not we need to write multi line comment. int maxLineLen = 80 - (indent.length() + 3); if (javadoc) w.write(indent + "/**\n"); do { @@ -543,18 +542,6 @@ public class CppClassBuilder implements ClassBuilder { void writeHeaderTypeDefs(Writer w, CNode root, String indent) throws IOException { w.write(indent + "typedef std::unique_ptr<const " + getInternalClassName(root) + "> UP;\n"); - for (Map.Entry<String, String> entry : vectorTypeDefs.entrySet()) { - String typeName = entry.getKey(); - String vectorName = entry.getValue(); - String typeDef = "typedef std::vector<" + typeName + "> " + vectorName; - w.write(indent + typeDef + ";\n"); - } - for (Map.Entry<String, String> entry : mapTypeDefs.entrySet()) { - String typeName = entry.getKey(); - String mapName = entry.getValue(); - String typeDef = "typedef std::map<vespalib::string, " + typeName + "> " + mapName; - w.write(indent + typeDef + ";\n"); - } } private static String getInternalClassName(CNode root) { @@ -599,11 +586,11 @@ public class CppClassBuilder implements ClassBuilder { w.write("#include <vespa/config/configgen/configpayload.h>\n"); w.write("#include <vespa/config/print/configdatabuffer.h>\n"); w.write("#include <vespa/config/common/configparser.h>\n"); - w.write("#include <vespa/config/configgen/vector_inserter.h>\n"); - w.write("#include <vespa/config/configgen/map_inserter.h>\n"); w.write("#include <vespa/vespalib/data/slime/convenience.h>\n"); w.write("#include <vespa/vespalib/data/slime/slime.h>\n"); w.write("#include <vespa/vespalib/stllike/asciistream.h>\n"); + w.write("#include <vespa/config/configgen/vector_inserter.hpp>\n"); + w.write("#include <vespa/config/configgen/map_inserter.hpp>\n"); w.write("\n"); writeNameSpaceBegin(w, generateCppNameSpace(root)); w.write("\nnamespace internal {\n\n"); @@ -627,7 +614,7 @@ public class CppClassBuilder implements ClassBuilder { w.write("\"" + line.replace("\"", "\\\"") + "\",\n"); } w.write("};\n"); - w.write("const std::vector<vespalib::string> " + typeName + "::CONFIG_DEF_SCHEMA(__internalDefSchema,\n"); + w.write("const ::config::StringVector " + typeName + "::CONFIG_DEF_SCHEMA(__internalDefSchema,\n"); w.write(" __internalDefSchema + (sizeof(__internalDefSchema) / \n"); w.write(" sizeof(__internalDefSchema[0])));\n"); w.write("\n"); @@ -640,7 +627,7 @@ public class CppClassBuilder implements ClassBuilder { root = true; } final String parent = fullClassName + "::"; - java.util.Set<String> declaredTypes = new java.util.HashSet<String>(); + java.util.Set<String> declaredTypes = new java.util.HashSet<>(); for (CNode child : node.getChildren()) { boolean complexType = (child instanceof InnerCNode || child instanceof LeafCNode.EnumLeaf); if (complexType && !declaredTypes.contains(child.getName())) { @@ -755,9 +742,13 @@ public class CppClassBuilder implements ClassBuilder { if (root) { writeConfigClassCopyConstructorDefinition(w, fullClassName, typeName, noexcept); writeConfigClassAssignmentOperatorDefinition(w, fullClassName, typeName, noexcept); + writeConfigClassMoveConstructorDefinition(w, fullClassName, typeName, noexcept); + writeConfigClassMoveOperatorDefinition(w, fullClassName, typeName, noexcept); } else { writeClassCopyConstructorDefinition(w, fullClassName, node); writeClassAssignmentOperatorDefinition(w, fullClassName, node); + writeClassMoveConstructorDefinition(w, fullClassName, node); + writeClassMoveOperatorDefinition(w, fullClassName, node); } writeDestructor(w, parent, typeName); @@ -768,30 +759,20 @@ public class CppClassBuilder implements ClassBuilder { + "{\n" + indent + "try {\n"); indent = " "; - w.write(indent + "const std::vector<vespalib::string> & __lines(__value.getLines());\n"); + w.write(indent + "const " + vectorTypeDefs.get("vespalib::string") + " & __lines(__value.getLines());\n"); } else { - w.write(parent + typeName + "(const std::vector<vespalib::string> & __lines)\n" + w.write(parent + typeName + "(const " + vectorTypeDefs.get("vespalib::string") +" & __lines)\n" + "{\n"); } - w.write("" - + indent + "std::set<vespalib::string> __remainingValuesToParse(" - + "__lines.begin(), __lines.end());\n"); - w.write(indent + "for(std::set<vespalib::string>::iterator __rVTPiter = __remainingValuesToParse.begin();\n" - + indent + " __rVTPiter != __remainingValuesToParse.end();)\n" - + indent + "{\n" - + indent + " if (ConfigParser::stripWhitespace(*__rVTPiter).empty()) {\n" - + indent + " std::set<vespalib::string>::iterator __rVTPiter2 = __rVTPiter++;\n" - + indent + " __remainingValuesToParse.erase(__rVTPiter2);\n" - + indent + " } else {\n" - + indent + " ++__rVTPiter;\n" - + indent + " }\n" - + indent + "}\n"); + w.write(indent + "std::set<vespalib::string> __remainingValuesToParse = ConfigParser::getUniqueNonWhiteSpaceLines(__lines);\n"); for (CNode child : node.getChildren()) { String childType = getTypeName(child, false); String childName = getIdentifier(child.getName()); + String childVectorType = null; if (child instanceof LeafCNode.EnumLeaf) { if (child.isArray) { - w.write(indent + "std::vector<vespalib::string> " + childName + "__ValueList(\n "); + childVectorType = "::config::StringVector"; + w.write(indent + childVectorType + " " + childName + "__ValueList(\n "); } else if (child.isMap) { w.write(indent + "std::map<vespalib::string, vespalib::string> " + childName + "__ValueMap(\n "); } else { @@ -802,18 +783,17 @@ public class CppClassBuilder implements ClassBuilder { w.write(indent + childName + " = "); } if (child.isArray) { - w.write("ConfigParser::parseArray<" + childType + ">(\"" - + child.getName() + "\", __lines)"); + if (childVectorType == null) { + childVectorType = getTypeName(child, true); + } + w.write("ConfigParser::parseArray<" + childVectorType + ">(\"" + child.getName() + "\", __lines)"); } else if (child.isMap) { - w.write("ConfigParser::parseMap<" + childType + ">(\"" - + child.getName() + "\", __lines)"); + w.write("ConfigParser::parseMap<" + childType + ">(\"" + child.getName() + "\", __lines)"); } else { if (child instanceof LeafCNode) { - w.write("ConfigParser::parse<" + childType + ">(\"" - + child.getName() + "\", __lines"); + w.write("ConfigParser::parse<" + childType + ">(\"" + child.getName() + "\", __lines"); } else { - w.write("ConfigParser::parseStruct<" + childType + ">(\"" - + child.getName() + "\", __lines"); + w.write("ConfigParser::parseStruct<" + childType + ">(\"" + child.getName() + "\", __lines"); } if (child instanceof LeafCNode && ((LeafCNode) child).getDefaultValue() != null) { LeafCNode leaf = (LeafCNode) child; @@ -832,26 +812,20 @@ public class CppClassBuilder implements ClassBuilder { w.write(");\n"); if (child.isArray) { w.write(indent + childName + ".reserve(" + childName + "__ValueList.size());\n" - + indent + "for (std::vector<vespalib::string>::const_iterator __it\n" - + indent + " = " + childName + "__ValueList.begin();\n" - + indent + " __it != " + childName + "__ValueList.end(); ++__it)\n" - + indent + "{\n" - + indent + " " + childName + ".push_back(get" + childType + "(*__it));\n" + + indent + "for (const auto & item : " + childName + "__ValueList) {\n" + + indent + " " + childName + ".push_back(get" + childType + "(item));\n" + indent + "}\n" ); } else if (child.isMap) { - w.write(indent + "typedef std::map<vespalib::string, vespalib::string> __ValueMap;\n"); - w.write(indent + "for (__ValueMap::iterator __it(" + childName + "__ValueMap.begin()), __mt(" + childName + "__ValueMap.end()); __it != __mt; __it++) {\n" - + " " + childName + "[__it->first] = get" + childType + "(__it->second);\n" + w.write(indent + "for (const auto & entry : " + childName + "__ValueMap) {\n" + + " " + childName + "[entry.first] = get" + childType + "(entry.second);\n" + "}\n" ); } } else { w.write(";\n"); } - w.write(indent + "ConfigParser::stripLinesForKey(\"" - + child.getName() + "\", " - + "__remainingValuesToParse);\n"); + w.write(indent + "ConfigParser::stripLinesForKey(\"" + child.getName() + "\", " + "__remainingValuesToParse);\n"); } if (root) { indent = " "; @@ -864,9 +838,8 @@ public class CppClassBuilder implements ClassBuilder { + "\n" ); // Write operator== - String lineBreak = (parent.length() + typeName.length() < 50 ? "" : "\n"); w.write("bool\n" - + parent + lineBreak + "operator==(const " + typeName + "& __rhs) const noexcept\n" + + parent + lineBreak(parent, typeName) + "operator==(const " + typeName + "& __rhs) const noexcept\n" + "{\n" + " return (" ); @@ -883,9 +856,8 @@ public class CppClassBuilder implements ClassBuilder { + "\n" ); // Write operator!= - lineBreak = (parent.length() + typeName.length() < 50 ? "" : "\n"); w.write("bool\n" - + parent + lineBreak + "operator!=(const " + typeName + "& __rhs) const noexcept\n" + + parent + lineBreak(parent, typeName) + "operator!=(const " + typeName + "& __rhs) const noexcept\n" + "{\n" + " return !(operator==(__rhs));\n" + "}\n" @@ -896,6 +868,10 @@ public class CppClassBuilder implements ClassBuilder { writeSlimeConstructor(w, node, parent, root); } + private static String lineBreak(String parent, String typeName) { + return (parent.length() + typeName.length() < 50 ? "" : "\n"); + } + public void writeSlimeEncoder(Writer w, CNode node, String parent, boolean root) throws IOException { String indent = " "; @@ -929,55 +905,54 @@ public class CppClassBuilder implements ClassBuilder { if (child.isArray) { w.write(indent + "__c.setString(\"type\", \"array\");\n"); w.write(indent + "vespalib::slime::Cursor & __c2 = __c.setArray(\"value\");\n"); - w.write(indent + "for (size_t __i = 0; __i < " + childName + ".size(); __i++) {\n"); + w.write(indent + "for (const auto & child : " + childName +") {\n"); w.write(indent + " vespalib::slime::Cursor & __c3 = __c2.addObject();\n"); if (child instanceof LeafCNode.EnumLeaf) { String repType = slimeTypeMap.get("enum"); w.write(indent + " __c3.setString(\"type\", \"enum\");\n"); w.write(indent + " __c3.set" + repType); - w.write("(\"value\", vespalib::Memory(get" + childType + "Name(" + childName + "[__i])));\n"); + w.write("(\"value\", vespalib::Memory(get" + childType + "Name(child)));\n"); } else if (child instanceof LeafCNode) { String type = ((LeafCNode) child).getType(); String repType = slimeTypeMap.get(type); w.write(indent + " __c3.setString(\"type\", \"" + type + "\");\n"); w.write(indent + " __c3.set" + repType); if ("String".equals(repType)) { - w.write("(\"value\", vespalib::Memory(" + childName + "[__i]));\n"); + w.write("(\"value\", vespalib::Memory(child));\n"); } else { - w.write("(\"value\", " + childName + "[__i]);\n"); + w.write("(\"value\", child);\n"); } } else { w.write(indent + " __c3.setString(\"type\", \"struct\");\n"); w.write(indent + " Cursor & __c4 = __c3.setObject(\"value\");\n"); - w.write(indent + " " + childName + "[__i].serialize(__c4);\n"); + w.write(indent + " child.serialize(__c4);\n"); } w.write(indent + "}\n"); } else if (child.isMap) { w.write(indent + "__c.setString(\"type\", \"map\");\n"); w.write(indent + "vespalib::slime::Cursor & __c2 = __c.setArray(\"value\");\n"); - String childMapType = getTypeName(child, true); - w.write(indent + "for (" + childMapType + "::const_iterator it(" + childName + ".begin()), mt(" + childName + ".end()); it != mt; it++) {\n"); + w.write(indent + "for (const auto & entry : " + childName + ") {\n"); w.write(indent + " vespalib::slime::Cursor & __c3 = __c2.addObject();\n"); - w.write(indent + " __c3.setString(\"key\", vespalib::Memory(it->first));\n"); + w.write(indent + " __c3.setString(\"key\", vespalib::Memory(entry.first));\n"); if (child instanceof LeafCNode.EnumLeaf) { String repType = slimeTypeMap.get("enum"); w.write(indent + " __c3.setString(\"type\", \"enum\");\n"); w.write(indent + " __c3.set" + repType); - w.write("(\"value\", vespalib::Memory(get" + childType + "Name(it->second)));\n"); + w.write("(\"value\", vespalib::Memory(get" + childType + "Name(entry.second)));\n"); } else if (child instanceof LeafCNode) { String type = ((LeafCNode) child).getType(); String repType = slimeTypeMap.get(type); w.write(indent + " __c3.setString(\"type\", \"" + type + "\");\n"); w.write(indent + " __c3.set" + repType); if ("String".equals(repType)) { - w.write("(\"value\", vespalib::Memory(it->second));\n"); + w.write("(\"value\", vespalib::Memory(entry.second));\n"); } else { - w.write("(\"value\", it->second);\n"); + w.write("(\"value\", entry.second);\n"); } } else { w.write(indent + " __c3.setString(\"type\", \"struct\");\n"); w.write(indent + " Cursor & __c4 = __c3.setObject(\"value\");\n"); - w.write(indent + " it->second.serialize(__c4);\n"); + w.write(indent + " entry.second.serialize(__c4);\n"); } w.write(indent + "}\n"); } else { @@ -1033,39 +1008,13 @@ public class CppClassBuilder implements ClassBuilder { if (child.isArray) { w.write(indent + "for (size_t __i = 0; __i < " + inspectorLine + ".children(); __i++) {\n"); w.write(indent + " " + childName + ".push_back("); - if (child instanceof LeafCNode.EnumLeaf) { - String repType = slimeTypeMap.get("enum"); - w.write("get" + childType + "(" + inspectorLine + "[__i][\"value\"].as" + repType + "().make_string())"); - } else if (child instanceof LeafCNode) { - String type = ((LeafCNode) child).getType(); - String repType = slimeTypeMap.get(type); - if ("String".equals(repType)) { - w.write("" + inspectorLine + "[__i][\"value\"].as" + repType + "().make_string()"); - } else { - w.write("" + inspectorLine + "[__i][\"value\"].as" + repType + "()"); - } - } else { - w.write(childType + "(" + inspectorLine + "[__i][\"value\"])"); - } + writeSlimeChild(w, child, childType, inspectorLine); w.write(");\n"); w.write(indent + "}\n"); } else if (child.isMap) { w.write(indent + "for (size_t __i = 0; __i < " + inspectorLine + ".children(); __i++) {\n"); w.write(indent + " " + childName + "[" + inspectorLine + "[__i][\"key\"].asString().make_string()] = "); - if (child instanceof LeafCNode.EnumLeaf) { - String repType = slimeTypeMap.get("enum"); - w.write("get" + childType + "(" + inspectorLine + "[__i][\"value\"].as" + repType + "().make_string())"); - } else if (child instanceof LeafCNode) { - String type = ((LeafCNode) child).getType(); - String repType = slimeTypeMap.get(type); - if ("String".equals(repType)) { - w.write("" + inspectorLine + "[__i][\"value\"].as" + repType + "().make_string()"); - } else { - w.write("" + inspectorLine + "[__i][\"value\"].as" + repType + "()"); - } - } else { - w.write(childType + "(" + inspectorLine + "[__i][\"value\"])"); - } + writeSlimeChild(w, child, childType, inspectorLine); w.write(";\n"); w.write(indent + "}\n"); } else { @@ -1090,6 +1039,23 @@ public class CppClassBuilder implements ClassBuilder { w.write("}\n\n"); } + private void writeSlimeChild(Writer w, CNode child, String childType, String inspectorLine) throws IOException { + if (child instanceof LeafCNode.EnumLeaf) { + String repType = slimeTypeMap.get("enum"); + w.write("get" + childType + "(" + inspectorLine + "[__i][\"value\"].as" + repType + "().make_string())"); + } else if (child instanceof LeafCNode) { + String type = ((LeafCNode) child).getType(); + String repType = slimeTypeMap.get(type); + if ("String".equals(repType)) { + w.write("" + inspectorLine + "[__i][\"value\"].as" + repType + "().make_string()"); + } else { + w.write("" + inspectorLine + "[__i][\"value\"].as" + repType + "()"); + } + } else { + w.write(childType + "(" + inspectorLine + "[__i][\"value\"])"); + } + } + public void writeSlimeConstructor(Writer w, CNode node, String parent, boolean root) throws IOException { String tmpName = getTypeName(node, false); String typeName = root ? getInternalClassName(node) : tmpName; @@ -1110,7 +1076,8 @@ public class CppClassBuilder implements ClassBuilder { String childInspector = "__inspector[\"" + child.getName() + "\"]"; if (child.isArray) { String inserterName = "__" + childName + "Inserter"; - w.write(indent + "::config::internal::VectorInserter<" + childType); + String childVectorType = getTypeName(child, true); + w.write(indent + "::config::internal::VectorInserter<" + childVectorType); if (child instanceof LeafCNode.EnumLeaf) { w.write(", Internal" + childType + "Converter"); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ModelContextImpl.java b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ModelContextImpl.java index 547494efcba..c50b75b3460 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ModelContextImpl.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ModelContextImpl.java @@ -205,7 +205,6 @@ public class ModelContextImpl implements ModelContext { private final double persistenceThrottlingWsDecrementFactor; private final double persistenceThrottlingWsBackoff; private final boolean useQrserverServiceName; - private final boolean enableJdiscPreshutdownCommand; public FeatureFlags(FlagSource source, ApplicationId appId) { this.defaultTermwiseLimit = flagValue(source, appId, Flags.DEFAULT_TERM_WISE_LIMIT); @@ -249,7 +248,6 @@ public class ModelContextImpl implements ModelContext { this.persistenceThrottlingWsDecrementFactor = flagValue(source, appId, Flags.PERSISTENCE_THROTTLING_WS_DECREMENT_FACTOR); this.persistenceThrottlingWsBackoff = flagValue(source, appId, Flags.PERSISTENCE_THROTTLING_WS_BACKOFF); this.useQrserverServiceName = flagValue(source, appId, Flags.USE_QRSERVER_SERVICE_NAME); - this.enableJdiscPreshutdownCommand = flagValue(source, appId, Flags.ENABLE_JDISC_PRESHUTDOWN_COMMAND); } @Override public double defaultTermwiseLimit() { return defaultTermwiseLimit; } @@ -295,7 +293,6 @@ public class ModelContextImpl implements ModelContext { @Override public double persistenceThrottlingWsDecrementFactor() { return persistenceThrottlingWsDecrementFactor; } @Override public double persistenceThrottlingWsBackoff() { return persistenceThrottlingWsBackoff; } @Override public boolean useQrserverServiceName() { return useQrserverServiceName; } - @Override public boolean enableJdiscPreshutdownCommand() { return enableJdiscPreshutdownCommand; } private static <V> V flagValue(FlagSource source, ApplicationId appId, UnboundFlag<? extends V, ?, ?> flag) { return flag.bindTo(source) diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/HttpRequest.java b/container-core/src/main/java/com/yahoo/container/jdisc/HttpRequest.java index 6f5cc5722c8..927284f2c66 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/HttpRequest.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/HttpRequest.java @@ -552,11 +552,6 @@ public class HttpRequest { } @Override - public <T> T getInstance(Key<T> tKey) { - return null; - } - - @Override public <T> T getInstance(Class<T> tClass) { return null; } diff --git a/container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java b/container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java index e95dbcbcb22..e78810db897 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java @@ -187,11 +187,6 @@ public class VipStatusHandlerTestCase { } @Override - public <T> T getInstance(Key<T> tKey) { - return null; - } - - @Override public <T> T getInstance(Class<T> tClass) { return null; } diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java b/container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java index 5f46184bf89..ae0f679771e 100644 --- a/container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/jdisc/LoggingRequestHandlerTestCase.java @@ -150,11 +150,6 @@ public class LoggingRequestHandlerTestCase { } @Override - public <T> T getInstance(Key<T> tKey) { - return null; - } - - @Override public <T> T getInstance(Class<T> tClass) { return null; } diff --git a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpRequestFactoryTest.java b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpRequestFactoryTest.java index e2ebdf7a8fc..d1ba4a4d190 100644 --- a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpRequestFactoryTest.java +++ b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpRequestFactoryTest.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jdisc.http.server.jetty; -import com.google.inject.Key; import com.yahoo.jdisc.Container; import com.yahoo.jdisc.References; import com.yahoo.jdisc.ResourceReference; @@ -158,11 +157,6 @@ public class HttpRequestFactoryTest { } @Override - public <T> T getInstance(Key<T> tKey) { - return null; - } - - @Override public <T> T getInstance(Class<T> tClass) { return null; } diff --git a/container-disc/src/main/java/com/yahoo/container/jdisc/ConfiguredApplication.java b/container-disc/src/main/java/com/yahoo/container/jdisc/ConfiguredApplication.java index f527937854f..aa70bd8197f 100644 --- a/container-disc/src/main/java/com/yahoo/container/jdisc/ConfiguredApplication.java +++ b/container-disc/src/main/java/com/yahoo/container/jdisc/ConfiguredApplication.java @@ -330,9 +330,12 @@ public final class ConfiguredApplication implements Application { synchronized (monitor) { Set<ServerProvider> serversToClose = createIdentityHashSet(startedServers); serversToClose.removeAll(currentServers); - for (ServerProvider server : serversToClose) { - server.close(); - startedServers.remove(server); + if (serversToClose.size() > 0) { + log.info(String.format("Closing %d server instances", serversToClose.size())); + for (ServerProvider server : serversToClose) { + server.close(); + startedServers.remove(server); + } } for (ServerProvider server : currentServers) { if (!startedServers.contains(server)) { @@ -383,37 +386,35 @@ public final class ConfiguredApplication implements Application { @Override public void stop() { + log.info("Stop: Initiated"); shutdownDeadline.schedule((long)(shutdownTimeoutS.get() * 1000), dumpHeapOnShutdownTimeout.get()); - stopServersAndAwaitTermination("Stop"); + stopServersAndAwaitTermination(); + log.info("Stop: Finished"); } private void prepareStop(Request request) { + log.info("PrepareStop: Initiated"); long timeoutMillis = (long) (request.parameters().get(0).asDouble() * 1000); try (ShutdownDeadline ignored = new ShutdownDeadline(configId).schedule(timeoutMillis, dumpHeapOnShutdownTimeout.get())) { - stopServersAndAwaitTermination("PrepareStop"); + stopServersAndAwaitTermination(); + log.info("PrepareStop: Finished"); } catch (Exception e) { request.setError(ErrorCode.METHOD_FAILED, e.getMessage()); throw e; } } - private void stopServersAndAwaitTermination(String logPrefix) { + private void stopServersAndAwaitTermination() { shutdownReconfigurer(); - log.info(logPrefix + ": Closing servers"); startAndStopServers(List.of()); startAndRemoveClients(List.of()); - log.info(logPrefix + ": Waiting for all in-flight requests to complete"); - activateContainer(null, () -> {}); + activateContainer(null, () -> log.info("Last active container generation has terminated")); nonTerminatedContainerTracker.arriveAndAwaitAdvance(); - log.info(logPrefix + ": Finished"); } private void shutdownReconfigurer() { - if (!reconfigurerThread.isAlive()) { - log.info("Reconfiguration thread shutdown already completed"); - return; - } + if (!reconfigurerThread.isAlive()) return; log.info("Shutting down reconfiguration thread"); long start = System.currentTimeMillis(); shutdownReconfiguration = true; @@ -421,7 +422,7 @@ public final class ConfiguredApplication implements Application { try { reconfigurerThread.join(); log.info(String.format( - "Reconfiguration shutdown completed in %.3f seconds", (System.currentTimeMillis() - start) / 1000D)); + "Reconfiguration thread shutdown completed in %.3f seconds", (System.currentTimeMillis() - start) / 1000D)); } catch (InterruptedException e) { String message = "Interrupted while waiting for reconfiguration shutdown"; log.warning(message); diff --git a/container-disc/src/main/sh/vespa-start-container-daemon.sh b/container-disc/src/main/sh/vespa-start-container-daemon.sh index 1aad9f18616..a6c2c5999a8 100755 --- a/container-disc/src/main/sh/vespa-start-container-daemon.sh +++ b/container-disc/src/main/sh/vespa-start-container-daemon.sh @@ -46,6 +46,7 @@ printenv > $cfpfile || exit 1 getconfig() { + set -e qrstartcfg="" case "${VESPA_CONFIG_ID}" in dir:*) @@ -58,6 +59,7 @@ getconfig() { esac cmds=`echo "$qrstartcfg" | perl -ne 's/^(\w+)\.(\w+) (.*)/$1_$2=$3/ && print'` eval "$cmds" + set +e } # Print the value of the cgroups v2 interface filename $1 for current process, diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json index c54a217d34f..1ce0ff610be 100644 --- a/container-search/abi-spec.json +++ b/container-search/abi-spec.json @@ -7158,6 +7158,7 @@ "methods": [ "public void <init>(com.fasterxml.jackson.core.JsonGenerator, boolean)", "public void <init>(com.fasterxml.jackson.core.JsonGenerator, boolean, boolean)", + "protected void <init>(boolean, boolean, boolean)", "public void <init>(com.fasterxml.jackson.core.JsonGenerator, boolean, boolean, boolean)", "public void accept(java.lang.String, java.lang.Object)", "public void accept(java.lang.String, byte[], int, int)", @@ -7199,6 +7200,7 @@ "public void endResponse()", "public java.lang.String getEncoding()", "public java.lang.String getMimeType()", + "protected com.yahoo.search.rendering.JsonRenderer$FieldConsumer createFieldConsumer(boolean)", "protected com.yahoo.search.rendering.JsonRenderer$FieldConsumer createFieldConsumer(com.fasterxml.jackson.core.JsonGenerator, boolean)" ], "fields": [] diff --git a/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java b/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java index f9a91558254..4666270c4bd 100644 --- a/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java +++ b/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java @@ -151,8 +151,12 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> { * method will be invoked when creating the first renderer instance, but not * for each fresh clone used by individual results. * + * @deprecated Will be removed in Vespa 8. Override the individual render methods of {@link JsonRenderer} to alter + * rendering behaviour. Override {@link #createFieldConsumer(boolean)} and sub-class {@link FieldConsumer} + * to alter rendering of hit fields. * @return an object mapper for the internal JsonFactory */ + @Deprecated(forRemoval = true, since = "7") // TODO Vespa 8 make private protected static ObjectMapper createJsonCodec() { return new ObjectMapper().disable(FLUSH_AFTER_WRITE_VALUE); } @@ -525,6 +529,13 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> { this.fieldConsumer = generator == null ? null : createFieldConsumer(generator, debugRendering, jsonMaps); } + /** Override this method to use a custom {@link FieldConsumer} sub-class to render fields */ + protected FieldConsumer createFieldConsumer(boolean debugRendering) { + return createFieldConsumer(generator, debugRendering, this.jsonMaps); + } + + /** @deprecated Will be removed in Vespa 8. Use {@link #createFieldConsumer(boolean)} instead. */ + @Deprecated(forRemoval = true, since = "7") // TODO Vespa 8 remove method protected FieldConsumer createFieldConsumer(JsonGenerator generator, boolean debugRendering) { return createFieldConsumer(generator, debugRendering, this.jsonMaps); } @@ -554,12 +565,25 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> { private MutableBoolean hasFieldsField; + /** @deprecated Will be removed in Vespa 8. Use {@link #FieldConsumer(boolean, boolean, boolean)} instead. */ + @Deprecated(forRemoval = true, since = "7") // TODO Vespa 8 Remove public FieldConsumer(JsonGenerator generator, boolean debugRendering) { this(generator, debugRendering, false); } + + /** @deprecated Will be removed in Vespa 8. Use {@link #FieldConsumer(boolean, boolean, boolean)} instead. */ + @Deprecated(forRemoval = true, since = "7") // TODO Vespa 8 Remove public FieldConsumer(JsonGenerator generator, boolean debugRendering, boolean tensorShortForm) { this(generator, debugRendering, tensorShortForm, false); } + + /** Invoke this from your constructor when sub-classing {@link FieldConsumer} */ + protected FieldConsumer(boolean debugRendering, boolean tensorShortForm, boolean jsonMaps) { + this(null, debugRendering, tensorShortForm, jsonMaps); + } + + /** @deprecated Will be removed in Vespa 8. Use {@link #FieldConsumer(boolean, boolean, boolean)} instead. */ + @Deprecated(forRemoval = true, since = "7") // TODO Vespa 8 remove public FieldConsumer(JsonGenerator generator, boolean debugRendering, boolean tensorShortForm, boolean jsonMaps) { this.generator = generator; this.debugRendering = debugRendering; @@ -578,14 +602,14 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> { /** Call before rendering a field to the generator */ void ensureFieldsField() throws IOException { if (hasFieldsField.get()) return; - generator.writeObjectFieldStart(FIELDS); + generator().writeObjectFieldStart(FIELDS); hasFieldsField.set(true); } /** Call after all fields in a hit to close the "fields" field of the JSON object */ void endHitFields() throws IOException { if ( ! hasFieldsField.get()) return; - generator.writeEndObject(); + generator().writeEndObject(); this.hasFieldsField = null; } @@ -594,7 +618,7 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> { try { if (shouldRender(name, value)) { ensureFieldsField(); - generator.writeFieldName(name); + generator().writeFieldName(name); renderFieldContents(value); } } @@ -608,8 +632,8 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> { try { if (shouldRenderUtf8Value(name, length)) { ensureFieldsField(); - generator.writeFieldName(name); - generator.writeUTF8String(utf8Data, offset, length); + generator().writeFieldName(name); + generator().writeUTF8String(utf8Data, offset, length); } } catch (IOException e) { @@ -700,7 +724,7 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> { private void renderInspectorDirect(Inspector data) throws IOException { StringBuilder intermediate = new StringBuilder(); JsonRender.render(data, intermediate, true); - generator.writeRawValue(intermediate.toString()); + generator().writeRawValue(intermediate.toString()); } protected void renderFieldContents(Object field) throws IOException { @@ -714,68 +738,75 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> { @Override public void accept(Object field) throws IOException { if (field == null) { - generator.writeNull(); + generator().writeNull(); } else if (field instanceof Boolean) { - generator.writeBoolean((Boolean)field); + generator().writeBoolean((Boolean)field); } else if (field instanceof Number) { renderNumberField((Number) field); } else if (field instanceof TreeNode) { - generator.writeTree((TreeNode) field); + generator().writeTree((TreeNode) field); } else if (field instanceof Tensor) { renderTensor(Optional.of((Tensor)field)); } else if (field instanceof FeatureData) { - generator.writeRawValue(((FeatureData)field).toJson(tensorShortForm)); + generator().writeRawValue(((FeatureData)field).toJson(tensorShortForm)); } else if (field instanceof Inspectable) { renderInspectorDirect(((Inspectable)field).inspect()); } else if (field instanceof JsonProducer) { - generator.writeRawValue(((JsonProducer) field).toJson()); + generator().writeRawValue(((JsonProducer) field).toJson()); } else if (field instanceof StringFieldValue) { - generator.writeString(((StringFieldValue)field).getString()); + generator().writeString(((StringFieldValue)field).getString()); } else if (field instanceof TensorFieldValue) { renderTensor(((TensorFieldValue)field).getTensor()); } else if (field instanceof FieldValue) { // the null below is the field which has already been written ((FieldValue) field).serialize(null, new JsonWriter(generator)); } else { - generator.writeString(field.toString()); + generator().writeString(field.toString()); } } private void renderNumberField(Number field) throws IOException { if (field instanceof Integer) { - generator.writeNumber(field.intValue()); + generator().writeNumber(field.intValue()); } else if (field instanceof Float) { - generator.writeNumber(field.floatValue()); + generator().writeNumber(field.floatValue()); } else if (field instanceof Double) { - generator.writeNumber(field.doubleValue()); + generator().writeNumber(field.doubleValue()); } else if (field instanceof Long) { - generator.writeNumber(field.longValue()); + generator().writeNumber(field.longValue()); } else if (field instanceof Byte || field instanceof Short) { - generator.writeNumber(field.intValue()); + generator().writeNumber(field.intValue()); } else if (field instanceof BigInteger) { - generator.writeNumber((BigInteger) field); + generator().writeNumber((BigInteger) field); } else if (field instanceof BigDecimal) { - generator.writeNumber((BigDecimal) field); + generator().writeNumber((BigDecimal) field); } else { - generator.writeNumber(field.doubleValue()); + generator().writeNumber(field.doubleValue()); } } private void renderTensor(Optional<Tensor> tensor) throws IOException { if (tensor.isEmpty()) { - generator.writeStartObject(); - generator.writeArrayFieldStart("cells"); - generator.writeEndArray(); - generator.writeEndObject(); + generator().writeStartObject(); + generator().writeArrayFieldStart("cells"); + generator().writeEndArray(); + generator().writeEndObject(); return; } if (tensorShortForm) { - generator.writeRawValue(new String(JsonFormat.encodeShortForm(tensor.get()), StandardCharsets.UTF_8)); + generator().writeRawValue(new String(JsonFormat.encodeShortForm(tensor.get()), StandardCharsets.UTF_8)); } else { - generator.writeRawValue(new String(JsonFormat.encode(tensor.get()), StandardCharsets.UTF_8)); + generator().writeRawValue(new String(JsonFormat.encode(tensor.get()), StandardCharsets.UTF_8)); } } + private JsonGenerator generator() { + if (generator == null) + throw new UnsupportedOperationException("Generator required but not assigned. " + + "All accept() methods must be overridden when sub-classing FieldConsumer"); + return generator; + } + } } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/MultipartParserTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/MultipartParserTest.java index 5bf22ede19d..2c81b1a7fd8 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/MultipartParserTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/MultipartParserTest.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.restapi.application; -import com.google.inject.Key; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.jdisc.Container; import com.yahoo.jdisc.Request; @@ -72,9 +71,6 @@ public class MultipartParserTest { public RequestHandler resolveHandler(Request request) { return null; } @Override - public <T> T getInstance(Key<T> key) { return null; } - - @Override public <T> T getInstance(Class<T> aClass) { return null; } @Override diff --git a/document/src/vespa/document/fieldvalue/document.cpp b/document/src/vespa/document/fieldvalue/document.cpp index 15198013c5f..36526f09dd6 100644 --- a/document/src/vespa/document/fieldvalue/document.cpp +++ b/document/src/vespa/document/fieldvalue/document.cpp @@ -10,7 +10,6 @@ #include <vespa/vespalib/objects/nbostream.h> #include <vespa/document/util/serializableexceptions.h> #include <vespa/document/fieldset/fieldsets.h> -#include <vespa/document/util/bytebuffer.h> #include <vespa/vespalib/data/databuffer.h> #include <vespa/vespalib/util/xmlstream.h> #include <vespa/vespalib/stllike/hash_map.hpp> diff --git a/eval/src/vespa/eval/eval/array_array_map.h b/eval/src/vespa/eval/eval/array_array_map.h index 3c070210680..e3601644f3e 100644 --- a/eval/src/vespa/eval/eval/array_array_map.h +++ b/eval/src/vespa/eval/eval/array_array_map.h @@ -4,6 +4,7 @@ #include <vespa/vespalib/util/arrayref.h> #include <vespa/vespalib/stllike/hash_set.h> +#include <vespa/vespalib/stllike/allocator.h> #include <vespa/vespalib/stllike/hash_set.hpp> #include <vector> #include <cassert> @@ -27,8 +28,8 @@ class ArrayArrayMap private: size_t _keys_per_entry; size_t _values_per_entry; - std::vector<K> _keys; - std::vector<V> _values; + std::vector<K, vespalib::allocator_large<K>> _keys; + std::vector<V, vespalib::allocator_large<V>> _values; public: size_t keys_per_entry() const { return _keys_per_entry; } @@ -123,14 +124,9 @@ private: } public: - ArrayArrayMap(size_t keys_per_entry_in, size_t values_per_entry_in, size_t expected_entries) - : _keys_per_entry(keys_per_entry_in), _values_per_entry(values_per_entry_in), _keys(), _values(), - _map(expected_entries * 2, Hash(), Equal(*this)), _hasher() - { - _keys.reserve(_keys_per_entry * expected_entries); - _values.reserve(_values_per_entry * expected_entries); - static_assert(!std::is_pointer_v<K>, "keys cannot be pointers due to auto-deref of alt keys"); - } + ArrayArrayMap(size_t keys_per_entry_in, size_t values_per_entry_in, size_t expected_entries); + ArrayArrayMap(const ArrayArrayMap &) = delete; + ArrayArrayMap & operator = (const ArrayArrayMap &) = delete; ~ArrayArrayMap(); size_t size() const { return _map.size(); } @@ -168,6 +164,16 @@ public: }; template <typename K, typename V, typename H, typename EQ> +ArrayArrayMap<K,V,H,EQ>::ArrayArrayMap(size_t keys_per_entry_in, size_t values_per_entry_in, size_t expected_entries) + : _keys_per_entry(keys_per_entry_in), _values_per_entry(values_per_entry_in), _keys(), _values(), + _map(expected_entries * 2, Hash(), Equal(*this)), _hasher() +{ + _keys.reserve(_keys_per_entry * expected_entries); + _values.reserve(_values_per_entry * expected_entries); + static_assert(!std::is_pointer_v<K>, "keys cannot be pointers due to auto-deref of alt keys"); +} + +template <typename K, typename V, typename H, typename EQ> ArrayArrayMap<K,V,H,EQ>::~ArrayArrayMap() = default; } diff --git a/eval/src/vespa/eval/eval/fast_addr_map.h b/eval/src/vespa/eval/eval/fast_addr_map.h index a3b73afba6d..b9bc39ad619 100644 --- a/eval/src/vespa/eval/eval/fast_addr_map.h +++ b/eval/src/vespa/eval/eval/fast_addr_map.h @@ -7,7 +7,6 @@ #include <vespa/vespalib/util/string_id.h> #include <vespa/vespalib/stllike/identity.h> #include <vespa/vespalib/stllike/hashtable.h> -#include <vector> namespace vespalib::eval { @@ -62,8 +61,8 @@ public: // view able to convert tags into sparse addresses struct LabelView { size_t addr_size; - const std::vector<string_id> &labels; - LabelView(size_t num_mapped_dims, const std::vector<string_id> &labels_in) + const StringIdVector &labels; + LabelView(size_t num_mapped_dims, const StringIdVector &labels_in) : addr_size(num_mapped_dims), labels(labels_in) {} ConstArrayRef<string_id> get_addr(size_t idx) const { return {&labels[idx * addr_size], addr_size}; @@ -105,7 +104,7 @@ private: HashType _map; public: - FastAddrMap(size_t num_mapped_dims, const std::vector<string_id> &labels_in, size_t expected_subspaces) + FastAddrMap(size_t num_mapped_dims, const StringIdVector &labels_in, size_t expected_subspaces) : _labels(num_mapped_dims, labels_in), _map(expected_subspaces * 2, Hash(), Equal(_labels)) {} ~FastAddrMap(); @@ -117,7 +116,7 @@ public: ConstArrayRef<string_id> get_addr(size_t idx) const { return _labels.get_addr(idx); } size_t size() const { return _map.size(); } constexpr size_t addr_size() const { return _labels.addr_size; } - const std::vector<string_id> &labels() const { return _labels.labels; } + const StringIdVector &labels() const { return _labels.labels; } template <typename T> size_t lookup(ConstArrayRef<T> addr, uint32_t hash) const { // assert(addr_size() == addr.size()); diff --git a/eval/src/vespa/eval/eval/fast_value.hpp b/eval/src/vespa/eval/eval/fast_value.hpp index 185529b2f51..a0a96bc4497 100644 --- a/eval/src/vespa/eval/eval/fast_value.hpp +++ b/eval/src/vespa/eval/eval/fast_value.hpp @@ -139,7 +139,7 @@ struct FastIterateView : public Value::Index::View { // operations by calling inline functions directly. struct FastValueIndex final : Value::Index { FastAddrMap map; - FastValueIndex(size_t num_mapped_dims_in, const std::vector<string_id> &labels, size_t expected_subspaces_in) + FastValueIndex(size_t num_mapped_dims_in, const StringIdVector &labels, size_t expected_subspaces_in) : map(num_mapped_dims_in, labels, expected_subspaces_in) {} size_t size() const override { return map.size(); } std::unique_ptr<View> create_view(ConstArrayRef<size_t> dims) const override; @@ -168,29 +168,19 @@ struct FastCells { static constexpr size_t elem_size = sizeof(T); size_t capacity; size_t size; - void *memory; - FastCells(size_t initial_capacity) - : capacity(roundUp2inN(initial_capacity)), - size(0), - memory(malloc(elem_size * capacity)) - { - static_assert(std::is_trivially_copyable_v<T>); - static_assert(can_skip_destruction<T>::value); - } - ~FastCells() { - free(memory); - } + mutable alloc::Alloc memory; + FastCells(size_t initial_capacity); + FastCells(const FastCells &) = delete; + FastCells & operator = (const FastCells &) = delete; + ~FastCells(); void ensure_free(size_t need) { if (__builtin_expect((size + need) > capacity, false)) { - capacity = roundUp2inN(size + need); - void *new_memory = malloc(elem_size * capacity); - memcpy(new_memory, memory, elem_size * size); - free(memory); - memory = new_memory; + reallocate(need); } } + void reallocate(size_t need); constexpr T *get(size_t offset) const { - return reinterpret_cast<T*>(memory) + offset; + return reinterpret_cast<T*>(memory.get()) + offset; } void push_back_fast(T value) { *get(size++) = value; @@ -209,17 +199,38 @@ struct FastCells { } }; +template <typename T> +FastCells<T>::FastCells(size_t initial_capacity) + : capacity(roundUp2inN(initial_capacity)), + size(0), + memory(alloc::Alloc::alloc(elem_size * capacity)) +{ + static_assert(std::is_trivially_copyable_v<T>); + static_assert(can_skip_destruction<T>::value); +} + +template <typename T> +void +FastCells<T>::reallocate(size_t need) { + capacity = roundUp2inN(size + need); + alloc::Alloc new_memory = alloc::Alloc::alloc(elem_size * capacity); + memcpy(new_memory.get(), memory.get(), elem_size * size); + memory = std::move(new_memory); +} + +template <typename T> +FastCells<T>::~FastCells() = default; + //----------------------------------------------------------------------------- template <typename T, bool transient> struct FastValue final : Value, ValueBuilder<T> { - using Handles = typename std::conditional<transient, - std::vector<string_id>, + StringIdVector, SharedStringRepo::Handles>::type; - static const std::vector<string_id> &get_view(const std::vector<string_id> &handles) { return handles; } - static const std::vector<string_id> &get_view(const SharedStringRepo::Handles &handles) { return handles.view(); } + static const StringIdVector &get_view(const StringIdVector &handles) { return handles; } + static const StringIdVector &get_view(const SharedStringRepo::Handles &handles) { return handles.view(); } ValueType my_type; size_t my_subspace_size; @@ -227,14 +238,7 @@ struct FastValue final : Value, ValueBuilder<T> { FastValueIndex my_index; FastCells<T> my_cells; - FastValue(const ValueType &type_in, size_t num_mapped_dims_in, size_t subspace_size_in, size_t expected_subspaces_in) - : my_type(type_in), my_subspace_size(subspace_size_in), - my_handles(), - my_index(num_mapped_dims_in, get_view(my_handles), expected_subspaces_in), - my_cells(subspace_size_in * expected_subspaces_in) - { - my_handles.reserve(expected_subspaces_in * num_mapped_dims_in); - } + FastValue(const ValueType &type_in, size_t num_mapped_dims_in, size_t subspace_size_in, size_t expected_subspaces_in); ~FastValue() override; const ValueType &type() const override { return my_type; } const Value::Index &index() const override { return my_index; } @@ -245,7 +249,7 @@ struct FastValue final : Value, ValueBuilder<T> { // not called abort(); } else { - return TypedCells(my_cells.memory, get_cell_type<T>(), my_cells.size); + return TypedCells(my_cells.memory.get(), get_cell_type<T>(), my_cells.size); } } void add_mapping(ConstArrayRef<vespalib::stringref> addr) { @@ -310,7 +314,20 @@ struct FastValue final : Value, ValueBuilder<T> { return usage; } }; -template <typename T,bool transient> FastValue<T,transient>::~FastValue() = default; + +template <typename T,bool transient> +FastValue<T,transient>::FastValue(const ValueType &type_in, size_t num_mapped_dims_in, + size_t subspace_size_in, size_t expected_subspaces_in) + : my_type(type_in), my_subspace_size(subspace_size_in), + my_handles(), + my_index(num_mapped_dims_in, get_view(my_handles), expected_subspaces_in), + my_cells(subspace_size_in * expected_subspaces_in) +{ + my_handles.reserve(expected_subspaces_in * num_mapped_dims_in); +} + +template <typename T,bool transient> +FastValue<T,transient>::~FastValue() = default; //----------------------------------------------------------------------------- @@ -328,7 +345,7 @@ struct FastDenseValue final : Value, ValueBuilder<T> { ~FastDenseValue() override; const ValueType &type() const override { return my_type; } const Value::Index &index() const override { return TrivialIndex::get(); } - TypedCells cells() const override { return TypedCells(my_cells.memory, get_cell_type<T>(), my_cells.size); } + TypedCells cells() const override { return TypedCells(my_cells.memory.get(), get_cell_type<T>(), my_cells.size); } ArrayRef<T> add_subspace(ConstArrayRef<vespalib::stringref>) override { return ArrayRef<T>(my_cells.get(0), my_cells.size); } diff --git a/eval/src/vespa/eval/eval/memory_usage_stuff.h b/eval/src/vespa/eval/eval/memory_usage_stuff.h index 79a4cfb0eda..10f5459b0e7 100644 --- a/eval/src/vespa/eval/eval/memory_usage_stuff.h +++ b/eval/src/vespa/eval/eval/memory_usage_stuff.h @@ -10,8 +10,9 @@ namespace vespalib::eval { template <typename T> MemoryUsage self_memory_usage() { return MemoryUsage(sizeof(T), sizeof(T), 0, 0); } -template <typename T> -MemoryUsage vector_extra_memory_usage(const std::vector<T> &vec) { +template <typename V> +MemoryUsage vector_extra_memory_usage(const V &vec) { + using T = typename V::value_type; MemoryUsage usage; usage.incAllocatedBytes(sizeof(T) * vec.capacity()); usage.incUsedBytes(sizeof(T) * vec.size()); diff --git a/eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp b/eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp index 9ddbf41f909..d6a7f54a78e 100644 --- a/eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp +++ b/eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp @@ -13,8 +13,7 @@ #include <vespa/log/log.h> LOG_SETUP(".vespalib.eval.value_cache.constant_tensor_loader"); -namespace vespalib { -namespace eval { +namespace vespalib::eval { using Inspector = slime::Inspector; using ObjectTraverser = slime::ObjectTraverser; @@ -110,5 +109,4 @@ ConstantTensorLoader::create(const vespalib::string &path, const vespalib::strin } } -} // namespace vespalib::eval -} // namespace vespalib +} diff --git a/eval/src/vespa/eval/streamed/streamed_value.h b/eval/src/vespa/eval/streamed/streamed_value.h index ef44eeafce3..a1927e793b2 100644 --- a/eval/src/vespa/eval/streamed/streamed_value.h +++ b/eval/src/vespa/eval/streamed/streamed_value.h @@ -2,10 +2,10 @@ #pragma once +#include "streamed_value_index.h" #include <vespa/eval/eval/value_type.h> #include <vespa/eval/eval/value.h> #include <vespa/vespalib/util/shared_string_repo.h> -#include "streamed_value_index.h" #include <cassert> namespace vespalib::eval { diff --git a/eval/src/vespa/eval/streamed/streamed_value_index.h b/eval/src/vespa/eval/streamed/streamed_value_index.h index 724874af577..d3f0f2781c4 100644 --- a/eval/src/vespa/eval/streamed/streamed_value_index.h +++ b/eval/src/vespa/eval/streamed/streamed_value_index.h @@ -16,10 +16,10 @@ class StreamedValueIndex : public Value::Index private: uint32_t _num_mapped_dims; uint32_t _num_subspaces; - const std::vector<string_id> &_labels_ref; + const StringIdVector &_labels_ref; public: - StreamedValueIndex(uint32_t num_mapped_dims, uint32_t num_subspaces, const std::vector<string_id> &labels_ref) + StreamedValueIndex(uint32_t num_mapped_dims, uint32_t num_subspaces, const StringIdVector &labels_ref) : _num_mapped_dims(num_mapped_dims), _num_subspaces(num_subspaces), _labels_ref(labels_ref) diff --git a/eval/src/vespa/eval/streamed/streamed_value_utils.h b/eval/src/vespa/eval/streamed/streamed_value_utils.h index efcaf4c6e7a..b808ad3c573 100644 --- a/eval/src/vespa/eval/streamed/streamed_value_utils.h +++ b/eval/src/vespa/eval/streamed/streamed_value_utils.h @@ -13,9 +13,9 @@ namespace vespalib::eval { * Reading more labels than available will trigger an assert. **/ struct LabelStream { - const std::vector<string_id> &source; + const StringIdVector &source; size_t pos; - LabelStream(const std::vector<string_id> &data) : source(data), pos(0) {} + LabelStream(const StringIdVector &data) : source(data), pos(0) {} string_id next_label() { assert(pos < source.size()); return source[pos++]; @@ -42,7 +42,7 @@ private: size_t _num_subspaces; LabelStream _labels; size_t _subspace_index; - std::vector<string_id> _current_address; + StringIdVector _current_address; public: LabelBlock next_block() { if (_subspace_index < _num_subspaces) { @@ -61,7 +61,7 @@ public: } LabelBlockStream(uint32_t num_subspaces, - const std::vector<string_id> &labels, + const StringIdVector &labels, uint32_t num_mapped_dims) : _num_subspaces(num_subspaces), _labels(labels), diff --git a/eval/src/vespa/eval/streamed/streamed_value_view.h b/eval/src/vespa/eval/streamed/streamed_value_view.h index 908176d5cac..53b9e733de5 100644 --- a/eval/src/vespa/eval/streamed/streamed_value_view.h +++ b/eval/src/vespa/eval/streamed/streamed_value_view.h @@ -24,7 +24,7 @@ private: public: StreamedValueView(const ValueType &type, size_t num_mapped_dimensions, TypedCells cells, size_t num_subspaces, - const std::vector<string_id> &labels) + const StringIdVector &labels) : _type(type), _cells_ref(cells), _my_index(num_mapped_dimensions, num_subspaces, labels) diff --git a/jdisc_core/abi-spec.json b/jdisc_core/abi-spec.json index d1b676b330f..06e76f88898 100644 --- a/jdisc_core/abi-spec.json +++ b/jdisc_core/abi-spec.json @@ -32,7 +32,7 @@ ], "methods": [ "public abstract com.yahoo.jdisc.handler.RequestHandler resolveHandler(com.yahoo.jdisc.Request)", - "public abstract java.lang.Object getInstance(com.google.inject.Key)", + "public java.lang.Object getInstance(com.google.inject.Key)", "public abstract java.lang.Object getInstance(java.lang.Class)" ], "fields": [] diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/Container.java b/jdisc_core/src/main/java/com/yahoo/jdisc/Container.java index f3ed16c65e7..e96f7f08fe8 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/Container.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/Container.java @@ -49,8 +49,10 @@ public interface Container extends SharedResource, Timer { * @return The appropriate instance of the given class. * @throws ConfigurationException If this injector cannot find or create the provider. * @throws ProvisionException If there was a runtime failure while providing an instance. + * @deprecated Use {@link #getInstance(Class)} instead. */ - <T> T getInstance(Key<T> key); + @Deprecated(forRemoval = true, since = "7") // TODO Vespa 8 remove + default <T> T getInstance(Key<T> key) { throw new UnsupportedOperationException(); } /** * Returns the appropriate instance for the given injection type. When feasible, avoid using this method in diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ContainerSnapshot.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ContainerSnapshot.java index f3641f2475b..808c8e89b1b 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ContainerSnapshot.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ContainerSnapshot.java @@ -37,7 +37,10 @@ class ContainerSnapshot extends AbstractResource implements Container { this.containerReference = container.refer(context); } + /** @deprecated Use {@link #getInstance(Class)} instead. */ @Override + @Deprecated(forRemoval = true, since = "7") // TODO Vespa 8 remove + @SuppressWarnings("removal") public <T> T getInstance(Key<T> key) { return container.guiceInjector().getInstance(key); } diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java index 987a24fe332..75154dd588e 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java @@ -3,7 +3,6 @@ package com.yahoo.jdisc; import com.google.inject.AbstractModule; import com.google.inject.Guice; -import com.google.inject.Key; import com.yahoo.jdisc.application.BindingMatch; import com.yahoo.jdisc.application.UriPattern; import com.yahoo.jdisc.handler.CompletionHandler; @@ -307,11 +306,6 @@ public class RequestTestCase { } @Override - public <T> T getInstance(Key<T> key) { - return Guice.createInjector().getInstance(key); - } - - @Override public <T> T getInstance(Class<T> type) { return Guice.createInjector().getInstance(type); } diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/core/ContainerSnapshotTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/core/ContainerSnapshotTestCase.java index 3e6987c8c6f..dc1f3c7609e 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/core/ContainerSnapshotTestCase.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/core/ContainerSnapshotTestCase.java @@ -2,8 +2,6 @@ package com.yahoo.jdisc.core; import com.google.inject.AbstractModule; -import com.google.inject.Key; -import com.google.inject.name.Names; import com.yahoo.jdisc.AbstractResource; import com.yahoo.jdisc.Request; import com.yahoo.jdisc.application.BindingMatch; @@ -142,13 +140,11 @@ public class ContainerSnapshotTestCase { @Override protected void configure() { bind(Object.class).toInstance(obj); - bind(String.class).annotatedWith(Names.named("foo")).toInstance("foo"); } }); ActiveContainer active = new ActiveContainer(driver.newContainerBuilder()); ContainerSnapshot snapshot = new ContainerSnapshot(active, null, null, null); assertSame(obj, snapshot.getInstance(Object.class)); - assertEquals("foo", snapshot.getInstance(Key.get(String.class, Names.named("foo")))); snapshot.release(); assertTrue(driver.close()); } diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/test/NonWorkingRequestTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/test/NonWorkingRequestTestCase.java index ac55334308c..b0d67102a12 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/test/NonWorkingRequestTestCase.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/test/NonWorkingRequestTestCase.java @@ -2,13 +2,11 @@ package com.yahoo.jdisc.test; import com.google.inject.AbstractModule; -import com.google.inject.Key; -import com.google.inject.name.Names; import com.yahoo.jdisc.Request; import org.junit.Test; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; /** @@ -23,13 +21,14 @@ public class NonWorkingRequestTestCase { @Test public void requireThatGuiceModulesAreInjected() { + Object obj = new Object(); Request request = NonWorkingRequest.newInstance("scheme://host/path", new AbstractModule() { @Override protected void configure() { - bind(String.class).annotatedWith(Names.named("foo")).toInstance("bar"); + bind(Object.class).toInstance(obj); } }); - assertEquals("bar", request.container().getInstance(Key.get(String.class, Names.named("foo")))); + assertSame(obj, request.container().getInstance(Object.class)); } } diff --git a/searchcommon/src/vespa/searchcommon/common/schema.cpp b/searchcommon/src/vespa/searchcommon/common/schema.cpp index 0127f727069..c6a2a4532a3 100644 --- a/searchcommon/src/vespa/searchcommon/common/schema.cpp +++ b/searchcommon/src/vespa/searchcommon/common/schema.cpp @@ -48,7 +48,7 @@ writeFieldSets(vespalib::asciistream &os, struct FieldName { vespalib::string name; - FieldName(const std::vector<vespalib::string> & lines) + FieldName(const config::StringVector & lines) : name(ConfigParser::parse<vespalib::string>("name", lines)) { } @@ -64,8 +64,7 @@ getFieldId(vespalib::stringref name, const T &map) } // namespace -namespace search { -namespace index { +namespace search::index { const uint32_t Schema::UNKNOWN_FIELD_ID(std::numeric_limits<uint32_t>::max()); @@ -88,7 +87,7 @@ Schema::Field::Field(vespalib::stringref n, DataType dt, CollectionType ct, vesp } // XXX: Resource leak if exception is thrown. -Schema::Field::Field(const std::vector<vespalib::string> & lines) +Schema::Field::Field(const config::StringVector & lines) : _name(ConfigParser::parse<vespalib::string>("name", lines)), _dataType(schema::dataTypeFromName(ConfigParser::parse<vespalib::string>("datatype", lines))), _collectionType(schema::collectionTypeFromName(ConfigParser::parse<vespalib::string>("collectiontype", lines))) @@ -140,7 +139,7 @@ Schema::IndexField::IndexField(vespalib::stringref name, DataType dt, { } -Schema::IndexField::IndexField(const std::vector<vespalib::string> &lines) +Schema::IndexField::IndexField(const config::StringVector &lines) : Field(lines), _avgElemLen(ConfigParser::parse<int32_t>("averageelementlen", lines, 512)), _interleaved_features(ConfigParser::parse<bool>("interleavedfeatures", lines, false)) @@ -181,11 +180,11 @@ Schema::IndexField::operator!=(const IndexField &rhs) const _interleaved_features != rhs._interleaved_features; } -Schema::FieldSet::FieldSet(const std::vector<vespalib::string> & lines) : +Schema::FieldSet::FieldSet(const config::StringVector & lines) : _name(ConfigParser::parse<vespalib::string>("name", lines)), _fields() { - std::vector<FieldName> fn = ConfigParser::parseArray<FieldName>("field", lines); + std::vector<FieldName> fn = ConfigParser::parseArray<std::vector<FieldName>>("field", lines); for (size_t i = 0; i < fn.size(); ++i) { _fields.push_back(fn[i].name); } @@ -238,16 +237,16 @@ Schema::loadFromFile(const vespalib::string & fileName) LOG(warning, "Could not open input file '%s' as part of loadFromFile()", fileName.c_str()); return false; } - std::vector<vespalib::string> lines; + config::StringVector lines; std::string tmpLine; while (file) { getline(file, tmpLine); lines.push_back(tmpLine); } - _indexFields = ConfigParser::parseArray<IndexField>("indexfield", lines); - _attributeFields = ConfigParser::parseArray<AttributeField>("attributefield", lines); - _summaryFields = ConfigParser::parseArray<SummaryField>("summaryfield", lines); - _fieldSets = ConfigParser::parseArray<FieldSet>("fieldset", lines); + _indexFields = ConfigParser::parseArray<std::vector<IndexField>>("indexfield", lines); + _attributeFields = ConfigParser::parseArray<std::vector<AttributeField>>("attributefield", lines); + _summaryFields = ConfigParser::parseArray<std::vector<SummaryField>>("summaryfield", lines); + _fieldSets = ConfigParser::parseArray<std::vector<FieldSet>>("fieldset", lines); _importedAttributeFields.clear(); // NOTE: these are not persisted to disk _indexIds.clear(); for (size_t i(0), m(_indexFields.size()); i < m; i++) { @@ -579,5 +578,4 @@ Schema::empty() const _importedAttributeFields.empty(); } -} // namespace search::index -} // namespace search +} diff --git a/searchcommon/src/vespa/searchcommon/common/schema.h b/searchcommon/src/vespa/searchcommon/common/schema.h index f86bb3068c5..3a9bcbdd904 100644 --- a/searchcommon/src/vespa/searchcommon/common/schema.h +++ b/searchcommon/src/vespa/searchcommon/common/schema.h @@ -3,10 +3,9 @@ #pragma once #include "datatype.h" -#include <vespa/vespalib/stllike/string.h> +#include <vespa/config/common/types.h> #include <vespa/vespalib/stllike/hash_map.h> #include <vespa/vespalib/util/ptrholder.h> -#include <vector> namespace vespalib { class asciistream; } namespace search::index { @@ -20,7 +19,6 @@ class Schema public: using UP = std::unique_ptr<Schema>; using SP = std::shared_ptr<Schema>; - using PH = vespalib::PtrHolder<Schema>; using DataType = schema::DataType; using CollectionType = schema::CollectionType; @@ -45,7 +43,7 @@ public: /** * Create this field based on the given config lines. **/ - Field(const std::vector<vespalib::string> & lines); + Field(const config::StringVector & lines); Field(const Field &) noexcept; Field & operator = (const Field &) noexcept; Field(Field &&) noexcept; @@ -92,7 +90,7 @@ public: /** * Create this index field based on the given config lines. **/ - IndexField(const std::vector<vespalib::string> &lines); + IndexField(const config::StringVector &lines); IndexField &setAvgElemLen(uint32_t avgElemLen) { _avgElemLen = avgElemLen; return *this; } IndexField &set_interleaved_features(bool value) { @@ -133,7 +131,7 @@ public: /** * Create this field collection based on the given config lines. **/ - FieldSet(const std::vector<vespalib::string> & lines); + FieldSet(const config::StringVector & lines); ~FieldSet(); @@ -143,8 +141,9 @@ public: } const vespalib::string &getName() const { return _name; } - const std::vector<vespalib::string> &getFields() const - { return _fields; } + const std::vector<vespalib::string> &getFields() const { + return _fields; + } bool operator==(const FieldSet &rhs) const; bool operator!=(const FieldSet &rhs) const; diff --git a/searchlib/src/vespa/searchlib/tensor/streamed_value_store.cpp b/searchlib/src/vespa/searchlib/tensor/streamed_value_store.cpp index 0901e643afa..2e6d771a870 100644 --- a/searchlib/src/vespa/searchlib/tensor/streamed_value_store.cpp +++ b/searchlib/src/vespa/searchlib/tensor/streamed_value_store.cpp @@ -11,7 +11,6 @@ #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/size_literals.h> #include <vespa/vespalib/util/typify.h> -#include <vespa/vespalib/util/stringfmt.h> #include <vespa/log/log.h> LOG_SETUP(".searchlib.tensor.streamed_value_store"); @@ -22,6 +21,7 @@ using namespace vespalib::eval; using vespalib::ConstArrayRef; using vespalib::MemoryUsage; using vespalib::string_id; +using vespalib::StringIdVector; namespace search::tensor { @@ -61,12 +61,12 @@ struct MyFastValueView final : Value { const ValueType &my_type; FastValueIndex my_index; TypedCells my_cells; - MyFastValueView(const ValueType &type_ref, const std::vector<string_id> &handle_view, TypedCells cells, size_t num_mapped, size_t num_spaces) + MyFastValueView(const ValueType &type_ref, const StringIdVector &handle_view, TypedCells cells, size_t num_mapped, size_t num_spaces) : my_type(type_ref), my_index(num_mapped, handle_view, num_spaces), my_cells(cells) { - const std::vector<string_id> &labels = handle_view; + const StringIdVector &labels = handle_view; for (size_t i = 0; i < num_spaces; ++i) { ConstArrayRef<string_id> addr(&labels[i * num_mapped], num_mapped); my_index.map.add_mapping(FastAddrMap::hash_labels(addr)); diff --git a/storage/src/vespa/storage/distributor/distributor_component.h b/storage/src/vespa/storage/distributor/distributor_component.h index 34fd08140e0..282f06981d3 100644 --- a/storage/src/vespa/storage/distributor/distributor_component.h +++ b/storage/src/vespa/storage/distributor/distributor_component.h @@ -23,7 +23,7 @@ class DistributorComponent : public storage::DistributorComponent, public DistributorOperationContext { private: DistributorInterface& _distributor; - BucketSpaceStateMap _bucket_space_states; + BucketSpaceStateMap _bucket_space_states; public: diff --git a/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp b/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp index 81c8271f755..5b267c3b9e9 100644 --- a/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp +++ b/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp @@ -101,8 +101,8 @@ std::unique_ptr<Handles> copy_strong_handles(const Handles &handles) { return result; } -std::unique_ptr<std::vector<string_id>> make_weak_handles(const Handles &handles) { - return std::make_unique<std::vector<string_id>>(handles.view()); +std::unique_ptr<StringIdVector> make_weak_handles(const Handles &handles) { + return std::make_unique<StringIdVector>(handles.view()); } //----------------------------------------------------------------------------- @@ -202,7 +202,7 @@ struct Fixture { std::vector<vespalib::string> get_direct_result; std::unique_ptr<Handles> strong; std::unique_ptr<Handles> strong_copy; - std::unique_ptr<std::vector<string_id>> weak; + std::unique_ptr<StringIdVector> weak; auto copy_strings_task = [&](){ copy_strings_result = copy_strings(work); }; auto copy_and_hash_task = [&](){ copy_and_hash_result = copy_and_hash(work); }; auto local_enum_task = [&](){ local_enum_result = local_enum(work); }; diff --git a/vespalib/src/tests/stllike/asciistream_test.cpp b/vespalib/src/tests/stllike/asciistream_test.cpp index be0bc1cb694..3042595e18c 100644 --- a/vespalib/src/tests/stllike/asciistream_test.cpp +++ b/vespalib/src/tests/stllike/asciistream_test.cpp @@ -409,27 +409,14 @@ AsciistreamTest::testWriteThenRead() void AsciistreamTest::testGetLine() { - asciistream is(""); - EXPECT_TRUE(is.getlines().empty()); - is = asciistream("line 1"); - std::vector<string> v = is.getlines(); - EXPECT_EQUAL(1u, v.size()); - EXPECT_EQUAL("line 1", v[0]); - is = asciistream("line 1\nline 2"); - v = is.getlines(); - EXPECT_EQUAL(2u, v.size()); - EXPECT_EQUAL("line 1", v[0]); - EXPECT_EQUAL("line 2", v[1]); - is = asciistream("line 1\nline 2\n\n"); - v = is.getlines(); - EXPECT_EQUAL(3u, v.size()); - EXPECT_EQUAL("line 1", v[0]); - EXPECT_EQUAL("line 2", v[1]); - EXPECT_EQUAL("", v[2]); - is = asciistream("line 1"); + asciistream is = asciistream("line 1\nline 2\nline 3"); string s; getline(is, s); EXPECT_EQUAL("line 1", s); + getline(is, s); + EXPECT_EQUAL("line 2", s); + getline(is, s); + EXPECT_EQUAL("line 3", s); } #define VERIFY_DOUBLE_SERIALIZATION(value, expected, format, precision) { \ diff --git a/vespalib/src/vespa/vespalib/data/slime/array_value.h b/vespalib/src/vespa/vespalib/data/slime/array_value.h index b1b257e8476..216d116498c 100644 --- a/vespalib/src/vespa/vespalib/data/slime/array_value.h +++ b/vespalib/src/vespa/vespalib/data/slime/array_value.h @@ -5,6 +5,7 @@ #include "value.h" #include "nix_value.h" #include "value_factory.h" +#include <vespa/vespalib/stllike/allocator.h> #include <vector> namespace vespalib::slime { @@ -18,7 +19,7 @@ class ArrayValue final : public Value private: SymbolTable &_symbolTable; Stash &_stash; - std::vector<Value*> _values; + std::vector<Value*, vespalib::allocator_large<Value*>> _values; protected: Cursor &addLeaf(const ValueFactory &input) override { diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp index 3602cbe6151..eb127c7051a 100644 --- a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp +++ b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp @@ -8,10 +8,9 @@ #include <vespa/vespalib/locale/c.h> #include <vespa/fastos/file.h> #include <limits> -#include <stdexcept> #include <cassert> -#include <cmath> #include <charconv> +#include <vector> #include <vespa/log/log.h> LOG_SETUP(".vespalib.stllike.asciistream"); @@ -603,16 +602,6 @@ asciistream::write(const void * buf, size_t len) _rbuf = _wbuf; } -std::vector<string> -asciistream::getlines(char delim) -{ - std::vector<string> lines; - while (!eof()) { - lines.push_back(getline(delim)); - } - return lines; -} - string asciistream::getline(char delim) { diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.h b/vespalib/src/vespa/vespalib/stllike/asciistream.h index 6a4b4378634..b333be6cec2 100644 --- a/vespalib/src/vespa/vespalib/stllike/asciistream.h +++ b/vespalib/src/vespa/vespalib/stllike/asciistream.h @@ -2,7 +2,6 @@ #pragma once #include <vespa/vespalib/stllike/string.h> -#include <vector> namespace vespalib { @@ -153,7 +152,6 @@ public: static asciistream createFromFile(stringref fileName); static asciistream createFromDevice(stringref fileName); string getline(char delim='\n'); - std::vector<string> getlines(char delim='\n'); char getFill() const noexcept { return _fill; } size_t getWidth() const noexcept { return static_cast<size_t>(_width); } // match input type of setw Base getBase() const noexcept { return _base; } diff --git a/vespalib/src/vespa/vespalib/util/shared_string_repo.h b/vespalib/src/vespa/vespalib/util/shared_string_repo.h index ec65b942d88..7ba59937c7c 100644 --- a/vespalib/src/vespa/vespalib/util/shared_string_repo.h +++ b/vespalib/src/vespa/vespalib/util/shared_string_repo.h @@ -8,6 +8,7 @@ #include <vespa/vespalib/stllike/string.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/stllike/identity.h> +#include <vespa/vespalib/stllike/allocator.h> #include <vespa/vespalib/stllike/hashtable.hpp> #include <xxhash.h> #include <mutex> @@ -95,6 +96,7 @@ private: return (--_ref_cnt == 0); } }; + using EntryVector = std::vector<Entry, allocator_large<Entry>>; struct Key { uint32_t idx; uint32_t hash; @@ -104,8 +106,8 @@ private: uint32_t operator()(const AltKey &key) const { return key.hash; } }; struct Equal { - const std::vector<Entry> &entries; - Equal(const std::vector<Entry> &entries_in) : entries(entries_in) {} + const EntryVector &entries; + Equal(const EntryVector &entries_in) : entries(entries_in) {} Equal(const Equal &rhs) = default; bool operator()(const Key &a, const Key &b) const { return (a.idx == b.idx); } bool operator()(const Key &a, const AltKey &b) const { return ((a.hash == b.hash) && (entries[a.idx].str() == b.str)); } @@ -113,10 +115,10 @@ private: using HashType = hashtable<Key,Key,Hash,Equal,Identity,hashtable_base::and_modulator>; private: - mutable SpinLock _lock; - std::vector<Entry> _entries; - uint32_t _free; - HashType _hash; + mutable SpinLock _lock; + EntryVector _entries; + uint32_t _free; + HashType _hash; void make_entries(size_t hint); @@ -291,7 +293,7 @@ public: // A collection of string handles with ownership class Handles { private: - std::vector<string_id> _handles; + StringIdVector _handles; public: Handles(); Handles(Handles &&rhs); @@ -309,7 +311,7 @@ public: string_id id = _repo.copy(handle); _handles.push_back(id); } - const std::vector<string_id> &view() const { return _handles; } + const StringIdVector &view() const { return _handles; } }; }; diff --git a/vespalib/src/vespa/vespalib/util/string_id.h b/vespalib/src/vespa/vespalib/util/string_id.h index 7a72feee64a..7fec1da0bb8 100644 --- a/vespalib/src/vespa/vespalib/util/string_id.h +++ b/vespalib/src/vespa/vespalib/util/string_id.h @@ -2,7 +2,8 @@ #pragma once -#include <cstdint> +#include <vespa/vespalib/stllike/allocator.h> +#include <vector> namespace vespalib { @@ -38,4 +39,6 @@ public: constexpr bool operator!=(const string_id &rhs) const noexcept { return (_id != rhs._id); } }; +using StringIdVector = std::vector<string_id, vespalib::allocator_large<string_id>>; + } |