diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-03-09 11:56:45 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-03-09 11:57:14 +0100 |
commit | 5071797e7dd5b48eb0dc0716248294735b50dce1 (patch) | |
tree | 14b1f01ff727927bb817fc05831f9c7d21bd5459 /searchlib | |
parent | 44607b151b97c0483354ff83630db6829df0a5ba (diff) |
Use AtomicEntryRef in MultiValueMappingBase.
Diffstat (limited to 'searchlib')
4 files changed, 23 insertions, 10 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/multi_value_mapping.h b/searchlib/src/vespa/searchlib/attribute/multi_value_mapping.h index 60f2f3709ec..71f1191e507 100644 --- a/searchlib/src/vespa/searchlib/attribute/multi_value_mapping.h +++ b/searchlib/src/vespa/searchlib/attribute/multi_value_mapping.h @@ -31,13 +31,13 @@ public: const vespalib::GrowStrategy &gs, std::shared_ptr<vespalib::alloc::MemoryAllocator> memory_allocator); ~MultiValueMapping() override; - ConstArrayRef get(uint32_t docId) const { return _store.get(_indices[docId]); } + ConstArrayRef get(uint32_t docId) const { return _store.get(_indices[docId].load_acquire()); } ConstArrayRef getDataForIdx(EntryRef idx) const { return _store.get(idx); } void set(uint32_t docId, ConstArrayRef values); // get_writable is generally unsafe and should only be used when // compacting enum store (replacing old enum index with updated enum index) - ArrayRef get_writable(uint32_t docId) { return _store.get_writable(_indices[docId]); } + ArrayRef get_writable(uint32_t docId) { return _store.get_writable(_indices[docId].load_relaxed()); } // Pass on hold list management to underlying store void transferHoldLists(generation_t generation) { _store.transferHoldLists(generation); } diff --git a/searchlib/src/vespa/searchlib/attribute/multi_value_mapping.hpp b/searchlib/src/vespa/searchlib/attribute/multi_value_mapping.hpp index 4db50ebb5a6..87ffaa75ace 100644 --- a/searchlib/src/vespa/searchlib/attribute/multi_value_mapping.hpp +++ b/searchlib/src/vespa/searchlib/attribute/multi_value_mapping.hpp @@ -32,9 +32,9 @@ void MultiValueMapping<EntryT,RefT>::set(uint32_t docId, ConstArrayRef values) { _indices.ensure_size(docId + 1); - EntryRef oldRef(_indices[docId]); + EntryRef oldRef(_indices[docId].load_relaxed()); ConstArrayRef oldValues = _store.get(oldRef); - _indices[docId] = _store.add(values); + _indices[docId].store_release(_store.add(values)); updateValueCount(oldValues.size(), values.size()); _store.remove(oldRef); } @@ -45,7 +45,7 @@ MultiValueMapping<EntryT,RefT>::compactWorst(CompactionSpec compaction_spec, con { vespalib::datastore::ICompactionContext::UP compactionContext(_store.compactWorst(compaction_spec, compaction_strategy)); if (compactionContext) { - compactionContext->compact(vespalib::ArrayRef<EntryRef>(&_indices[0], _indices.size())); + compactionContext->compact(vespalib::ArrayRef<AtomicEntryRef>(&_indices[0], _indices.size())); } } diff --git a/searchlib/src/vespa/searchlib/attribute/multi_value_mapping_base.cpp b/searchlib/src/vespa/searchlib/attribute/multi_value_mapping_base.cpp index 7ad61ccedc5..11ea58bc124 100644 --- a/searchlib/src/vespa/searchlib/attribute/multi_value_mapping_base.cpp +++ b/searchlib/src/vespa/searchlib/attribute/multi_value_mapping_base.cpp @@ -3,6 +3,7 @@ #include "multi_value_mapping_base.h" #include <vespa/vespalib/datastore/compaction_spec.h> #include <vespa/vespalib/datastore/compaction_strategy.h> +#include <vespa/vespalib/util/array.hpp> #include <cassert> namespace search::attribute { @@ -24,14 +25,19 @@ MultiValueMappingBase::~MultiValueMappingBase() = default; MultiValueMappingBase::RefCopyVector MultiValueMappingBase::getRefCopy(uint32_t size) const { assert(size <= _indices.size()); - return RefCopyVector(&_indices[0], &_indices[0] + size); + RefCopyVector result; + result.reserve(size); + for (uint32_t lid = 0; lid < size; ++lid) { + result.push_back(_indices[lid].load_relaxed()); + } + return result; } void MultiValueMappingBase::addDoc(uint32_t & docId) { uint32_t retval = _indices.size(); - _indices.push_back(EntryRef()); + _indices.push_back(AtomicEntryRef()); docId = retval; } @@ -54,7 +60,7 @@ MultiValueMappingBase::clearDocs(uint32_t lidLow, uint32_t lidLimit, std::functi assert(lidLow <= lidLimit); assert(lidLimit <= _indices.size()); for (uint32_t lid = lidLow; lid < lidLimit; ++lid) { - if (_indices[lid].valid()) { + if (_indices[lid].load_relaxed().valid()) { clearDoc(lid); } } @@ -90,3 +96,9 @@ MultiValueMappingBase::considerCompact(const CompactionStrategy &compactionStrat } } + +namespace vespalib { + +template class Array<datastore::AtomicEntryRef>; + +} diff --git a/searchlib/src/vespa/searchlib/attribute/multi_value_mapping_base.h b/searchlib/src/vespa/searchlib/attribute/multi_value_mapping_base.h index 2b2b4d5f8a3..e4588c8e743 100644 --- a/searchlib/src/vespa/searchlib/attribute/multi_value_mapping_base.h +++ b/searchlib/src/vespa/searchlib/attribute/multi_value_mapping_base.h @@ -2,8 +2,8 @@ #pragma once +#include <vespa/vespalib/datastore/atomic_entry_ref.h> #include <vespa/vespalib/datastore/compaction_spec.h> -#include <vespa/vespalib/datastore/entryref.h> #include <vespa/vespalib/util/address_space.h> #include <vespa/vespalib/util/rcuvector.h> #include <functional> @@ -23,8 +23,9 @@ class MultiValueMappingBase public: using CompactionSpec = vespalib::datastore::CompactionSpec; using CompactionStrategy = vespalib::datastore::CompactionStrategy; + using AtomicEntryRef = vespalib::datastore::AtomicEntryRef; using EntryRef = vespalib::datastore::EntryRef; - using RefVector = vespalib::RcuVectorBase<EntryRef>; + using RefVector = vespalib::RcuVectorBase<AtomicEntryRef>; protected: std::shared_ptr<vespalib::alloc::MemoryAllocator> _memory_allocator; |