diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-05-23 19:03:30 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-05-23 19:03:30 +0000 |
commit | 82bea8313f493bc8f790633e0c3aee213f4612b7 (patch) | |
tree | 94715d54e8b7ca47140d98cd5e4816b87ec9d198 | |
parent | 3a4a2785afccbbd246eaad4f8d20ec22d0465562 (diff) |
- Stick to using GrowStragey everywhere.
- Store the full config in the rcu vector.
12 files changed, 31 insertions, 91 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp index 46b5f051422..1888b2c4a52 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp @@ -409,16 +409,11 @@ DocumentMetaStore::DocumentMetaStore(BucketDBOwnerSP bucketDB, const GrowStrategy &grow, SubDbType subDbType) : DocumentMetaStoreAttribute(name), - _metaDataStore(grow.getDocsInitialCapacity(), - grow.getDocsGrowPercent(), - grow.getDocsGrowDelta(), - getGenerationHolder()), + _metaDataStore(grow.to_generic_strategy(), getGenerationHolder()), _gidToLidMap(), _gid_to_lid_map_write_itr(vespalib::datastore::EntryRef(), _gidToLidMap.getAllocator()), _gid_to_lid_map_write_itr_prepare_serial_num(0u), - _lidAlloc(_metaDataStore.size(), - _metaDataStore.capacity(), - getGenerationHolder()), + _lidAlloc(_metaDataStore.size(), _metaDataStore.capacity(), getGenerationHolder()), _bucketDB(std::move(bucketDB)), _shrinkLidSpaceBlockers(0), _subDbType(subDbType), diff --git a/searchlib/src/vespa/searchlib/attribute/reference_attribute.cpp b/searchlib/src/vespa/searchlib/attribute/reference_attribute.cpp index 473174de284..66042bcf0c4 100644 --- a/searchlib/src/vespa/searchlib/attribute/reference_attribute.cpp +++ b/searchlib/src/vespa/searchlib/attribute/reference_attribute.cpp @@ -43,7 +43,7 @@ ReferenceAttribute::ReferenceAttribute(const vespalib::stringref baseFileName, const Config & cfg) : NotImplementedAttribute(baseFileName, cfg), _store({}), - _indices(getGenerationHolder()), + _indices(cfg.getGrowStrategy().to_generic_strategy(), getGenerationHolder()), _compaction_spec(), _gidToLidMapperFactory(), _referenceMappings(getGenerationHolder(), getCommittedDocIdLimitRef()) diff --git a/searchlib/src/vespa/searchlib/attribute/reference_mappings.cpp b/searchlib/src/vespa/searchlib/attribute/reference_mappings.cpp index 65bbd9514c7..6ebc2996408 100644 --- a/searchlib/src/vespa/searchlib/attribute/reference_mappings.cpp +++ b/searchlib/src/vespa/searchlib/attribute/reference_mappings.cpp @@ -9,10 +9,10 @@ namespace search::attribute { ReferenceMappings::ReferenceMappings(GenerationHolder &genHolder, const std::atomic<uint32_t>& committedDocIdLimit) - : _reverseMappingIndices(genHolder), + : _reverseMappingIndices(vespalib::GrowStrategy(16, 1.0, 0), genHolder), _targetLidLimit(0), _reverseMapping(), - _targetLids(genHolder), + _targetLids(vespalib::GrowStrategy(16, 1.0, 0), genHolder), _committedDocIdLimit(committedDocIdLimit) { } diff --git a/searchlib/src/vespa/searchlib/attribute/singleenumattribute.cpp b/searchlib/src/vespa/searchlib/attribute/singleenumattribute.cpp index 38ef186b717..e6695ef6c6c 100644 --- a/searchlib/src/vespa/searchlib/attribute/singleenumattribute.cpp +++ b/searchlib/src/vespa/searchlib/attribute/singleenumattribute.cpp @@ -15,10 +15,7 @@ using attribute::Config; SingleValueEnumAttributeBase:: SingleValueEnumAttributeBase(const Config & c, GenerationHolder &genHolder, const vespalib::alloc::Alloc& initial_alloc) - : _enumIndices(c.getGrowStrategy().getDocsInitialCapacity(), - c.getGrowStrategy().getDocsGrowPercent(), - c.getGrowStrategy().getDocsGrowDelta(), - genHolder, initial_alloc) + : _enumIndices(c.getGrowStrategy().to_generic_strategy(), genHolder, initial_alloc) { } diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp index 917f0f55894..0a3c6a9ac4f 100644 --- a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp @@ -17,11 +17,7 @@ template <typename B> SingleValueNumericAttribute<B>:: SingleValueNumericAttribute(const vespalib::string & baseFileName, const AttributeVector::Config & c) : B(baseFileName, c), - _data(c.getGrowStrategy().getDocsInitialCapacity(), - c.getGrowStrategy().getDocsGrowPercent(), - c.getGrowStrategy().getDocsGrowDelta(), - getGenerationHolder(), - this->get_initial_alloc()) + _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 eca74255026..3bc2cb8f96a 100644 --- a/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp +++ b/searchlib/src/vespa/searchlib/attribute/singlesmallnumericattribute.cpp @@ -24,10 +24,7 @@ SingleValueSmallNumericAttribute(const vespalib::string & baseFileName, _valueShiftShift(valueShiftShift), _valueShiftMask(valueShiftMask), _wordShift(wordShift), - _wordData(c.getGrowStrategy().getDocsInitialCapacity(), - c.getGrowStrategy().getDocsGrowPercent(), - c.getGrowStrategy().getDocsGrowDelta(), - getGenerationHolder()) + _wordData(c.getGrowStrategy().to_generic_strategy(), getGenerationHolder()) { assert(_valueMask + 1 == (1u << (1u << valueShiftShift))); assert((_valueShiftMask + 1) * (1u << valueShiftShift) == 8 * sizeof(Word)); diff --git a/searchlib/src/vespa/searchlib/common/condensedbitvectors.cpp b/searchlib/src/vespa/searchlib/common/condensedbitvectors.cpp index 569e1275080..74df5c8c5d4 100644 --- a/searchlib/src/vespa/searchlib/common/condensedbitvectors.cpp +++ b/searchlib/src/vespa/searchlib/common/condensedbitvectors.cpp @@ -17,7 +17,7 @@ class CondensedBitVectorT : public CondensedBitVector { public: CondensedBitVectorT(size_t sz, GenerationHolder &genHolder) : - _v(sz, 30, 1000, genHolder) + _v(vespalib::GrowStrategy(sz, 30, 1000), genHolder) { for (size_t i = 0; i < sz; ++i) { _v.push_back(0); diff --git a/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp b/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp index 51a4d392839..04cb687e366 100644 --- a/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp +++ b/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp @@ -67,9 +67,7 @@ LogDataStore::LogDataStore(vespalib::Executor &executor, const vespalib::string _tune(tune), _fileHeaderContext(fileHeaderContext), _genHandler(), - _lidInfo(growStrategy.getDocsInitialCapacity(), - growStrategy.getDocsGrowPercent(), - growStrategy.getDocsGrowDelta()), + _lidInfo(growStrategy.to_generic_strategy()), _fileChunks(), _holdFileChunks(), _active(0), diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp index c1cafd547aa..dabf9203551 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp +++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp @@ -49,10 +49,7 @@ vespalib::string makeWrongTensorTypeMsg(const ValueType &fieldTensorType, const TensorAttribute::TensorAttribute(vespalib::stringref name, const Config &cfg, TensorStore &tensorStore) : NotImplementedAttribute(name, cfg), - _refVector(cfg.getGrowStrategy().getDocsInitialCapacity(), - cfg.getGrowStrategy().getDocsGrowPercent(), - cfg.getGrowStrategy().getDocsGrowDelta(), - getGenerationHolder()), + _refVector(cfg.getGrowStrategy().to_generic_strategy(), getGenerationHolder()), _tensorStore(tensorStore), _is_dense(cfg.tensorType().is_dense()), _emptyTensor(createEmptyTensor(cfg.tensorType())), diff --git a/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp b/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp index 7161eed24c9..0190d59edfb 100644 --- a/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp +++ b/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp @@ -34,7 +34,7 @@ assertUsage(const MemoryUsage & exp, const MemoryUsage & act) TEST(RcuVectorTest, basic) { { // insert - RcuVector<int32_t> v(4, 0, 4); + RcuVector<int32_t> v(GrowStrategy(4, 0, 4)); for (int32_t i = 0; i < 100; ++i) { v.push_back(i); EXPECT_EQ(i, v[i]); @@ -53,7 +53,7 @@ TEST(RcuVectorTest, basic) TEST(RcuVectorTest, resize) { { // resize percent - RcuVector<int32_t> v(2, 50, 0); + RcuVector<int32_t> v(GrowStrategy(2, 0.50, 0)); EXPECT_EQ(2u, v.capacity()); v.push_back(0); EXPECT_EQ(2u, v.capacity()); @@ -65,7 +65,7 @@ TEST(RcuVectorTest, resize) EXPECT_TRUE(v.isFull()); } { // resize delta - RcuVector<int32_t> v(1, 0, 3); + RcuVector<int32_t> v(GrowStrategy(1, 0, 3)); EXPECT_EQ(1u, v.capacity()); v.push_back(0); EXPECT_EQ(1u, v.capacity()); @@ -75,7 +75,7 @@ TEST(RcuVectorTest, resize) EXPECT_TRUE(!v.isFull()); } { // resize both - RcuVector<int32_t> v(2, 200, 3); + RcuVector<int32_t> v(GrowStrategy(2, 2.0, 3)); EXPECT_EQ(2u, v.capacity()); v.push_back(0); EXPECT_EQ(2u, v.capacity()); @@ -87,14 +87,14 @@ TEST(RcuVectorTest, resize) EXPECT_TRUE(!v.isFull()); } { // reserve - RcuVector<int32_t> v(2, 0, 0); + RcuVector<int32_t> v(GrowStrategy(2, 0, 0)); EXPECT_EQ(2u, v.capacity()); v.unsafe_reserve(8); EXPECT_EQ(8u, v.capacity()); } { // explicit resize GenerationHolder g; - RcuVectorBase<int8_t> v(g); + RcuVectorBase<int8_t> v(GrowStrategy(16, 1.0, 0), g); v.push_back(1); v.push_back(2); g.transferHoldLists(0); @@ -120,7 +120,7 @@ TEST(RcuVectorTest, resize) TEST(RcuVectorTest, generation_handling) { - RcuVector<int32_t> v(2, 0, 2); + RcuVector<int32_t> v(GrowStrategy(2, 0, 2)); v.push_back(0); v.push_back(10); EXPECT_EQ(0u, v.getMemoryUsage().allocatedBytesOnHold()); @@ -143,7 +143,7 @@ TEST(RcuVectorTest, generation_handling) TEST(RcuVectorTest, reserve) { - RcuVector<int32_t> v(2, 0, 2); + RcuVector<int32_t> v(GrowStrategy(2, 0, 2)); EXPECT_EQ(2u, v.capacity()); EXPECT_EQ(0u, v.size()); v.push_back(0); @@ -167,7 +167,7 @@ TEST(RcuVectorTest, reserve) TEST(RcuVectorTest, memory_usage) { - RcuVector<int8_t> v(2, 0, 2); + RcuVector<int8_t> v(GrowStrategy(2, 0, 2)); EXPECT_TRUE(assertUsage(MemoryUsage(2,0,0,0), v.getMemoryUsage())); v.push_back(0); EXPECT_TRUE(assertUsage(MemoryUsage(2,1,0,0), v.getMemoryUsage())); @@ -186,7 +186,7 @@ TEST(RcuVectorTest, memory_usage) TEST(RcuVectorTest, shrink_with_buffer_copying) { GenerationHolder g; - RcuVectorBase<int8_t> v(16, 100, 0, g); + RcuVectorBase<int8_t> v(GrowStrategy(16, 1.0, 0), g); v.push_back(1); v.push_back(2); v.push_back(3); @@ -229,7 +229,7 @@ struct ShrinkFixture { ShrinkFixture() : g(), initial_capacity(4 * page_ints()), initial_size(initial_capacity / 1024 * 1000), - vec(initial_capacity, 50, 0, g, alloc::Alloc::allocMMap()), oldPtr() + vec(GrowStrategy(initial_capacity, 0.50, 0), g, alloc::Alloc::allocMMap()), oldPtr() { for (size_t i = 0; i < initial_size; ++i) { vec.push_back(7); @@ -272,7 +272,7 @@ TEST(RcuVectorTest, shrink_can_shrink_mmap_allocation) TEST(RcuVectorTest, small_expand) { GenerationHolder g; - RcuVectorBase<int8_t> v(1, 50, 0, g); + RcuVectorBase<int8_t> v(GrowStrategy(1, 0.50, 0), g); EXPECT_EQ(1u, v.capacity()); EXPECT_EQ(0u, v.size()); v.push_back(1); @@ -321,7 +321,7 @@ struct Fixture : public FixtureBase { Fixture::Fixture() : FixtureBase(), - arr(g, initial_alloc) + arr(GrowStrategy(16, 1.0, 0), g, initial_alloc) { arr.reserve(100); } @@ -403,7 +403,7 @@ struct StressFixture : public FixtureBase { StressFixture::StressFixture() : FixtureBase(), - arr(g, initial_alloc), + arr(GrowStrategy(16, 1.0, 0), g, initial_alloc), stop_read(false), read_area(1000), generation_handler(), diff --git a/vespalib/src/vespa/vespalib/util/rcuvector.h b/vespalib/src/vespa/vespalib/util/rcuvector.h index ce48082099c..1c5cad8ea90 100644 --- a/vespalib/src/vespa/vespalib/util/rcuvector.h +++ b/vespalib/src/vespa/vespalib/util/rcuvector.h @@ -46,12 +46,11 @@ protected: private: ArrayType _data; std::atomic<const T*> _vector_start; - size_t _growPercent; - size_t _growDelta; + GrowStrategy _growStrategy; GenerationHolderType &_genHolder; size_t calcNewSize(size_t baseSize) const { - size_t delta = (baseSize * _growPercent / 100) + _growDelta; + size_t delta = (baseSize * _growStrategy.getGrowPercent() / 100) + _growStrategy.getGrowDelta(); return baseSize + std::max(delta, static_cast<size_t>(1)); } size_t calcNewSize() const { @@ -65,8 +64,6 @@ protected: public: using ValueType = T; - RcuVectorBase(GenerationHolderType &genHolder, - const Alloc &initialAlloc = Alloc::alloc()); /** * Construct a new vector with the given initial capacity and grow @@ -75,10 +72,6 @@ public: * New capacity is calculated based on old capacity and grow parameters: * nc = oc + (oc * growPercent / 100) + growDelta. **/ - RcuVectorBase(size_t initialCapacity, size_t growPercent, size_t growDelta, - GenerationHolderType &genHolder, - const Alloc &initialAlloc = Alloc::alloc()); - RcuVectorBase(GrowStrategy growStrategy, GenerationHolderType &genHolder, const Alloc &initialAlloc = Alloc::alloc()); @@ -185,7 +178,6 @@ public: * New capacity is calculated based on old capacity and grow parameters: * nc = oc + (oc * growPercent / 100) + growDelta. **/ - RcuVector(size_t initialCapacity, size_t growPercent, size_t growDelta); RcuVector(GrowStrategy growStrategy); ~RcuVector(); diff --git a/vespalib/src/vespa/vespalib/util/rcuvector.hpp b/vespalib/src/vespa/vespalib/util/rcuvector.hpp index 81928251b19..decaf774e88 100644 --- a/vespalib/src/vespa/vespalib/util/rcuvector.hpp +++ b/vespalib/src/vespa/vespalib/util/rcuvector.hpp @@ -111,44 +111,19 @@ RcuVectorBase<T>::shrink(size_t newSize) } template <typename T> -RcuVectorBase<T>::RcuVectorBase(GenerationHolderType &genHolder, - const Alloc &initialAlloc) - : _data(initialAlloc), - _vector_start(nullptr), - _growPercent(100), - _growDelta(0), - _genHolder(genHolder) -{ - _data.reserve(16); - update_vector_start(); -} - -template <typename T> -RcuVectorBase<T>::RcuVectorBase(size_t initialCapacity, - size_t growPercent, - size_t growDelta, +RcuVectorBase<T>::RcuVectorBase(GrowStrategy growStrategy, GenerationHolderType &genHolder, const Alloc &initialAlloc) : _data(initialAlloc), _vector_start(nullptr), - _growPercent(growPercent), - _growDelta(growDelta), + _growStrategy(growStrategy), _genHolder(genHolder) { - _data.reserve(initialCapacity); + _data.reserve(_growStrategy.getInitialCapacity()); update_vector_start(); } template <typename T> -RcuVectorBase<T>::RcuVectorBase(GrowStrategy growStrategy, - GenerationHolderType &genHolder, - const Alloc &initialAlloc) - : RcuVectorBase(growStrategy.getInitialCapacity(), growStrategy.getGrowPercent(), - growStrategy.getGrowDelta(), genHolder, initialAlloc) -{ -} - -template <typename T> MemoryUsage RcuVectorBase<T>::getMemoryUsage() const { @@ -181,14 +156,7 @@ RcuVector<T>::onReallocation() { template <typename T> RcuVector<T>::RcuVector() - : RcuVectorBase<T>(_genHolderStore), - _generation(0), - _genHolderStore() -{ } - -template <typename T> -RcuVector<T>::RcuVector(size_t initialCapacity, size_t growPercent, size_t growDelta) - : RcuVectorBase<T>(initialCapacity, growPercent, growDelta, _genHolderStore), + : RcuVectorBase<T>(GrowStrategy(16, 1.0, 0), _genHolderStore), _generation(0), _genHolderStore() { } |