summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-03-10 13:13:51 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-03-10 13:27:00 +0000
commitcc04abc57ff890ee0e2f1956433520b72c9d6b14 (patch)
treec5dff4a4aff8ec3d5f081f7f1af8909256176296
parent4fc5346dcb568d2bd4e284d0ddfd1228cd904d53 (diff)
Use a non const Store when you are in write thread, and a const when not.
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumattributesaver.cpp7
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumattributesaver.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumstore.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumstore.hpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/i_enum_store.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multienumattributesaver.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multienumattributesaver.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/reference_attribute_saver.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/reference_attribute_saver.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singleenumattributesaver.cpp13
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singleenumattributesaver.h2
-rw-r--r--vespalib/src/tests/datastore/array_store/array_store_test.cpp6
-rw-r--r--vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp6
-rw-r--r--vespalib/src/vespa/vespalib/datastore/array_store.h2
-rw-r--r--vespalib/src/vespa/vespalib/datastore/array_store.hpp2
-rw-r--r--vespalib/src/vespa/vespalib/datastore/datastorebase.h1
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store.h5
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store.hpp2
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.h4
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.hpp8
20 files changed, 33 insertions, 45 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/enumattributesaver.cpp b/searchlib/src/vespa/searchlib/attribute/enumattributesaver.cpp
index 74a37ca8394..a2090185158 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumattributesaver.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/enumattributesaver.cpp
@@ -8,16 +8,13 @@
namespace search {
-EnumAttributeSaver::
-EnumAttributeSaver(const IEnumStore &enumStore)
+EnumAttributeSaver::EnumAttributeSaver(IEnumStore &enumStore)
: _enumStore(enumStore),
_enumerator(enumStore.make_enumerator())
{
}
-EnumAttributeSaver::~EnumAttributeSaver()
-{
-}
+EnumAttributeSaver::~EnumAttributeSaver() = default;
void
EnumAttributeSaver::writeUdat(IAttributeSaveTarget &saveTarget)
diff --git a/searchlib/src/vespa/searchlib/attribute/enumattributesaver.h b/searchlib/src/vespa/searchlib/attribute/enumattributesaver.h
index d6dceb4772a..47af8c0452e 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumattributesaver.h
+++ b/searchlib/src/vespa/searchlib/attribute/enumattributesaver.h
@@ -24,7 +24,7 @@ private:
std::unique_ptr<Enumerator> _enumerator;
public:
- EnumAttributeSaver(const IEnumStore &enumStore);
+ EnumAttributeSaver(IEnumStore &enumStore);
~EnumAttributeSaver();
void writeUdat(IAttributeSaveTarget &saveTarget);
diff --git a/searchlib/src/vespa/searchlib/attribute/enumstore.h b/searchlib/src/vespa/searchlib/attribute/enumstore.h
index df3a595ae34..59524f3788a 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumstore.h
+++ b/searchlib/src/vespa/searchlib/attribute/enumstore.h
@@ -212,7 +212,7 @@ public:
void inc_compaction_count() override {
_store.get_allocator().get_data_store().inc_compaction_count();
}
- std::unique_ptr<Enumerator> make_enumerator() const override;
+ std::unique_ptr<Enumerator> make_enumerator() override;
std::unique_ptr<EntryComparator> allocate_comparator() const override;
// Methods below are only relevant for strings, and are templated to only be instantiated on demand.
diff --git a/searchlib/src/vespa/searchlib/attribute/enumstore.hpp b/searchlib/src/vespa/searchlib/attribute/enumstore.hpp
index b863e56fb4a..bc767a296eb 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumstore.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/enumstore.hpp
@@ -259,7 +259,7 @@ EnumStoreT<EntryT>::consider_compact_dictionary(const CompactionStrategy& compac
template <typename EntryT>
std::unique_ptr<IEnumStore::Enumerator>
-EnumStoreT<EntryT>::make_enumerator() const
+EnumStoreT<EntryT>::make_enumerator()
{
return std::make_unique<Enumerator>(*_dict, _store.get_data_store(), false);
}
diff --git a/searchlib/src/vespa/searchlib/attribute/i_enum_store.h b/searchlib/src/vespa/searchlib/attribute/i_enum_store.h
index 57886511221..2157db3e5ed 100644
--- a/searchlib/src/vespa/searchlib/attribute/i_enum_store.h
+++ b/searchlib/src/vespa/searchlib/attribute/i_enum_store.h
@@ -72,7 +72,7 @@ public:
enumstore::EnumeratedLoader make_enumerated_loader();
enumstore::EnumeratedPostingsLoader make_enumerated_postings_loader();
- virtual std::unique_ptr<Enumerator> make_enumerator() const = 0;
+ virtual std::unique_ptr<Enumerator> make_enumerator() = 0;
virtual std::unique_ptr<vespalib::datastore::EntryComparator> allocate_comparator() const = 0;
};
diff --git a/searchlib/src/vespa/searchlib/attribute/multienumattributesaver.cpp b/searchlib/src/vespa/searchlib/attribute/multienumattributesaver.cpp
index 083f0409821..87326f3628f 100644
--- a/searchlib/src/vespa/searchlib/attribute/multienumattributesaver.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/multienumattributesaver.cpp
@@ -80,7 +80,7 @@ MultiValueEnumAttributeSaver<MultiValueT>::
MultiValueEnumAttributeSaver(GenerationHandler::Guard &&guard,
const attribute::AttributeHeader &header,
const MultiValueMapping &mvMapping,
- const IEnumStore &enumStore)
+ IEnumStore &enumStore)
: Parent(std::move(guard), header, mvMapping),
_mvMapping(mvMapping),
_enumSaver(enumStore),
diff --git a/searchlib/src/vespa/searchlib/attribute/multienumattributesaver.h b/searchlib/src/vespa/searchlib/attribute/multienumattributesaver.h
index 44c45567733..7c127ac0781 100644
--- a/searchlib/src/vespa/searchlib/attribute/multienumattributesaver.h
+++ b/searchlib/src/vespa/searchlib/attribute/multienumattributesaver.h
@@ -35,7 +35,7 @@ public:
MultiValueEnumAttributeSaver(GenerationHandler::Guard &&guard,
const attribute::AttributeHeader &header,
const MultiValueMapping &mvMapping,
- const IEnumStore &enumStore);
+ IEnumStore &enumStore);
~MultiValueEnumAttributeSaver() override;
};
diff --git a/searchlib/src/vespa/searchlib/attribute/reference_attribute_saver.cpp b/searchlib/src/vespa/searchlib/attribute/reference_attribute_saver.cpp
index 0c3180875a3..a8f13df0a85 100644
--- a/searchlib/src/vespa/searchlib/attribute/reference_attribute_saver.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/reference_attribute_saver.cpp
@@ -16,7 +16,7 @@ namespace search::attribute {
ReferenceAttributeSaver::ReferenceAttributeSaver(GenerationHandler::Guard &&guard,
const AttributeHeader &header,
EntryRefVector&& indices,
- const Store &store)
+ Store &store)
: AttributeSaver(std::move(guard), header),
_indices(std::move(indices)),
_store(store),
@@ -25,9 +25,7 @@ ReferenceAttributeSaver::ReferenceAttributeSaver(GenerationHandler::Guard &&guar
}
-ReferenceAttributeSaver::~ReferenceAttributeSaver()
-{
-}
+ReferenceAttributeSaver::~ReferenceAttributeSaver() = default;
namespace {
diff --git a/searchlib/src/vespa/searchlib/attribute/reference_attribute_saver.h b/searchlib/src/vespa/searchlib/attribute/reference_attribute_saver.h
index deddc9980ec..fa3fafc3254 100644
--- a/searchlib/src/vespa/searchlib/attribute/reference_attribute_saver.h
+++ b/searchlib/src/vespa/searchlib/attribute/reference_attribute_saver.h
@@ -41,7 +41,7 @@ public:
ReferenceAttributeSaver(vespalib::GenerationHandler::Guard &&guard,
const AttributeHeader &header,
EntryRefVector&& indices,
- const Store &store);
+ Store &store);
~ReferenceAttributeSaver() override;
};
diff --git a/searchlib/src/vespa/searchlib/attribute/singleenumattributesaver.cpp b/searchlib/src/vespa/searchlib/attribute/singleenumattributesaver.cpp
index 1857e942136..1f3f3e104d1 100644
--- a/searchlib/src/vespa/searchlib/attribute/singleenumattributesaver.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/singleenumattributesaver.cpp
@@ -4,7 +4,6 @@
#include "iattributesavetarget.h"
#include <vespa/searchlib/util/bufferwriter.h>
-
using search::attribute::EntryRefVector;
using vespalib::GenerationHandler;
@@ -14,25 +13,20 @@ SingleValueEnumAttributeSaver::
SingleValueEnumAttributeSaver(GenerationHandler::Guard &&guard,
const attribute::AttributeHeader &header,
EntryRefVector &&indices,
- const IEnumStore &enumStore)
+ IEnumStore &enumStore)
: AttributeSaver(std::move(guard), header),
_indices(std::move(indices)),
_enumSaver(enumStore)
{
}
-
-SingleValueEnumAttributeSaver::~SingleValueEnumAttributeSaver()
-{
-}
-
+SingleValueEnumAttributeSaver::~SingleValueEnumAttributeSaver() = default;
bool
SingleValueEnumAttributeSaver::onSave(IAttributeSaveTarget &saveTarget)
{
_enumSaver.writeUdat(saveTarget);
- std::unique_ptr<search::BufferWriter> datWriter(saveTarget.datWriter().
- allocBufferWriter());
+ std::unique_ptr<search::BufferWriter> datWriter(saveTarget.datWriter().allocBufferWriter());
assert(saveTarget.getEnumerated());
auto &enumerator = _enumSaver.get_enumerator();
enumerator.enumerateValues();
@@ -49,5 +43,4 @@ SingleValueEnumAttributeSaver::onSave(IAttributeSaveTarget &saveTarget)
return true;
}
-
} // namespace search
diff --git a/searchlib/src/vespa/searchlib/attribute/singleenumattributesaver.h b/searchlib/src/vespa/searchlib/attribute/singleenumattributesaver.h
index af83d36cbbb..7f1c62c7720 100644
--- a/searchlib/src/vespa/searchlib/attribute/singleenumattributesaver.h
+++ b/searchlib/src/vespa/searchlib/attribute/singleenumattributesaver.h
@@ -22,7 +22,7 @@ public:
SingleValueEnumAttributeSaver(vespalib::GenerationHandler::Guard &&guard,
const attribute::AttributeHeader &header,
attribute::EntryRefVector &&indices,
- const IEnumStore &enumStore);
+ IEnumStore &enumStore);
~SingleValueEnumAttributeSaver() override;
};
diff --git a/vespalib/src/tests/datastore/array_store/array_store_test.cpp b/vespalib/src/tests/datastore/array_store/array_store_test.cpp
index 3ebe8fdba1a..97e1ddb985d 100644
--- a/vespalib/src/tests/datastore/array_store/array_store_test.cpp
+++ b/vespalib/src/tests/datastore/array_store/array_store_test.cpp
@@ -97,13 +97,13 @@ struct ArrayStoreTest : public TestT
uint32_t getBufferId(EntryRef ref) const {
return EntryRefType(ref).bufferId();
}
- void assertBufferState(EntryRef ref, const MemStats& expStats) const {
+ void assertBufferState(EntryRef ref, const MemStats& expStats) {
EXPECT_EQ(expStats._used, store.bufferState(ref).size());
EXPECT_EQ(expStats._hold, store.bufferState(ref).stats().hold_elems());
EXPECT_EQ(expStats._dead, store.bufferState(ref).stats().dead_elems());
}
- void assert_buffer_stats(EntryRef ref, const TestBufferStats& exp_stats) const {
- auto& state = store.bufferState(ref);
+ void assert_buffer_stats(EntryRef ref, const TestBufferStats& exp_stats) {
+ const auto& state = store.bufferState(ref);
EXPECT_EQ(exp_stats._used, state.size());
EXPECT_EQ(exp_stats._hold, state.stats().hold_elems());
EXPECT_EQ(exp_stats._dead, state.stats().dead_elems());
diff --git a/vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp b/vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp
index 64e0c1599bd..7d4451556c8 100644
--- a/vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp
+++ b/vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp
@@ -56,11 +56,11 @@ struct TestBase : public ::testing::Test {
uint32_t get_buffer_id(EntryRef ref) const {
return EntryRefType(ref).bufferId();
}
- const BufferState &buffer_state(EntryRef ref) const {
+ BufferState &buffer_state(EntryRef ref) {
return allocator.get_data_store().getBufferState(get_buffer_id(ref));
}
- void assert_buffer_state(EntryRef ref, const TestBufferStats expStats) const {
- const auto & stats = buffer_state(ref).stats();
+ void assert_buffer_state(EntryRef ref, const TestBufferStats expStats) {
+ auto & stats = buffer_state(ref).stats();
EXPECT_EQ(expStats._used, buffer_state(ref).size());
EXPECT_EQ(expStats._hold, stats.hold_elems());
EXPECT_EQ(expStats._dead, stats.dead_elems());
diff --git a/vespalib/src/vespa/vespalib/datastore/array_store.h b/vespalib/src/vespa/vespalib/datastore/array_store.h
index 43bd469fca4..dd786e5f2e2 100644
--- a/vespalib/src/vespa/vespalib/datastore/array_store.h
+++ b/vespalib/src/vespa/vespalib/datastore/array_store.h
@@ -139,7 +139,7 @@ public:
static DataStoreBase& get_data_store_base(ArrayStore &self) { return self._store; }
// Should only be used for unit testing
- const BufferState &bufferState(EntryRef ref) const;
+ const BufferState &bufferState(EntryRef ref);
bool has_free_lists_enabled() const { return _store.has_free_lists_enabled(); }
bool has_held_buffers() const noexcept { return _store.has_held_buffers(); }
diff --git a/vespalib/src/vespa/vespalib/datastore/array_store.hpp b/vespalib/src/vespa/vespalib/datastore/array_store.hpp
index 64aed0bd541..301cff1e414 100644
--- a/vespalib/src/vespa/vespalib/datastore/array_store.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/array_store.hpp
@@ -197,7 +197,7 @@ ArrayStore<EntryT, RefT, TypeMapperT>::update_stat(const CompactionStrategy& com
template <typename EntryT, typename RefT, typename TypeMapperT>
const BufferState &
-ArrayStore<EntryT, RefT, TypeMapperT>::bufferState(EntryRef ref) const
+ArrayStore<EntryT, RefT, TypeMapperT>::bufferState(EntryRef ref)
{
RefT internalRef(ref);
return _store.getBufferState(internalRef.bufferId());
diff --git a/vespalib/src/vespa/vespalib/datastore/datastorebase.h b/vespalib/src/vespa/vespalib/datastore/datastorebase.h
index 9efd91ef138..db91ce8d8cd 100644
--- a/vespalib/src/vespa/vespalib/datastore/datastorebase.h
+++ b/vespalib/src/vespa/vespalib/datastore/datastorebase.h
@@ -73,7 +73,6 @@ public:
* Get the primary buffer id for the given type id.
*/
uint32_t primary_buffer_id(uint32_t typeId) const { return _primary_buffer_ids[typeId]; }
- const BufferState &getBufferState(uint32_t bufferId) const { return _states[bufferId]; }
BufferState &getBufferState(uint32_t bufferId) { return _states[bufferId]; }
const BufferAndMeta & getBufferMeta(uint32_t bufferId) const { return _buffers[bufferId]; }
uint32_t getNumBuffers() const { return _numBuffers; }
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store.h b/vespalib/src/vespa/vespalib/datastore/unique_store.h
index 1313d57fbab..f2d62020ab4 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store.h
@@ -67,7 +67,8 @@ public:
Allocator& get_allocator() { return _allocator; }
const Allocator& get_allocator() const { return _allocator; }
IUniqueStoreDictionary& get_dictionary() { return *_dict; }
- inline const DataStoreType& get_data_store() const noexcept { return _allocator.get_data_store(); }
+ const DataStoreType& get_data_store() const noexcept { return _allocator.get_data_store(); }
+ DataStoreType& get_data_store() noexcept { return _allocator.get_data_store(); }
// Pass on hold list management to underlying store
void assign_generation(generation_t current_gen);
@@ -78,7 +79,7 @@ public:
uint32_t getNumUniques() const;
Builder getBuilder(uint32_t uniqueValuesHint);
- Enumerator getEnumerator(bool sort_unique_values) const;
+ Enumerator getEnumerator(bool sort_unique_values);
// Should only be used for unit testing
const BufferState &bufferState(EntryRef ref) const;
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store.hpp b/vespalib/src/vespa/vespalib/datastore/unique_store.hpp
index d9d5f9fee7f..aef6ea07290 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store.hpp
@@ -221,7 +221,7 @@ UniqueStore<EntryT, RefT, Compare, Allocator>::getBuilder(uint32_t uniqueValuesH
template <typename EntryT, typename RefT, typename Compare, typename Allocator>
typename UniqueStore<EntryT, RefT, Compare, Allocator>::Enumerator
-UniqueStore<EntryT, RefT, Compare, Allocator>::getEnumerator(bool sort_unique_values) const
+UniqueStore<EntryT, RefT, Compare, Allocator>::getEnumerator(bool sort_unique_values)
{
return Enumerator(*_dict, _store, sort_unique_values);
}
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.h b/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.h
index c4baff2206b..a6e7c2c974e 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.h
@@ -30,9 +30,9 @@ private:
EnumValues _enumValues;
uint32_t _next_enum_val;
- void allocate_enum_values();
+ void allocate_enum_values(DataStoreBase &store);
public:
- UniqueStoreEnumerator(const IUniqueStoreDictionary &dict, const DataStoreBase &store, bool sort_unique_values);
+ UniqueStoreEnumerator(const IUniqueStoreDictionary &dict, DataStoreBase &store, bool sort_unique_values);
~UniqueStoreEnumerator();
void enumerateValue(EntryRef ref);
void enumerateValues();
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.hpp b/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.hpp
index 52437fc765c..6d08a027bf1 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_enumerator.hpp
@@ -9,7 +9,7 @@
namespace vespalib::datastore {
template <typename RefT>
-UniqueStoreEnumerator<RefT>::UniqueStoreEnumerator(const IUniqueStoreDictionary &dict, const DataStoreBase &store, bool sort_unique_values)
+UniqueStoreEnumerator<RefT>::UniqueStoreEnumerator(const IUniqueStoreDictionary &dict, DataStoreBase &store, bool sort_unique_values)
: _dict_snapshot(dict.get_read_snapshot()),
_store(store),
_enumValues(),
@@ -19,7 +19,7 @@ UniqueStoreEnumerator<RefT>::UniqueStoreEnumerator(const IUniqueStoreDictionary
if (sort_unique_values) {
_dict_snapshot->sort();
}
- allocate_enum_values();
+ allocate_enum_values(store);
}
template <typename RefT>
@@ -40,11 +40,11 @@ UniqueStoreEnumerator<RefT>::enumerateValue(EntryRef ref)
template <typename RefT>
void
-UniqueStoreEnumerator<RefT>::allocate_enum_values()
+UniqueStoreEnumerator<RefT>::allocate_enum_values(DataStoreBase & store)
{
_enumValues.resize(RefType::numBuffers());
for (uint32_t bufferId = 0; bufferId < RefType::numBuffers(); ++bufferId) {
- const BufferState &state = _store.getBufferState(bufferId);
+ const BufferState &state = store.getBufferState(bufferId);
if (state.isActive()) {
_enumValues[bufferId].resize(state.get_used_arrays());
}