diff options
15 files changed, 68 insertions, 53 deletions
diff --git a/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp b/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp index 8dc2551d96b..c9f3a1c1de8 100644 --- a/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp +++ b/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp @@ -11,6 +11,7 @@ #include <vespa/searchcore/proton/bucketdb/bucket_db_owner.h> #include <vespa/searchcore/proton/common/hw_info.h> #include <vespa/searchcore/proton/documentmetastore/documentmetastorecontext.h> +#include <vespa/searchcore/proton/documentmetastore/documentmetastore.h> #include <vespa/searchcore/proton/flushengine/shrink_lid_space_flush_target.h> #include <vespa/searchcore/proton/initializer/initializer_task.h> #include <vespa/searchcore/proton/initializer/task_runner.h> @@ -240,7 +241,7 @@ struct ParallelAttributeManager { InitializerTask::SP documentMetaStoreInitTask; std::shared_ptr<bucketdb::BucketDBOwner> bucketDbOwner; - DocumentMetaStore::SP documentMetaStore; + std::shared_ptr<DocumentMetaStore> documentMetaStore; AllocStrategy alloc_strategy; bool fastAccessAttributesOnly; std::shared_ptr<AttributeManager::SP> mgr; diff --git a/searchcore/src/tests/proton/server/documentretriever_test.cpp b/searchcore/src/tests/proton/server/documentretriever_test.cpp index 2e217a3f6a8..8185f8a30be 100644 --- a/searchcore/src/tests/proton/server/documentretriever_test.cpp +++ b/searchcore/src/tests/proton/server/documentretriever_test.cpp @@ -101,6 +101,7 @@ using vespalib::eval::SimpleValue; using vespalib::eval::TensorSpec; using vespalib::eval::ValueType; using vespalib::eval::Value; +using proton::documentmetastore::IStore; using namespace document::config_builder; using namespace search::index; @@ -296,7 +297,7 @@ struct Fixture { const GlobalId &gid; BucketId bucket_id; Timestamp timestamp; - DocumentMetaStore::DocId lid; + IStore::DocId lid; MyDocumentStore doc_store; search::AttributeManager attr_manager; Schema schema; @@ -365,11 +366,10 @@ struct Fixture { _dtName(doc_type_name), _retriever() { - using Result = DocumentMetaStore::Result; meta_store.constructFreeList(); - Result inspect = meta_store.get().inspect(gid, 0u); + IStore::Result inspect = meta_store.get().inspect(gid, 0u); uint32_t docSize = 1; - Result putRes(meta_store.get().put(gid, bucket_id, timestamp, docSize, inspect.getLid(), 0u)); + IStore::Result putRes(meta_store.get().put(gid, bucket_id, timestamp, docSize, inspect.getLid(), 0u)); meta_store.get().commit(search::CommitParam(0)); lid = putRes.getLid(); ASSERT_TRUE(putRes.ok()); diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_initializer.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_initializer.cpp index 77cc1142f75..320e3f06d53 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_initializer.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_initializer.cpp @@ -3,6 +3,7 @@ #include "attribute_manager_initializer.h" #include "attributes_initializer_base.h" #include "attribute_collection_spec_factory.h" +#include <vespa/searchcore/proton/documentmetastore/documentmetastoreattribute.h> #include <vespa/searchcorespi/index/i_thread_service.h> #include <future> @@ -22,12 +23,12 @@ class AttributeInitializerTask : public InitializerTask { private: AttributeInitializer::UP _initializer; - DocumentMetaStore::SP _documentMetaStore; + std::shared_ptr<DocumentMetaStoreAttribute> _documentMetaStore; InitializedAttributesResult &_result; public: AttributeInitializerTask(AttributeInitializer::UP initializer, - DocumentMetaStore::SP documentMetaStore, + std::shared_ptr<DocumentMetaStoreAttribute> documentMetaStore, InitializedAttributesResult &result) : _initializer(std::move(initializer)), _documentMetaStore(std::move(documentMetaStore)), @@ -52,14 +53,14 @@ class AttributeManagerInitializerTask : public vespalib::Executor::Task { std::promise<void> _promise; search::SerialNum _configSerialNum; - DocumentMetaStore::SP _documentMetaStore; + std::shared_ptr<DocumentMetaStoreAttribute> _documentMetaStore; AttributeManager::SP _attrMgr; InitializedAttributesResult &_attributesResult; public: AttributeManagerInitializerTask(std::promise<void> &&promise, search::SerialNum configSerialNum, - DocumentMetaStore::SP documentMetaStore, + std::shared_ptr<DocumentMetaStoreAttribute> documentMetaStore, AttributeManager::SP attrMgr, InitializedAttributesResult &attributesResult); ~AttributeManagerInitializerTask() override; @@ -69,7 +70,7 @@ public: AttributeManagerInitializerTask::AttributeManagerInitializerTask(std::promise<void> &&promise, search::SerialNum configSerialNum, - DocumentMetaStore::SP documentMetaStore, + std::shared_ptr<DocumentMetaStoreAttribute> documentMetaStore, AttributeManager::SP attrMgr, InitializedAttributesResult &attributesResult) : _promise(std::move(promise)), @@ -96,13 +97,13 @@ class AttributeInitializerTasksBuilder : public IAttributeInitializerRegistry private: InitializerTask &_attrMgrInitTask; InitializerTask::SP _documentMetaStoreInitTask; - DocumentMetaStore::SP _documentMetaStore; + std::shared_ptr<DocumentMetaStoreAttribute> _documentMetaStore; InitializedAttributesResult &_attributesResult; public: AttributeInitializerTasksBuilder(InitializerTask &attrMgrInitTask, InitializerTask::SP documentMetaStoreInitTask, - DocumentMetaStore::SP documentMetaStore, + std::shared_ptr<DocumentMetaStoreAttribute> documentMetaStore, InitializedAttributesResult &attributesResult); ~AttributeInitializerTasksBuilder() override; void add(AttributeInitializer::UP initializer) override; @@ -110,7 +111,7 @@ public: AttributeInitializerTasksBuilder::AttributeInitializerTasksBuilder(InitializerTask &attrMgrInitTask, InitializerTask::SP documentMetaStoreInitTask, - DocumentMetaStore::SP documentMetaStore, + std::shared_ptr<DocumentMetaStoreAttribute> documentMetaStore, InitializedAttributesResult &attributesResult) : _attrMgrInitTask(attrMgrInitTask), _documentMetaStoreInitTask(std::move(documentMetaStoreInitTask)), @@ -142,7 +143,7 @@ AttributeManagerInitializer::createAttributeSpec() const AttributeManagerInitializer::AttributeManagerInitializer(SerialNum configSerialNum, initializer::InitializerTask::SP documentMetaStoreInitTask, - DocumentMetaStore::SP documentMetaStore, + std::shared_ptr<DocumentMetaStoreAttribute> documentMetaStore, const AttributeManager & baseAttrMgr, const AttributesConfig &attrCfg, const AllocStrategy& alloc_strategy, diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_initializer.h b/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_initializer.h index 79203696ea1..a3a91b0d2e8 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_initializer.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_initializer.h @@ -4,7 +4,6 @@ #include "attributemanager.h" #include "initialized_attributes_result.h" -#include <vespa/searchcore/proton/documentmetastore/documentmetastore.h> #include <vespa/searchcore/proton/initializer/initializer_task.h> #include <vespa/searchcore/proton/common/alloc_strategy.h> #include <vespa/searchlib/common/serialnum.h> @@ -14,6 +13,8 @@ namespace searchcorespi::index { struct IThreadService; } namespace proton { +class DocumentMetaStoreAttribute; + /** * Class used to initialize an attribute manager. */ @@ -21,7 +22,7 @@ class AttributeManagerInitializer : public initializer::InitializerTask { private: search::SerialNum _configSerialNum; - DocumentMetaStore::SP _documentMetaStore; + std::shared_ptr<DocumentMetaStoreAttribute> _documentMetaStore; AttributeManager::SP _attrMgr; vespa::config::search::AttributesConfig _attrCfg; AllocStrategy _alloc_strategy; @@ -35,7 +36,7 @@ private: public: AttributeManagerInitializer(search::SerialNum configSerialNum, initializer::InitializerTask::SP documentMetaStoreInitTask, - DocumentMetaStore::SP documentMetaStore, + std::shared_ptr<DocumentMetaStoreAttribute> documentMetaStore, const AttributeManager & baseAttrMgr, const vespa::config::search::AttributesConfig &attrCfg, const AllocStrategy& alloc_strategy, diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/document_meta_store_initializer_result.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/document_meta_store_initializer_result.cpp index 16251ec7abf..8db8f00ed30 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/document_meta_store_initializer_result.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/document_meta_store_initializer_result.cpp @@ -5,18 +5,14 @@ namespace proton { DocumentMetaStoreInitializerResult:: -DocumentMetaStoreInitializerResult(DocumentMetaStore::SP - documentMetaStore_in, - const search::TuneFileAttributes & - tuneFile_in) - : _documentMetaStore(documentMetaStore_in), +DocumentMetaStoreInitializerResult(std::shared_ptr<DocumentMetaStore> documentMetaStore_in, + const search::TuneFileAttributes & tuneFile_in) + : _documentMetaStore(std::move(documentMetaStore_in)), _tuneFile(tuneFile_in) { } -DocumentMetaStoreInitializerResult::~DocumentMetaStoreInitializerResult() -{ -} +DocumentMetaStoreInitializerResult::~DocumentMetaStoreInitializerResult() = default; } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/document_meta_store_initializer_result.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/document_meta_store_initializer_result.h index 22d59e0f8cd..5d43d2925cf 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/document_meta_store_initializer_result.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/document_meta_store_initializer_result.h @@ -2,11 +2,11 @@ #pragma once -#include "documentmetastore.h" #include <vespa/searchlib/common/tunefileinfo.h> namespace proton { +class DocumentMetaStore; /** * The result after initializing document meta store component in a @@ -15,20 +15,18 @@ namespace proton { class DocumentMetaStoreInitializerResult { private: - DocumentMetaStore::SP _documentMetaStore; + std::shared_ptr<DocumentMetaStore> _documentMetaStore; const search::TuneFileAttributes _tuneFile; public: using SP = std::shared_ptr<DocumentMetaStoreInitializerResult>; - DocumentMetaStoreInitializerResult(DocumentMetaStore::SP - documentMetaStore_in, - const search::TuneFileAttributes & - tuneFile_in); + DocumentMetaStoreInitializerResult(std::shared_ptr<DocumentMetaStore> documentMetaStore_in, + const search::TuneFileAttributes & tuneFile_in); virtual ~DocumentMetaStoreInitializerResult(); - DocumentMetaStore::SP documentMetaStore() const { + std::shared_ptr<DocumentMetaStore> documentMetaStore() const { return _documentMetaStore; } const search::TuneFileAttributes &tuneFile() const { return _tuneFile; } diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp index 77452b60f21..27cffd67b86 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp @@ -228,10 +228,8 @@ DocumentMetaStore::onUpdateStat() { auto &compaction_strategy = getConfig().getCompactionStrategy(); vespalib::MemoryUsage usage = _metaDataStore.getMemoryUsage(); + usage.merge(_lidAlloc.getMemoryUsage()); usage.incAllocatedBytesOnHold(getGenerationHolder().get_held_bytes()); - size_t bvSize = _lidAlloc.getUsedLidsSize(); - usage.incAllocatedBytes(bvSize); - usage.incUsedBytes(bvSize); auto gid_to_lid_map_memory_usage = _gidToLidMap.getMemoryUsage(); _should_compact_gid_to_lid_map = compaction_strategy.should_compact_memory(gid_to_lid_map_memory_usage); usage.merge(gid_to_lid_map_memory_usage); diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.h index 72a062d85eb..e6b87ffdfc7 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.h @@ -6,7 +6,6 @@ #include "documentmetastoreattribute.h" #include "lid_allocator.h" #include "lid_gid_key_comparator.h" -#include "lid_hold_list.h" #include "raw_document_meta_data.h" #include <vespa/searchcore/proton/common/subdbtype.h> #include <vespa/searchlib/queryeval/blueprint.h> diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastorecontext.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastorecontext.cpp index 3be9282987c..57516f6d0aa 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastorecontext.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastorecontext.cpp @@ -1,15 +1,21 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "documentmetastorecontext.h" +#include "documentmetastore.h" namespace proton { -DocumentMetaStoreContext::ReadGuard::ReadGuard(const search::AttributeVector::SP &metaStoreAttr) : +DocumentMetaStoreContext::ReadGuard::ReadGuard(const std::shared_ptr<search::AttributeVector> & metaStoreAttr) : _guard(metaStoreAttr), _store(static_cast<const DocumentMetaStore &>(*_guard)) { } +const search::IDocumentMetaStore & +DocumentMetaStoreContext::ReadGuard::get() const { + return _store; +} + DocumentMetaStoreContext::DocumentMetaStoreContext(std::shared_ptr<bucketdb::BucketDBOwner> bucketDB) : DocumentMetaStoreContext(std::move(bucketDB), DocumentMetaStore::getFixedName(), search::GrowStrategy()) {} @@ -23,8 +29,8 @@ DocumentMetaStoreContext::DocumentMetaStoreContext(std::shared_ptr<bucketdb::Buc } -DocumentMetaStoreContext::DocumentMetaStoreContext(const search::AttributeVector::SP &metaStoreAttr) : - _metaStoreAttr(metaStoreAttr), +DocumentMetaStoreContext::DocumentMetaStoreContext(std::shared_ptr<search::AttributeVector> metaStoreAttr) : + _metaStoreAttr(std::move(metaStoreAttr)), _metaStore(std::dynamic_pointer_cast<IDocumentMetaStore>(_metaStoreAttr)) { } diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastorecontext.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastorecontext.h index fce2968104d..f85515922f9 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastorecontext.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastorecontext.h @@ -2,11 +2,13 @@ #pragma once -#include "documentmetastore.h" #include "i_document_meta_store_context.h" +#include <vespa/searchcommon/common/growstrategy.h> namespace proton { +class DocumentMetaStore; + /** * Class providing write and read interface to the document meta store. */ @@ -19,12 +21,12 @@ public: search::AttributeGuard _guard; const DocumentMetaStore &_store; public: - explicit ReadGuard(const search::AttributeVector::SP &metaStoreAttr); - const search::IDocumentMetaStore &get() const override { return _store; } + explicit ReadGuard(const std::shared_ptr<search::AttributeVector> &metaStoreAttr); + const search::IDocumentMetaStore &get() const override; }; private: - search::AttributeVector::SP _metaStoreAttr; - IDocumentMetaStore::SP _metaStore; + std::shared_ptr<search::AttributeVector> _metaStoreAttr; + std::shared_ptr<IDocumentMetaStore> _metaStore; public: explicit DocumentMetaStoreContext(std::shared_ptr<bucketdb::BucketDBOwner> bucketDB); @@ -40,9 +42,9 @@ public: * Create a new context with the given document meta store encapsulated * as an attribute vector. */ - explicit DocumentMetaStoreContext(const search::AttributeVector::SP &metaStoreAttr); + explicit DocumentMetaStoreContext(std::shared_ptr<search::AttributeVector> metaStoreAttr); - proton::IDocumentMetaStore::SP getSP() const override { return _metaStore; } + std::shared_ptr<proton::IDocumentMetaStore> getSP() const override { return _metaStore; } proton::IDocumentMetaStore & get() override { return *_metaStore; } IReadGuard::UP getReadGuard() const override { return std::make_unique<ReadGuard>(_metaStoreAttr); diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoresaver.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoresaver.h index 5f97ba1e0b0..f3f343aef38 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoresaver.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoresaver.h @@ -2,8 +2,10 @@ #pragma once +#include "lid_gid_key_comparator.h" +#include "i_store.h" +#include <vespa/vespalib/btree/btreeiterator.h> #include <vespa/searchlib/attribute/attributesaver.h> -#include "documentmetastore.h" namespace proton { diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.cpp index 5efc639064e..7b7d590d913 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.cpp @@ -27,11 +27,19 @@ LidAllocator::LidAllocator(uint32_t size, _freeLids(size, capacity, genHolder, true, false), _usedLids(size, capacity, genHolder, false, true), _pendingHoldLids(size, capacity, genHolder, false, false), - _lidFreeListConstructed(false), _activeLids(size, capacity, genHolder, false, false), - _numActiveLids(0u) -{ + _numActiveLids(0u), + _lidFreeListConstructed(false) +{ } +vespalib::MemoryUsage +LidAllocator::getMemoryUsage() const { + vespalib::MemoryUsage usage; + size_t allocated = sizeof(*this) + _freeLids.byteSize() + _usedLids.byteSize() + + _pendingHoldLids.byteSize() + _activeLids.byteSize() + _holdLids.size(); + usage.incAllocatedBytes(allocated); + usage.incUsedBytes(allocated); + return usage; } LidAllocator::~LidAllocator() = default; diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.h index 297218d17f8..2f38f47e4af 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.h @@ -6,6 +6,7 @@ #include "lidstatevector.h" #include <vespa/searchlib/attribute/attributeguard.h> #include <vespa/searchlib/queryeval/blueprint.h> +#include <vespa/vespalib/util/memoryusage.h> #include <atomic> namespace proton::documentmetastore { @@ -24,9 +25,9 @@ private: LidStateVector _freeLids; LidStateVector _usedLids; LidStateVector _pendingHoldLids; - bool _lidFreeListConstructed; LidStateVector _activeLids; std::atomic<uint32_t> _numActiveLids; + bool _lidFreeListConstructed; public: LidAllocator(uint32_t size, @@ -40,7 +41,7 @@ public: void registerLid(DocId lid) { _usedLids.setBit(lid); } void unregisterLid(DocId lid); void unregister_lids(const std::vector<DocId>& lids); - size_t getUsedLidsSize() const { return _usedLids.byteSize(); } + vespalib::MemoryUsage getMemoryUsage() const; void reclaim_memory(generation_t oldest_used_gen) { _holdLids.reclaim_memory(oldest_used_gen, _freeLids); } diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_hold_list.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_hold_list.cpp index ef0a244fc37..bacaf361d4a 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_hold_list.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_hold_list.cpp @@ -14,7 +14,7 @@ LidHoldList::add(const uint32_t data, generation_t generation) { if (!_holdList.empty()) { assert(generation >= _holdList.back().second); } - _holdList.push_back(std::make_pair(data, generation)); + _holdList.emplace_back(data, generation); } void diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_hold_list.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_hold_list.h index 1000a11e6cb..0e80713d3c9 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_hold_list.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_hold_list.h @@ -37,6 +37,8 @@ public: **/ size_t size() const { return _holdList.size(); } + size_t byteSize() const { return _holdList.size() * sizeof(Element); } + /** * Clears the free list. **/ |