aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-06-15 08:30:29 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-06-15 08:30:29 +0000
commit1e229d508131b5099576e857132ce79a55342b4e (patch)
tree2052db056440aea68284fd3c824c9236b97642b4 /searchlib
parent5343a9bea2b71203d3a804a9d6e04745723146cb (diff)
Move code from .h to .cpp file
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/docstore/visitcache.cpp60
-rw-r--r--searchlib/src/vespa/searchlib/docstore/visitcache.h64
2 files changed, 64 insertions, 60 deletions
diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
index e9023c48ee5..cb56d5d20ff 100644
--- a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
@@ -2,12 +2,14 @@
#include "visitcache.h"
#include "ibucketizer.h"
-#include <vespa/vespalib/stllike/cache.hpp>
-#include <vespa/vespalib/stllike/hash_map.hpp>
+#include <vespa/vespalib/stllike/hash_set.h>
+#include <vespa/vespalib/stllike/hash_map.h>
+#include <vespa/vespalib/stllike/cache.h>
#include <vespa/vespalib/data/databuffer.h>
#include <vespa/vespalib/util/compressor.h>
#include <vespa/vespalib/util/memory_allocator.h>
-#include <algorithm>
+#include <vespa/vespalib/stllike/cache.hpp>
+#include <vespa/vespalib/stllike/hash_map.hpp>
namespace search::docstore {
@@ -53,8 +55,7 @@ getBufferSize(const BlobSet::Positions & p) {
BlobSet::BlobSet(Positions positions, Alloc && buffer) noexcept
: _positions(std::move(positions)),
_buffer(std::move(buffer), getBufferSize(_positions))
-{
-}
+{ }
void
BlobSet::append(uint32_t lid, ConstBufferRef blob) {
@@ -79,8 +80,7 @@ CompressedBlobSet::CompressedBlobSet() noexcept
: _compression(CompressionConfig::Type::LZ4),
_positions(),
_buffer()
-{
-}
+{ }
CompressedBlobSet::~CompressedBlobSet() = default;
@@ -136,8 +136,45 @@ VisitCollector::visit(uint32_t lid, ConstBufferRef buf) {
}
}
+struct ByteSize {
+ size_t operator() (const CompressedBlobSet & arg) const noexcept { return arg.byteSize(); }
+};
+
}
+using CacheParams = vespalib::CacheParam<
+ vespalib::LruParam<KeySet, CompressedBlobSet>,
+ VisitCache::BackingStore,
+ vespalib::zero<KeySet>,
+ ByteSize
+>;
+
+/**
+ * This extends the default thread safe cache implementation so that
+ * it will correctly invalidate the cached sets when objects are removed/updated.
+ * It will also detect the addition of new objects to any of the sets upon first
+ * usage of the set and then invalidate and perform fresh visit of the backing store.
+ */
+class VisitCache::Cache : public vespalib::cache<CacheParams> {
+public:
+ Cache(BackingStore & b, size_t maxBytes);
+ ~Cache() override;
+ CompressedBlobSet readSet(const KeySet & keys);
+ void removeKey(uint32_t key);
+ vespalib::MemoryUsage getStaticMemoryUsage() const override;
+private:
+ void locateAndInvalidateOtherSubsets(const UniqueLock & cacheGuard, const KeySet & keys);
+ using IdSet = vespalib::hash_set<uint64_t>;
+ using Parent = vespalib::cache<CacheParams>;
+ using LidUniqueKeySetId = vespalib::hash_map<uint32_t, uint64_t>;
+ using IdKeySetMap = vespalib::hash_map<uint64_t, KeySet>;
+ IdSet findSetsContaining(const UniqueLock &, const KeySet & keys) const;
+ void onInsert(const K & key) override;
+ void onRemove(const K & key) override;
+ LidUniqueKeySetId _lid2Id;
+ IdKeySetMap _id2KeySet;
+};
+
bool
VisitCache::BackingStore::read(const KeySet &key, CompressedBlobSet &blobs) const {
BlobSet blobSet;
@@ -157,8 +194,9 @@ VisitCache::BackingStore::reconfigure(CompressionConfig compression) {
VisitCache::VisitCache(IDataStore &store, size_t cacheSize, CompressionConfig compression) :
_store(store, compression),
_cache(std::make_unique<Cache>(_store, cacheSize))
-{
-}
+{ }
+
+VisitCache::~VisitCache() = default;
void
VisitCache::reconfigure(size_t cacheSize, CompressionConfig compression) {
@@ -166,6 +204,10 @@ VisitCache::reconfigure(size_t cacheSize, CompressionConfig compression) {
_cache->setCapacityBytes(cacheSize);
}
+vespalib::MemoryUsage
+VisitCache::getStaticMemoryUsage() const {
+ return _cache->getStaticMemoryUsage();
+}
VisitCache::Cache::IdSet
VisitCache::Cache::findSetsContaining(const UniqueLock &, const KeySet & keys) const {
diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.h b/searchlib/src/vespa/searchlib/docstore/visitcache.h
index 8b7ae5e6753..f7b419c0fc6 100644
--- a/searchlib/src/vespa/searchlib/docstore/visitcache.h
+++ b/searchlib/src/vespa/searchlib/docstore/visitcache.h
@@ -3,14 +3,10 @@
#pragma once
#include "idocumentstore.h"
-#include <vespa/vespalib/stllike/cache.h>
-#include <vespa/vespalib/stllike/hash_set.h>
-#include <vespa/vespalib/stllike/hash_map.h>
#include <vespa/vespalib/util/alloc.h>
#include <vespa/vespalib/util/memory.h>
#include <vespa/vespalib/util/compressionconfig.h>
#include <vespa/vespalib/objects/nbostream.h>
-#include <vespa/document/util/bytebuffer.h>
namespace search::docstore {
@@ -100,26 +96,27 @@ class VisitCache {
public:
using CompressionConfig = vespalib::compression::CompressionConfig;
VisitCache(IDataStore &store, size_t cacheSize, CompressionConfig compression);
+ ~VisitCache();
CompressedBlobSet read(const IDocumentStore::LidVector & keys) const;
void remove(uint32_t key);
void invalidate(uint32_t key) { remove(key); }
vespalib::CacheStats getCacheStats() const;
- vespalib::MemoryUsage getStaticMemoryUsage() const { return _cache->getStaticMemoryUsage(); }
+ vespalib::MemoryUsage getStaticMemoryUsage() const;
void reconfigure(size_t cacheSize, CompressionConfig compression);
-private:
+
/**
- * This implments the interface the cache uses when it has a cache miss.
- * It wraps an IDataStore. Given a set of lids it will visit all objects
- * and compress them as a complete set to maximize compression rate.
- * As this is a readonly cache the write/erase methods are noops.
- */
+ * This implments the interface the cache uses when it has a cache miss.
+ * It wraps an IDataStore. Given a set of lids it will visit all objects
+ * and compress them as a complete set to maximize compression rate.
+ * As this is a readonly cache the write/erase methods are noops.
+ */
class BackingStore {
public:
- BackingStore(IDataStore &store, CompressionConfig compression) :
- _backingStore(store),
- _compression(compression)
+ BackingStore(IDataStore &store, CompressionConfig compression)
+ : _backingStore(store),
+ _compression(compression)
{ }
bool read(const KeySet &key, CompressedBlobSet &blobs) const;
void write(const KeySet &, const CompressedBlobSet &) { }
@@ -130,44 +127,9 @@ private:
IDataStore &_backingStore;
std::atomic<CompressionConfig> _compression;
};
+private:
- struct ByteSize {
- size_t operator() (const CompressedBlobSet & arg) const noexcept { return arg.byteSize(); }
- };
-
- using CacheParams = vespalib::CacheParam<
- vespalib::LruParam<KeySet, CompressedBlobSet>,
- BackingStore,
- vespalib::zero<KeySet>,
- ByteSize
- >;
-
- /**
- * This extends the default thread safe cache implementation so that
- * it will correctly invalidate the cached sets when objects are removed/updated.
- * It will also detect the addition of new objects to any of the sets upon first
- * usage of the set and then invalidate and perform fresh visit of the backing store.
- */
- class Cache : public vespalib::cache<CacheParams> {
- public:
- Cache(BackingStore & b, size_t maxBytes);
- ~Cache() override;
- CompressedBlobSet readSet(const KeySet & keys);
- void removeKey(uint32_t key);
- vespalib::MemoryUsage getStaticMemoryUsage() const override;
- private:
- void locateAndInvalidateOtherSubsets(const UniqueLock & cacheGuard, const KeySet & keys);
- using IdSet = vespalib::hash_set<uint64_t>;
- using Parent = vespalib::cache<CacheParams>;
- using LidUniqueKeySetId = vespalib::hash_map<uint32_t, uint64_t>;
- using IdKeySetMap = vespalib::hash_map<uint64_t, KeySet>;
- IdSet findSetsContaining(const UniqueLock &, const KeySet & keys) const;
- void onInsert(const K & key) override;
- void onRemove(const K & key) override;
- LidUniqueKeySetId _lid2Id;
- IdKeySetMap _id2KeySet;
- };
-
+ class Cache;
BackingStore _store;
std::unique_ptr<Cache> _cache;
};