// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include #include #include #include #include namespace vespalib { class nbostream; } namespace vespalib::datastore { struct ICompactionContext; } namespace vespalib::eval { struct Value; } namespace search::tensor { /** * Class for storing serialized tensors in memory, used by TensorAttribute. * * Serialization format is subject to change. Changes to serialization format * might also require corresponding changes to implemented optimized tensor * operations that use the serialized tensor as argument. */ class TensorStore : public vespalib::datastore::ICompactable { public: using EntryRef = vespalib::datastore::EntryRef; typedef vespalib::GenerationHandler::generation_t generation_t; protected: vespalib::datastore::DataStoreBase& _store; vespalib::datastore::CompactionSpec _compaction_spec; public: TensorStore(vespalib::datastore::DataStoreBase &store); virtual ~TensorStore(); virtual void holdTensor(EntryRef ref) = 0; virtual vespalib::MemoryUsage update_stat(const vespalib::datastore::CompactionStrategy& compaction_strategy) = 0; virtual std::unique_ptr start_compact(const vespalib::datastore::CompactionStrategy& compaction_strategy) = 0; virtual EntryRef store_tensor(const vespalib::eval::Value& tensor) = 0; virtual EntryRef store_encoded_tensor(vespalib::nbostream& encoded) = 0; virtual std::unique_ptr get_tensor(EntryRef ref) const = 0; virtual bool encode_stored_tensor(EntryRef ref, vespalib::nbostream& target) const = 0; // Inherit doc from DataStoreBase void trimHoldLists(generation_t usedGen) { _store.trimHoldLists(usedGen); } // Inherit doc from DataStoreBase void transferHoldLists(generation_t generation) { _store.transferHoldLists(generation); } void clearHoldLists() { _store.clearHoldLists(); } vespalib::MemoryUsage getMemoryUsage() const { return _store.getMemoryUsage(); } vespalib::AddressSpace get_address_space_usage() const { return _store.getAddressSpaceUsage(); } bool consider_compact() const noexcept { return _compaction_spec.compact() && !_store.has_held_buffers(); } }; }