diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-04-29 14:11:15 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-04-29 14:12:52 +0200 |
commit | e1122cf5e270f3d13c04ff56cb787fb2f6b0b1c9 (patch) | |
tree | 606eae7906f684a3ce6626aaec684e2cdbb2999a /searchlib | |
parent | 4b98768ff0b2772631e9bcce55568f3171b2015d (diff) |
Fix race conditions in vespalib::Cache.
Diffstat (limited to 'searchlib')
9 files changed, 16 insertions, 61 deletions
diff --git a/searchlib/src/tests/docstore/document_store/document_store_test.cpp b/searchlib/src/tests/docstore/document_store/document_store_test.cpp index 0483ea26423..5050592dc87 100644 --- a/searchlib/src/tests/docstore/document_store/document_store_test.cpp +++ b/searchlib/src/tests/docstore/document_store/document_store_test.cpp @@ -2,7 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/searchlib/docstore/logdocumentstore.h> #include <vespa/searchlib/docstore/value.h> -#include <vespa/searchlib/docstore/cachestats.h> +#include <vespa/vespalib/stllike/cache_stats.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/document/fieldvalue/document.h> diff --git a/searchlib/src/tests/docstore/document_store_visitor/document_store_visitor_test.cpp b/searchlib/src/tests/docstore/document_store_visitor/document_store_visitor_test.cpp index c08aa7ce9fc..e811e68f4b5 100644 --- a/searchlib/src/tests/docstore/document_store_visitor/document_store_visitor_test.cpp +++ b/searchlib/src/tests/docstore/document_store_visitor/document_store_visitor_test.cpp @@ -3,7 +3,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/searchlib/docstore/documentstore.h> #include <vespa/searchlib/docstore/logdocumentstore.h> -#include <vespa/searchlib/docstore/cachestats.h> +#include <vespa/vespalib/stllike/cache_stats.h> #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/searchlib/common/bitvector.h> #include <vespa/document/repo/documenttyperepo.h> diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp index bb2d0177dd9..fffa1778c85 100644 --- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp +++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp @@ -13,6 +13,7 @@ #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/searchlib/test/directory_handler.h> #include <vespa/vespalib/stllike/asciistream.h> +#include <vespa/vespalib/stllike/cache_stats.h> #include <vespa/vespalib/test/insertion_operators.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/util/threadstackexecutor.h> @@ -24,6 +25,7 @@ using document::StringFieldValue; using namespace search::docstore; using namespace search; using namespace vespalib::alloc; +using vespalib::CacheStats; using search::index::DummyFileHeaderContext; using search::test::DirectoryHandler; diff --git a/searchlib/src/vespa/searchlib/docstore/cachestats.h b/searchlib/src/vespa/searchlib/docstore/cachestats.h deleted file mode 100644 index 4bad9b48fa3..00000000000 --- a/searchlib/src/vespa/searchlib/docstore/cachestats.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include <cstdint> -#include <sys/types.h> - -namespace search { - -struct CacheStats { - size_t hits; - size_t misses; - size_t elements; - size_t memory_used; - size_t invalidations; - - CacheStats() - : hits(0), - misses(0), - elements(0), - memory_used(0), - invalidations(0) - { } - - CacheStats(size_t hits_, size_t misses_, size_t elements_, size_t memory_used_, size_t invalidations_) - : hits(hits_), - misses(misses_), - elements(elements_), - memory_used(memory_used_), - invalidations(invalidations_) - { } - - CacheStats & - operator+=(const CacheStats &rhs) - { - hits += rhs.hits; - misses += rhs.misses; - elements += rhs.elements; - memory_used += rhs.memory_used; - invalidations += rhs.invalidations; - return *this; - } - - size_t lookups() const { return hits + misses; } -}; - -} - diff --git a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp index b4ff050c0f6..0853672e949 100644 --- a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp +++ b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp @@ -1,6 +1,5 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "cachestats.h" #include "documentstore.h" #include "visitcache.h" #include "ibucketizer.h" @@ -16,6 +15,7 @@ LOG_SETUP(".searchlib.docstore.documentstore"); using document::DocumentTypeRepo; +using vespalib::CacheStats; using vespalib::compression::CompressionConfig; namespace search { @@ -437,8 +437,8 @@ DocumentStore::getFileChunkStats() const CacheStats DocumentStore::getCacheStats() const { CacheStats visitStats = _visitCache->getCacheStats(); - CacheStats singleStats(_cache->getHit(), _cache->getMiss() + _uncached_lookups, - _cache->size(), _cache->sizeBytes(), _cache->getInvalidate()); + CacheStats singleStats = _cache->get_stats(); + singleStats.add_extra_misses(_uncached_lookups.load(std::memory_order_relaxed)); singleStats += visitStats; return singleStats; } diff --git a/searchlib/src/vespa/searchlib/docstore/documentstore.h b/searchlib/src/vespa/searchlib/docstore/documentstore.h index 6402c16cd5e..6270108efb8 100644 --- a/searchlib/src/vespa/searchlib/docstore/documentstore.h +++ b/searchlib/src/vespa/searchlib/docstore/documentstore.h @@ -82,7 +82,7 @@ public: size_t getDiskFootprint() const override { return _backingStore.getDiskFootprint(); } size_t getDiskBloat() const override { return _backingStore.getDiskBloat(); } size_t getMaxSpreadAsBloat() const override { return _backingStore.getMaxSpreadAsBloat(); } - CacheStats getCacheStats() const override; + vespalib::CacheStats getCacheStats() const override; size_t memoryMeta() const override { return _backingStore.memoryMeta(); } const vespalib::string & getBaseDir() const override { return _backingStore.getBaseDir(); } void accept(IDocumentStoreReadVisitor &visitor, IDocumentStoreVisitorProgress &visitorProgress, diff --git a/searchlib/src/vespa/searchlib/docstore/idocumentstore.h b/searchlib/src/vespa/searchlib/docstore/idocumentstore.h index d84a5ad7e7e..08983efb0da 100644 --- a/searchlib/src/vespa/searchlib/docstore/idocumentstore.h +++ b/searchlib/src/vespa/searchlib/docstore/idocumentstore.h @@ -12,12 +12,13 @@ namespace document { class DocumentTypeRepo; } -namespace vespalib { class nbostream; } +namespace vespalib { +class CacheStats; +class nbostream; +} namespace search { -struct CacheStats; - class IDocumentStoreReadVisitor { public: @@ -163,7 +164,7 @@ public: /** * Returns statistics about the cache. */ - virtual CacheStats getCacheStats() const = 0; + virtual vespalib::CacheStats getCacheStats() const = 0; /** * Returns the base directory from which all structures are stored. diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp index c37fe30b421..fd6146dae47 100644 --- a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp +++ b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp @@ -11,6 +11,7 @@ namespace search::docstore { +using vespalib::CacheStats; using vespalib::ConstBufferRef; using vespalib::DataBuffer; using vespalib::alloc::Alloc; @@ -221,7 +222,7 @@ VisitCache::remove(uint32_t key) { CacheStats VisitCache::getCacheStats() const { - return CacheStats(_cache->getHit(), _cache->getMiss(), _cache->size(), _cache->sizeBytes(), _cache->getInvalidate()); + return _cache->get_stats(); } VisitCache::Cache::Cache(BackingStore & b, size_t maxBytes) : diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.h b/searchlib/src/vespa/searchlib/docstore/visitcache.h index 1e2dbd29062..558f01f5e80 100644 --- a/searchlib/src/vespa/searchlib/docstore/visitcache.h +++ b/searchlib/src/vespa/searchlib/docstore/visitcache.h @@ -3,7 +3,6 @@ #pragma once #include "idocumentstore.h" -#include "cachestats.h" #include <vespa/vespalib/stllike/cache.h> #include <vespa/vespalib/stllike/hash_set.h> #include <vespa/vespalib/stllike/hash_map.h> @@ -105,7 +104,7 @@ public: void remove(uint32_t key); void invalidate(uint32_t key) { remove(key); } - CacheStats getCacheStats() const; + vespalib::CacheStats getCacheStats() const; void reconfigure(size_t cacheSize, const CompressionConfig &compression); private: /** |