diff options
Diffstat (limited to 'searchlib/src/vespa/searchlib/docstore/storebybucket.h')
-rw-r--r-- | searchlib/src/vespa/searchlib/docstore/storebybucket.h | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/searchlib/src/vespa/searchlib/docstore/storebybucket.h b/searchlib/src/vespa/searchlib/docstore/storebybucket.h index dfe6199aa2e..ea1c6e766e0 100644 --- a/searchlib/src/vespa/searchlib/docstore/storebybucket.h +++ b/searchlib/src/vespa/searchlib/docstore/storebybucket.h @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once @@ -7,7 +7,6 @@ #include <vespa/vespalib/data/memorydatastore.h> #include <vespa/vespalib/util/executor.h> #include <vespa/vespalib/stllike/hash_map.h> -#include <map> #include <condition_variable> namespace search::docstore { @@ -24,56 +23,59 @@ class StoreByBucket using ConstBufferRef = vespalib::ConstBufferRef; using CompressionConfig = vespalib::compression::CompressionConfig; public: - StoreByBucket(MemoryDataStore & backingMemory, Executor & executor, CompressionConfig compression) noexcept; - //TODO Putting the below move constructor into cpp file fails for some unknown reason. Needs to be resolved. - StoreByBucket(StoreByBucket &&) noexcept = default; - StoreByBucket(const StoreByBucket &) = delete; - StoreByBucket & operator=(StoreByBucket &&) noexcept = delete; - StoreByBucket & operator = (const StoreByBucket &) = delete; - ~StoreByBucket(); - class IWrite { - public: - using BucketId=document::BucketId; - virtual ~IWrite() { } - virtual void write(BucketId bucketId, uint32_t chunkId, uint32_t lid, const void *buffer, size_t sz) = 0; - }; - void add(document::BucketId bucketId, uint32_t chunkId, uint32_t lid, const void *buffer, size_t sz); - void drain(IWrite & drain); - size_t getChunkCount() const; - size_t getBucketCount() const { return _where.size(); } - size_t getLidCount() const { - size_t lidCount(0); - for (const auto & it : _where) { - lidCount += it.second.size(); - } - return lidCount; - } -private: - void incChunksPosted(); - void waitAllProcessed(); - Chunk::UP createChunk(); - void closeChunk(Chunk::UP chunk); struct Index { using BucketId=document::BucketId; - Index(BucketId bucketId, uint32_t id, uint32_t chunkId, uint32_t entry) noexcept : - _bucketId(bucketId), _id(id), _chunkId(chunkId), _lid(entry) + Index(BucketId bucketId, uint32_t localChunkId, uint32_t chunkId, uint32_t entry) noexcept : + _bucketId(bucketId), _localChunkId(localChunkId), _chunkId(chunkId), _lid(entry) { } bool operator < (const Index & b) const noexcept { return BucketId::bucketIdToKey(_bucketId.getRawId()) < BucketId::bucketIdToKey(b._bucketId.getRawId()); } BucketId _bucketId; - uint32_t _id; + uint32_t _localChunkId; uint32_t _chunkId; uint32_t _lid; }; using IndexVector = std::vector<Index, vespalib::allocator_large<Index>>; + struct IWrite { + using BucketId=document::BucketId; + virtual ~IWrite() = default; + virtual void write(BucketId bucketId, uint32_t chunkId, uint32_t lid, ConstBufferRef data) = 0; + }; + struct IndexIterator { + virtual ~IndexIterator() = default; + virtual bool has_next() noexcept = 0; + virtual Index next() noexcept = 0; + }; + struct StoreIndex { + virtual ~StoreIndex() = default; + virtual void store(const Index & index) = 0; + }; + StoreByBucket(StoreIndex & storeIndex, MemoryDataStore & backingMemory, + Executor & executor, CompressionConfig compression) noexcept; + //TODO Putting the below move constructor into cpp file fails for some unknown reason. Needs to be resolved. + StoreByBucket(StoreByBucket &&) noexcept = delete; + StoreByBucket(const StoreByBucket &) = delete; + StoreByBucket & operator=(StoreByBucket &&) noexcept = delete; + StoreByBucket & operator = (const StoreByBucket &) = delete; + ~StoreByBucket(); + void add(document::BucketId bucketId, uint32_t chunkId, uint32_t lid, ConstBufferRef data); + void close(); + /// close() must have been called prior to calling getBucketCount() or drain() + void drain(IWrite & drain, IndexIterator & iterator); + size_t getChunkCount() const noexcept; +private: + void incChunksPosted(); + void waitAllProcessed(); + Chunk::UP createChunk(); + void closeChunk(Chunk::UP chunk); uint64_t _chunkSerial; Chunk::UP _current; - std::map<uint64_t, IndexVector> _where; + StoreIndex & _storeIndex; MemoryDataStore & _backingMemory; Executor & _executor; - std::unique_ptr<std::mutex> _lock; - std::unique_ptr<std::condition_variable> _cond; + mutable std::mutex _lock; + std::condition_variable _cond; size_t _numChunksPosted; vespalib::hash_map<uint64_t, ConstBufferRef> _chunks; CompressionConfig _compression; |