summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-05-26 12:17:16 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-05-26 12:17:16 +0000
commitb97550bbeba3fc7eb37f35ec5b97feb540a216b5 (patch)
tree11628f5f95049da128b30b628ec1553d39cea308 /searchlib
parentff4b47aed7c1de0f4c34a6904b0cbfac70ee0294 (diff)
Use unique_ptr for Config in AttributeVector
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/attribute/postinglistattribute/postinglistattribute_test.cpp7
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attribute_operation.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributevector.cpp19
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributevector.h24
-rw-r--r--searchlib/src/vespa/searchlib/attribute/floatbase.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/integerbase.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlenumericattribute.h8
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp14
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp1
-rw-r--r--searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/tensor/tensor_attribute.h4
12 files changed, 58 insertions, 32 deletions
diff --git a/searchlib/src/tests/attribute/postinglistattribute/postinglistattribute_test.cpp b/searchlib/src/tests/attribute/postinglistattribute/postinglistattribute_test.cpp
index e58954e1e93..ad082b3375a 100644
--- a/searchlib/src/tests/attribute/postinglistattribute/postinglistattribute_test.cpp
+++ b/searchlib/src/tests/attribute/postinglistattribute/postinglistattribute_test.cpp
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/gtest/gtest.h>
-#include <vespa/vespalib/stllike/asciistream.h>
#include <vespa/document/update/arithmeticvalueupdate.h>
#include <vespa/searchlib/attribute/attribute.h>
@@ -13,12 +12,14 @@
#include <vespa/searchlib/attribute/multistringpostattribute.h>
#include <vespa/searchlib/common/growablebitvector.h>
#include <vespa/searchlib/queryeval/executeinfo.h>
+#include <vespa/searchlib/fef/termfieldmatchdata.h>
#include <vespa/searchlib/parsequery/parse.h>
-#include <vespa/searchlib/attribute/enumstore.hpp>
+#include <vespa/searchcommon/attribute/config.h>
+#include <vespa/vespalib/stllike/asciistream.h>
#include <vespa/vespalib/io/fileutil.h>
#include <vespa/vespalib/util/compress.h>
-#include <vespa/searchlib/fef/termfieldmatchdata.h>
#include <vespa/fastos/file.h>
+#include <vespa/searchlib/attribute/enumstore.hpp>
#include <iostream>
#include <vespa/log/log.h>
diff --git a/searchlib/src/vespa/searchlib/attribute/attribute_operation.cpp b/searchlib/src/vespa/searchlib/attribute/attribute_operation.cpp
index 347793be4c6..e21e272f225 100644
--- a/searchlib/src/vespa/searchlib/attribute/attribute_operation.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attribute_operation.cpp
@@ -96,7 +96,7 @@ struct UpdateFast {
void operator()(uint32_t docid) { attr->set(docid, op(attr->getFast(docid))); }
bool valid() const {
return (attr != nullptr) &&
- (attr->getConfig().isMutable()); }
+ (attr->isMutable()); }
};
template <typename OP>
diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
index d7c9bb8d224..2ad95a584ab 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
@@ -14,6 +14,7 @@
#include <vespa/document/update/mapvalueupdate.h>
#include <vespa/fastlib/io/bufferedfile.h>
#include <vespa/searchcommon/attribute/attribute_utils.h>
+#include <vespa/searchcommon/attribute/config.h>
#include <vespa/searchlib/common/tunefileinfo.h>
#include <vespa/searchlib/index/dummyfileheadercontext.h>
#include <vespa/searchlib/query/query_term_decoder.h>
@@ -136,7 +137,7 @@ make_memory_allocator(const vespalib::string& name, const search::attribute::Con
AttributeVector::AttributeVector(vespalib::stringref baseFileName, const Config &c)
: _baseFileName(baseFileName),
- _config(c),
+ _config(std::make_unique<Config>(c)),
_interlock(std::make_shared<attribute::Interlock>()),
_enumLock(),
_genHandler(),
@@ -170,6 +171,16 @@ AttributeVector::updateStat(bool force) {
bool AttributeVector::hasEnum() const { return _hasEnum; }
uint32_t AttributeVector::getMaxValueCount() const { return _highestValueCount.load(std::memory_order_relaxed); }
+bool AttributeVector::hasMultiValue() const { return _config->collectionType().isMultiValue(); }
+bool AttributeVector::hasWeightedSetType() const { return _config->collectionType().isWeightedSet(); }
+size_t AttributeVector::getFixedWidth() const { return _config->basicType().fixedSize(); }
+attribute::BasicType AttributeVector::getInternalBasicType() const { return _config->basicType(); }
+attribute::CollectionType AttributeVector::getInternalCollectionType() const { return _config->collectionType(); }
+bool AttributeVector::hasArrayType() const { return _config->collectionType().isArray(); }
+bool AttributeVector::getIsFilter() const { return _config->getIsFilter(); }
+bool AttributeVector::getIsFastSearch() const { return _config->fastSearch(); }
+bool AttributeVector::isMutable() const { return _config->isMutable(); }
+bool AttributeVector::getEnableOnlyBitVector() const { return _config->getEnableOnlyBitVector(); }
bool
AttributeVector::isEnumerated(const vespalib::GenericHeader &header)
@@ -774,12 +785,12 @@ void
AttributeVector::update_config(const Config& cfg)
{
commit(true);
- _config.setGrowStrategy(cfg.getGrowStrategy());
- if (cfg.getCompactionStrategy() == _config.getCompactionStrategy()) {
+ _config->setGrowStrategy(cfg.getGrowStrategy());
+ if (cfg.getCompactionStrategy() == _config->getCompactionStrategy()) {
return;
}
drain_hold(1_Mi); // Wait until 1MiB or less on hold
- _config.setCompactionStrategy(cfg.getCompactionStrategy());
+ _config->setCompactionStrategy(cfg.getCompactionStrategy());
updateStat(true);
commit(); // might trigger compaction
drain_hold(1_Mi); // Wait until 1MiB or less on hold
diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.h b/searchlib/src/vespa/searchlib/attribute/attributevector.h
index 09dc27f0451..983c4c4ae22 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributevector.h
+++ b/searchlib/src/vespa/searchlib/attribute/attributevector.h
@@ -59,6 +59,7 @@ namespace search {
class InterlockGuard;
class SearchContext;
class MultiValueMappingBase;
+ class Config;
}
namespace fileutil {
@@ -352,18 +353,23 @@ public:
void logEnumStoreEvent(const char *reason, const char *stage);
/** Return the fixed length of the attribute. If 0 then you must inquire each document. */
- size_t getFixedWidth() const override { return _config.basicType().fixedSize(); }
- const Config &getConfig() const noexcept { return _config; }
+ size_t getFixedWidth() const override;
+ BasicType getInternalBasicType() const;
+ CollectionType getInternalCollectionType() const;
+ bool hasArrayType() const;
+ bool getIsFilter() const override final;
+ bool getIsFastSearch() const override final;
+ bool isMutable() const;
+ bool getEnableOnlyBitVector() const;
+
+ const Config &getConfig() const noexcept { return *_config; }
void update_config(const Config& cfg);
- BasicType getInternalBasicType() const { return _config.basicType(); }
- CollectionType getInternalCollectionType() const { return _config.collectionType(); }
const BaseName & getBaseFileName() const { return _baseFileName; }
void setBaseFileName(vespalib::stringref name) { _baseFileName = name; }
bool isUpdateableInMemoryOnly() const { return _isUpdateableInMemoryOnly; }
const vespalib::string & getName() const override final { return _baseFileName.getAttributeName(); }
- bool hasArrayType() const { return _config.collectionType().isArray(); }
bool hasEnum() const override final;
uint32_t getMaxValueCount() const override;
uint32_t getEnumMax() const { return _enumMax; }
@@ -388,8 +394,6 @@ public:
BasicType::Type getBasicType() const override final { return getInternalBasicType().type(); }
CollectionType::Type getCollectionType() const override final { return getInternalCollectionType().type(); }
- bool getIsFilter() const override final { return _config.getIsFilter(); }
- bool getIsFastSearch() const override final { return _config.fastSearch(); }
uint32_t getCommittedDocIdLimit() const override final { return _committedDocIdLimit.load(std::memory_order_acquire); }
bool isImported() const override;
@@ -490,7 +494,7 @@ private:
BaseName _baseFileName;
- Config _config;
+ std::unique_ptr<Config> _config;
std::shared_ptr<attribute::Interlock> _interlock;
mutable std::shared_mutex _enumLock;
GenerationHandler _genHandler;
@@ -533,8 +537,8 @@ private:
friend class AttributeManagerTest;
public:
bool headerTypeOK(const vespalib::GenericHeader &header) const;
- bool hasMultiValue() const override final { return _config.collectionType().isMultiValue(); }
- bool hasWeightedSetType() const override final { return _config.collectionType().isWeightedSet(); }
+ bool hasMultiValue() const override final;
+ bool hasWeightedSetType() const override final;
/**
* Should be called by the writer thread.
*/
diff --git a/searchlib/src/vespa/searchlib/attribute/floatbase.h b/searchlib/src/vespa/searchlib/attribute/floatbase.h
index 8ca6eda6421..787273c2050 100644
--- a/searchlib/src/vespa/searchlib/attribute/floatbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/floatbase.h
@@ -60,7 +60,7 @@ public:
using LoadedVector = SequentialReadModifyWriteInterface<LoadedNumericValueT>;
virtual T get(DocId doc) const = 0;
virtual T getFromEnum(EnumHandle e) const = 0;
- T defaultValue() const { return getConfig().isMutable() ? 0.0 : attribute::getUndefined<T>(); }
+ T defaultValue() const { return isMutable() ? 0.0 : attribute::getUndefined<T>(); }
protected:
FloatingPointAttributeTemplate(const vespalib::string & name);
FloatingPointAttributeTemplate(const vespalib::string & name, const Config & c);
diff --git a/searchlib/src/vespa/searchlib/attribute/integerbase.h b/searchlib/src/vespa/searchlib/attribute/integerbase.h
index 65d16ce934a..42f169a0c1a 100644
--- a/searchlib/src/vespa/searchlib/attribute/integerbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/integerbase.h
@@ -58,7 +58,7 @@ public:
using LoadedVector = SequentialReadModifyWriteInterface<LoadedNumericValueT>;
virtual T get(DocId doc) const = 0;
virtual T getFromEnum(EnumHandle e) const = 0;
- T defaultValue() const { return getConfig().isMutable() ? 0 : attribute::getUndefined<T>(); }
+ T defaultValue() const { return isMutable() ? 0 : attribute::getUndefined<T>(); }
protected:
IntegerAttributeTemplate(const vespalib::string & name);
IntegerAttributeTemplate(const vespalib::string & name, const Config & c);
diff --git a/searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp b/searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp
index b0765680f78..a5bb901be31 100644
--- a/searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp
@@ -10,6 +10,7 @@
#include <vespa/searchlib/query/query_term_simple.h>
#include <vespa/searchlib/queryeval/emptysearch.h>
#include <vespa/searchlib/util/file_settings.h>
+#include <vespa/searchcommon/attribute/config.h>
#include <vespa/vespalib/data/databuffer.h>
#include <vespa/vespalib/util/size_literals.h>
diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.h b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.h
index cf3fa85a060..2e9303bef62 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.h
@@ -41,12 +41,8 @@ protected:
}
public:
- SingleValueNumericAttribute(const vespalib::string & baseFileName,
- const AttributeVector::Config & c =
- AttributeVector::Config(AttributeVector::
- BasicType::fromType(T()),
- attribute::CollectionType::SINGLE));
-
+ SingleValueNumericAttribute(const vespalib::string & baseFileName); // Only for testing
+ SingleValueNumericAttribute(const vespalib::string & baseFileName, const AttributeVector::Config & c);
~SingleValueNumericAttribute();
diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp
index 0a3c6a9ac4f..15f745cf311 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp
@@ -10,14 +10,22 @@
#include "singlenumericattributesaver.h"
#include "single_numeric_search_context.h"
#include <vespa/searchlib/query/query_term_simple.h>
+#include <vespa/searchcommon/attribute/config.h>
namespace search {
template <typename B>
SingleValueNumericAttribute<B>::
-SingleValueNumericAttribute(const vespalib::string & baseFileName, const AttributeVector::Config & c) :
- B(baseFileName, c),
- _data(c.getGrowStrategy().to_generic_strategy(), getGenerationHolder(), this->get_initial_alloc())
+SingleValueNumericAttribute(const vespalib::string & baseFileName)
+ : SingleValueNumericAttribute(baseFileName, attribute::Config(attribute::BasicType::fromType(T()),
+ attribute::CollectionType::SINGLE))
+{ }
+
+template <typename B>
+SingleValueNumericAttribute<B>::
+SingleValueNumericAttribute(const vespalib::string & baseFileName, const AttributeVector::Config & c)
+ : B(baseFileName, c),
+ _data(c.getGrowStrategy().to_generic_strategy(), getGenerationHolder(), this->get_initial_alloc())
{ }
template <typename B>
diff --git a/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp b/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp
index 3bc2cb8f96a..3ee2671d7e1 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp
@@ -7,6 +7,7 @@
#include "single_small_numeric_search_context.h"
#include <vespa/searchlib/query/query_term_simple.h>
#include <vespa/searchlib/util/file_settings.h>
+#include <vespa/searchcommon/attribute/config.h>
#include <vespa/vespalib/data/databuffer.h>
#include <vespa/vespalib/util/size_literals.h>
diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp
index e000afedadc..4a6dfecb388 100644
--- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp
+++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp
@@ -5,6 +5,7 @@
#include <vespa/document/datatype/tensor_data_type.h>
#include <vespa/searchlib/attribute/address_space_components.h>
#include <vespa/searchlib/util/state_explorer_utils.h>
+#include <vespa/searchcommon/attribute/config.h>
#include <vespa/vespalib/data/slime/cursor.h>
#include <vespa/vespalib/data/slime/inserter.h>
#include <vespa/vespalib/util/shared_string_repo.h>
@@ -311,6 +312,11 @@ TensorAttribute::complete_set_tensor(DocId docid, const vespalib::eval::Value& t
(void) prepare_result;
}
+attribute::DistanceMetric
+TensorAttribute::distance_metric() const {
+ return getConfig().distance_metric();
+}
+
IMPLEMENT_IDENTIFIABLE_ABSTRACT(TensorAttribute, AttributeVector);
}
diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h
index 518caef9dc9..505e072fa31 100644
--- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h
+++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h
@@ -68,9 +68,7 @@ public:
virtual void update_tensor(DocId docId,
const document::TensorUpdate &update,
bool create_empty_if_non_existing);
- DistanceMetric distance_metric() const override {
- return getConfig().distance_metric();
- }
+ DistanceMetric distance_metric() const override;
uint32_t get_num_docs() const override { return getNumDocs(); }
/**