diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-10-06 00:48:45 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-10-06 00:48:45 +0200 |
commit | e3e76af788dd5a0c8cbad64cebbe60656ac4075b (patch) | |
tree | 9c25b7eb1f09a9a3423838e1f5270caa8e42553f /searchlib/src/vespa | |
parent | b61e190f896f217f54a71e14b33b0589b8d87a32 (diff) |
Use vespalib::datastore::CompactionContext when compacting tensor attributes.
Diffstat (limited to 'searchlib/src/vespa')
19 files changed, 123 insertions, 82 deletions
diff --git a/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp index c713b3ef335..d4353532309 100644 --- a/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp +++ b/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp @@ -5,7 +5,6 @@ #include "nearest_neighbor_index.h" #include "nearest_neighbor_index_loader.h" #include "nearest_neighbor_index_saver.h" -#include "tensor_attribute.hpp" #include <vespa/eval/eval/value.h> #include <vespa/fastlib/io/bufferedfile.h> #include <vespa/searchcommon/attribute/config.h> @@ -435,12 +434,6 @@ DenseTensorAttribute::onInitSave(vespalib::stringref fileName) std::move(index_saver)); } -void -DenseTensorAttribute::compactWorst() -{ - doCompactWorst<DenseTensorStore::RefType>(); -} - uint32_t DenseTensorAttribute::getVersion() const { diff --git a/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.h b/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.h index 1138a4f4433..b0991aa57aa 100644 --- a/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.h +++ b/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.h @@ -45,7 +45,6 @@ public: bool supports_extract_cells_ref() const override { return true; } bool onLoad(vespalib::Executor *executor) override; std::unique_ptr<AttributeSaver> onInitSave(vespalib::stringref fileName) override; - void compactWorst() override; uint32_t getVersion() const override; void onCommit() override; void onGenerationChange(generation_t next_gen) override; diff --git a/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.cpp b/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.cpp index 6435ba6f27c..7e001cef3c6 100644 --- a/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.cpp +++ b/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.cpp @@ -2,10 +2,17 @@ #include "dense_tensor_store.h" #include <vespa/eval/eval/value.h> +#include <vespa/vespalib/datastore/compacting_buffers.h> +#include <vespa/vespalib/datastore/compaction_context.h> +#include <vespa/vespalib/datastore/compaction_strategy.h> #include <vespa/vespalib/datastore/datastore.hpp> #include <vespa/vespalib/util/memory_allocator.h> +using vespalib::datastore::CompactionContext; +using vespalib::datastore::CompactionSpec; +using vespalib::datastore::CompactionStrategy; using vespalib::datastore::Handle; +using vespalib::datastore::ICompactionContext; using vespalib::eval::CellType; using vespalib::eval::CellTypeUtils; using vespalib::eval::Value; @@ -98,7 +105,7 @@ DenseTensorStore::allocRawBuffer() { size_t bufSize = getBufSize(); size_t alignedBufSize = _tensorSizeCalc.alignedSize(); - auto result = _concreteStore.freeListRawAllocator<char>(_typeId).alloc(alignedBufSize); + auto result = _concreteStore.freeListRawAllocator<char>(0u).alloc(alignedBufSize); clearPadAreaAfterBuffer(result.data, bufSize, alignedBufSize); return result; } @@ -125,6 +132,21 @@ DenseTensorStore::move(EntryRef ref) return newraw.ref; } +vespalib::MemoryUsage +DenseTensorStore::update_stat(const CompactionStrategy& compaction_strategy) +{ + auto array_store_memory_usage = _store.getMemoryUsage(); + _compaction_spec = CompactionSpec(compaction_strategy.should_compact_memory(array_store_memory_usage), false); + return array_store_memory_usage; +} + +std::unique_ptr<ICompactionContext> +DenseTensorStore::start_compact(const CompactionStrategy& compaction_strategy) +{ + auto compacting_buffers = _store.start_compact_worst_buffers(_compaction_spec, compaction_strategy); + return std::make_unique<CompactionContext>(*this, std::move(compacting_buffers)); +} + std::unique_ptr<Value> DenseTensorStore::getTensor(EntryRef ref) const { diff --git a/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.h b/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.h index 7176edbcf08..bd83772ee55 100644 --- a/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.h +++ b/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.h @@ -5,6 +5,7 @@ #include "tensor_store.h" #include <vespa/eval/eval/value_type.h> #include <vespa/eval/eval/typed_cells.h> +#include <vespa/vespalib/datastore/datastore.h> namespace vespalib::eval { struct Value; } @@ -67,6 +68,8 @@ public: vespalib::datastore::Handle<char> allocRawBuffer(); void holdTensor(EntryRef ref) override; EntryRef move(EntryRef ref) override; + vespalib::MemoryUsage update_stat(const vespalib::datastore::CompactionStrategy& compaction_strategy) override; + std::unique_ptr<vespalib::datastore::ICompactionContext> start_compact(const vespalib::datastore::CompactionStrategy& compaction_strategy) override; std::unique_ptr<vespalib::eval::Value> getTensor(EntryRef ref) const; vespalib::eval::TypedCells get_typed_cells(EntryRef ref) const { return vespalib::eval::TypedCells(ref.valid() ? getRawBuffer(ref) : &_emptySpace[0], diff --git a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp index 9085ff6bb00..e2271e63425 100644 --- a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp +++ b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp @@ -11,7 +11,6 @@ #include "blob_sequence_reader.h" #include "tensor_deserialize.h" -#include "tensor_attribute.hpp" using vespalib::eval::FastValueBuilderFactory; @@ -141,10 +140,4 @@ DirectTensorAttribute::onInitSave(vespalib::stringref fileName) _direct_store); } -void -DirectTensorAttribute::compactWorst() -{ - doCompactWorst<DirectTensorStore::RefType>(); -} - } // namespace diff --git a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.h b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.h index 931fb969978..2dfb5c1efcd 100644 --- a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.h +++ b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.h @@ -23,8 +23,6 @@ public: std::unique_ptr<vespalib::eval::Value> getTensor(DocId docId) const override; bool onLoad(vespalib::Executor *executor) override; std::unique_ptr<AttributeSaver> onInitSave(vespalib::stringref fileName) override; - void compactWorst() override; - void set_tensor(DocId docId, std::unique_ptr<vespalib::eval::Value> tensor); const vespalib::eval::Value &get_tensor_ref(DocId docId) const override; bool supports_get_tensor_ref() const override { return true; } diff --git a/searchlib/src/vespa/searchlib/tensor/direct_tensor_store.cpp b/searchlib/src/vespa/searchlib/tensor/direct_tensor_store.cpp index e6084c9cde4..3ca7722e6ca 100644 --- a/searchlib/src/vespa/searchlib/tensor/direct_tensor_store.cpp +++ b/searchlib/src/vespa/searchlib/tensor/direct_tensor_store.cpp @@ -2,11 +2,18 @@ #include "direct_tensor_store.h" #include <vespa/eval/eval/value.h> +#include <vespa/vespalib/datastore/compacting_buffers.h> +#include <vespa/vespalib/datastore/compaction_context.h> +#include <vespa/vespalib/datastore/compaction_strategy.h> #include <vespa/vespalib/datastore/datastore.hpp> #include <vespa/vespalib/datastore/buffer_type.hpp> #include <vespa/vespalib/util/size_literals.h> +using vespalib::datastore::CompactionContext; +using vespalib::datastore::CompactionSpec; +using vespalib::datastore::CompactionStrategy; using vespalib::datastore::EntryRef; +using vespalib::datastore::ICompactionContext; namespace search::tensor { @@ -78,4 +85,19 @@ DirectTensorStore::move(EntryRef ref) return new_ref; } +vespalib::MemoryUsage +DirectTensorStore::update_stat(const CompactionStrategy& compaction_strategy) +{ + auto array_store_memory_usage = _store.getMemoryUsage(); + _compaction_spec = CompactionSpec(compaction_strategy.should_compact_memory(array_store_memory_usage), false); + return array_store_memory_usage; +} + +std::unique_ptr<ICompactionContext> +DirectTensorStore::start_compact(const CompactionStrategy& compaction_strategy) +{ + auto compacting_buffers = _store.start_compact_worst_buffers(_compaction_spec, compaction_strategy); + return std::make_unique<CompactionContext>(*this, std::move(compacting_buffers)); +} + } diff --git a/searchlib/src/vespa/searchlib/tensor/direct_tensor_store.h b/searchlib/src/vespa/searchlib/tensor/direct_tensor_store.h index 587ded2209c..57e7453ff99 100644 --- a/searchlib/src/vespa/searchlib/tensor/direct_tensor_store.h +++ b/searchlib/src/vespa/searchlib/tensor/direct_tensor_store.h @@ -3,6 +3,7 @@ #pragma once #include "tensor_store.h" +#include <vespa/vespalib/datastore/datastore.h> namespace vespalib::eval { struct Value; } @@ -49,6 +50,8 @@ public: void holdTensor(EntryRef ref) override; EntryRef move(EntryRef ref) override; + vespalib::MemoryUsage update_stat(const vespalib::datastore::CompactionStrategy& compaction_strategy) override; + std::unique_ptr<vespalib::datastore::ICompactionContext> start_compact(const vespalib::datastore::CompactionStrategy& compaction_strategy) override; }; } diff --git a/searchlib/src/vespa/searchlib/tensor/serialized_fast_value_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/serialized_fast_value_attribute.cpp index 3e9f41c812c..7229fbed752 100644 --- a/searchlib/src/vespa/searchlib/tensor/serialized_fast_value_attribute.cpp +++ b/searchlib/src/vespa/searchlib/tensor/serialized_fast_value_attribute.cpp @@ -11,7 +11,6 @@ LOG_SETUP(".searchlib.tensor.serialized_fast_value_attribute"); #include "blob_sequence_reader.h" -#include "tensor_attribute.hpp" using namespace vespalib; using namespace vespalib::eval; @@ -97,10 +96,4 @@ SerializedFastValueAttribute::onInitSave(vespalib::stringref fileName) _streamedValueStore); } -void -SerializedFastValueAttribute::compactWorst() -{ - doCompactWorst<StreamedValueStore::RefType>(); -} - } diff --git a/searchlib/src/vespa/searchlib/tensor/serialized_fast_value_attribute.h b/searchlib/src/vespa/searchlib/tensor/serialized_fast_value_attribute.h index e37076fe299..0ef644813ee 100644 --- a/searchlib/src/vespa/searchlib/tensor/serialized_fast_value_attribute.h +++ b/searchlib/src/vespa/searchlib/tensor/serialized_fast_value_attribute.h @@ -26,7 +26,6 @@ public: std::unique_ptr<vespalib::eval::Value> getTensor(DocId docId) const override; bool onLoad(vespalib::Executor *executor) override; std::unique_ptr<AttributeSaver> onInitSave(vespalib::stringref fileName) override; - void compactWorst() override; }; } diff --git a/searchlib/src/vespa/searchlib/tensor/streamed_value_store.cpp b/searchlib/src/vespa/searchlib/tensor/streamed_value_store.cpp index 763486f82e2..ffaac493053 100644 --- a/searchlib/src/vespa/searchlib/tensor/streamed_value_store.cpp +++ b/searchlib/src/vespa/searchlib/tensor/streamed_value_store.cpp @@ -7,6 +7,9 @@ #include <vespa/eval/streamed/streamed_value_builder_factory.h> #include <vespa/eval/streamed/streamed_value_view.h> #include <vespa/vespalib/datastore/buffer_type.hpp> +#include <vespa/vespalib/datastore/compacting_buffers.h> +#include <vespa/vespalib/datastore/compaction_context.h> +#include <vespa/vespalib/datastore/compaction_strategy.h> #include <vespa/vespalib/datastore/datastore.hpp> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/size_literals.h> @@ -15,8 +18,12 @@ LOG_SETUP(".searchlib.tensor.streamed_value_store"); -using vespalib::datastore::Handle; +using vespalib::datastore::CompactionContext; +using vespalib::datastore::CompactionSpec; +using vespalib::datastore::CompactionStrategy; using vespalib::datastore::EntryRef; +using vespalib::datastore::Handle; +using vespalib::datastore::ICompactionContext; using namespace vespalib::eval; using vespalib::ConstArrayRef; using vespalib::MemoryUsage; @@ -237,6 +244,21 @@ StreamedValueStore::move(EntryRef ref) return new_ref; } +vespalib::MemoryUsage +StreamedValueStore::update_stat(const CompactionStrategy& compaction_strategy) +{ + auto array_store_memory_usage = _store.getMemoryUsage(); + _compaction_spec = CompactionSpec(compaction_strategy.should_compact_memory(array_store_memory_usage), false); + return array_store_memory_usage; +} + +std::unique_ptr<ICompactionContext> +StreamedValueStore::start_compact(const CompactionStrategy& compaction_strategy) +{ + auto compacting_buffers = _store.start_compact_worst_buffers(_compaction_spec, compaction_strategy); + return std::make_unique<CompactionContext>(*this, std::move(compacting_buffers)); +} + bool StreamedValueStore::encode_stored_tensor(EntryRef ref, vespalib::nbostream &target) const { diff --git a/searchlib/src/vespa/searchlib/tensor/streamed_value_store.h b/searchlib/src/vespa/searchlib/tensor/streamed_value_store.h index 9c5c5a91d18..58137e316dd 100644 --- a/searchlib/src/vespa/searchlib/tensor/streamed_value_store.h +++ b/searchlib/src/vespa/searchlib/tensor/streamed_value_store.h @@ -6,6 +6,7 @@ #include <vespa/eval/eval/value_type.h> #include <vespa/eval/eval/value.h> #include <vespa/eval/streamed/streamed_value.h> +#include <vespa/vespalib/datastore/datastore.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/shared_string_repo.h> @@ -69,6 +70,8 @@ public: void holdTensor(EntryRef ref) override; EntryRef move(EntryRef ref) override; + vespalib::MemoryUsage update_stat(const vespalib::datastore::CompactionStrategy& compaction_strategy) override; + std::unique_ptr<vespalib::datastore::ICompactionContext> start_compact(const vespalib::datastore::CompactionStrategy& compaction_strategy) override; std::unique_ptr<vespalib::eval::Value> get_tensor(EntryRef ref) const; bool encode_stored_tensor(EntryRef ref, vespalib::nbostream &target) const; diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp index 78c58e86a3b..cdaea07176a 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp +++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp @@ -8,6 +8,7 @@ #include <vespa/searchcommon/attribute/config.h> #include <vespa/vespalib/data/slime/cursor.h> #include <vespa/vespalib/data/slime/inserter.h> +#include <vespa/vespalib/datastore/i_compaction_context.h> #include <vespa/vespalib/util/shared_string_repo.h> #include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/value_codec.h> @@ -53,8 +54,7 @@ TensorAttribute::TensorAttribute(vespalib::stringref name, const Config &cfg, Te _tensorStore(tensorStore), _is_dense(cfg.tensorType().is_dense()), _emptyTensor(createEmptyTensor(cfg.tensorType())), - _compactGeneration(0), - _cached_tensor_store_memory_usage() + _compactGeneration(0) { } @@ -84,11 +84,14 @@ TensorAttribute::onCommit() { // Note: Cost can be reduced if unneeded generation increments are dropped incGeneration(); - if (getFirstUsedGeneration() > _compactGeneration) { - // No data held from previous compact operation - if (getConfig().getCompactionStrategy().should_compact_memory(_cached_tensor_store_memory_usage)) { - compactWorst(); + if (_tensorStore.consider_compact()) { + auto context = _tensorStore.start_compact(getConfig().getCompactionStrategy()); + if (context) { + context->compact(vespalib::ArrayRef<AtomicEntryRef>(&_refVector[0], _refVector.size())); } + _compactGeneration = getCurrentGeneration(); + incGeneration(); + updateStat(true); } } @@ -163,8 +166,7 @@ vespalib::MemoryUsage TensorAttribute::update_stat() { vespalib::MemoryUsage result = _refVector.getMemoryUsage(); - _cached_tensor_store_memory_usage = _tensorStore.getMemoryUsage(); - result.merge(_cached_tensor_store_memory_usage); + result.merge(_tensorStore.update_stat(getConfig().getCompactionStrategy())); result.mergeGenerationHeldBytes(getGenerationHolder().getHeldBytes()); return result; } diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h index c8aa42c6133..411efcd8fea 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h +++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h @@ -28,10 +28,7 @@ protected: bool _is_dense; std::unique_ptr<vespalib::eval::Value> _emptyTensor; uint64_t _compactGeneration; // Generation when last compact occurred - vespalib::MemoryUsage _cached_tensor_store_memory_usage; - template <typename RefType> - void doCompactWorst(); void checkTensorType(const vespalib::eval::Value &tensor) const; void setTensorRef(DocId docId, EntryRef ref); virtual vespalib::MemoryUsage update_stat(); @@ -86,7 +83,6 @@ public: */ virtual void complete_set_tensor(DocId docid, const vespalib::eval::Value& tensor, std::unique_ptr<PrepareResult> prepare_result); - virtual void compactWorst() = 0; }; } diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.hpp b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.hpp deleted file mode 100644 index 749b0429975..00000000000 --- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -namespace search { - -namespace tensor { - -template <typename RefType> -void -TensorAttribute::doCompactWorst() -{ - uint32_t bufferId = _tensorStore.startCompactWorstBuffer(); - size_t lidLimit = _refVector.size(); - for (uint32_t lid = 0; lid < lidLimit; ++lid) { - RefType ref = _refVector[lid].load_relaxed(); - (void) ref; - if (ref.valid() && ref.bufferId() == bufferId) { - RefType newRef = _tensorStore.move(ref); - _refVector[lid].store_release(newRef); - } - } - _tensorStore.finishCompactWorstBuffer(bufferId); - _compactGeneration = getCurrentGeneration(); - incGeneration(); - updateStat(true); -} - -} // namespace search::tensor - -} // namespace search diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_buffer_store.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_buffer_store.cpp index 34454e9f780..eff6ac9f374 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_buffer_store.cpp +++ b/searchlib/src/vespa/searchlib/tensor/tensor_buffer_store.cpp @@ -5,10 +5,14 @@ #include <vespa/eval/streamed/streamed_value_builder_factory.h> #include <vespa/vespalib/datastore/array_store.hpp> #include <vespa/vespalib/datastore/buffer_type.hpp> +#include <vespa/vespalib/datastore/compaction_context.h> +#include <vespa/vespalib/datastore/compaction_strategy.h> #include <vespa/vespalib/datastore/datastore.hpp> #include <vespa/vespalib/util/size_literals.h> using vespalib::alloc::MemoryAllocator; +using vespalib::datastore::CompactionContext; +using vespalib::datastore::CompactionStrategy; using vespalib::datastore::EntryRef; using vespalib::eval::StreamedValueBuilderFactory; using vespalib::eval::Value; @@ -54,6 +58,22 @@ TensorBufferStore::move(EntryRef ref) return new_ref; } +vespalib::MemoryUsage +TensorBufferStore::update_stat(const CompactionStrategy& compaction_strategy) +{ + auto array_store_address_space_usage = _store.getAddressSpaceUsage(); + auto array_store_memory_usage = _store.getMemoryUsage(); + _compaction_spec = compaction_strategy.should_compact(array_store_memory_usage, array_store_address_space_usage); + return array_store_memory_usage; +} + +std::unique_ptr<vespalib::datastore::ICompactionContext> +TensorBufferStore::start_compact(const CompactionStrategy& compaction_strategy) +{ + auto compacting_buffers = _store.start_compact_worst_buffers(_compaction_spec, compaction_strategy); + return std::make_unique<CompactionContext>(*this, std::move(compacting_buffers)); +} + EntryRef TensorBufferStore::store_tensor(const Value &tensor) { diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_buffer_store.h b/searchlib/src/vespa/searchlib/tensor/tensor_buffer_store.h index 18b98efa8fa..585bbd7a0c3 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_buffer_store.h +++ b/searchlib/src/vespa/searchlib/tensor/tensor_buffer_store.h @@ -28,6 +28,8 @@ public: ~TensorBufferStore(); void holdTensor(EntryRef ref) override; EntryRef move(EntryRef ref) override; + vespalib::MemoryUsage update_stat(const vespalib::datastore::CompactionStrategy& compaction_strategy) override; + std::unique_ptr<vespalib::datastore::ICompactionContext> start_compact(const vespalib::datastore::CompactionStrategy& compaction_strategy) override; EntryRef store_tensor(const vespalib::eval::Value &tensor); EntryRef store_encoded_tensor(vespalib::nbostream &encoded); std::unique_ptr<vespalib::eval::Value> get_tensor(EntryRef ref) const; diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_store.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_store.cpp index 8356c1c8bb7..fc8f3175f99 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_store.cpp +++ b/searchlib/src/vespa/searchlib/tensor/tensor_store.cpp @@ -6,7 +6,7 @@ namespace search::tensor { TensorStore::TensorStore(vespalib::datastore::DataStoreBase &store) : _store(store), - _typeId(0) + _compaction_spec() { } TensorStore::~TensorStore() = default; diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_store.h b/searchlib/src/vespa/searchlib/tensor/tensor_store.h index 3c9146607d0..90bc82c4fde 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_store.h +++ b/searchlib/src/vespa/searchlib/tensor/tensor_store.h @@ -2,10 +2,13 @@ #pragma once +#include <vespa/vespalib/datastore/compaction_spec.h> +#include <vespa/vespalib/datastore/datastorebase.h> #include <vespa/vespalib/datastore/entryref.h> -#include <vespa/vespalib/datastore/datastore.h> +#include <vespa/vespalib/datastore/i_compactable.h> #include <vespa/vespalib/util/generationhandler.h> +namespace vespalib::datastore { struct ICompactionContext; } namespace vespalib::eval { struct Value; } namespace search::tensor { @@ -17,15 +20,15 @@ namespace search::tensor { * might also require corresponding changes to implemented optimized tensor * operations that use the serialized tensor as argument. */ -class TensorStore +class TensorStore : public vespalib::datastore::ICompactable { public: using EntryRef = vespalib::datastore::EntryRef; typedef vespalib::GenerationHandler::generation_t generation_t; protected: - vespalib::datastore::DataStoreBase &_store; - const uint32_t _typeId; + vespalib::datastore::DataStoreBase& _store; + vespalib::datastore::CompactionSpec _compaction_spec; public: TensorStore(vespalib::datastore::DataStoreBase &store); @@ -33,7 +36,10 @@ public: virtual ~TensorStore(); virtual void holdTensor(EntryRef ref) = 0; - virtual EntryRef move(EntryRef ref) = 0; + + virtual vespalib::MemoryUsage update_stat(const vespalib::datastore::CompactionStrategy& compaction_strategy) = 0; + + virtual std::unique_ptr<vespalib::datastore::ICompactionContext> start_compact(const vespalib::datastore::CompactionStrategy& compaction_strategy) = 0; // Inherit doc from DataStoreBase void trimHoldLists(generation_t usedGen) { @@ -57,12 +63,8 @@ public: return _store.getAddressSpaceUsage(); } - uint32_t startCompactWorstBuffer() { - return _store.startCompactWorstBuffer(_typeId); - } - - void finishCompactWorstBuffer(uint32_t bufferId) { - _store.holdBuffer(bufferId); + bool consider_compact() const noexcept { + return _compaction_spec.compact() && !_store.has_held_buffers(); } }; |