diff options
author | Håvard Pettersen <havardpe@oath.com> | 2022-03-14 13:28:43 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2022-03-14 13:28:43 +0000 |
commit | 4711921ac7703b7e6eeb4e16cbd3e5d81472e4bd (patch) | |
tree | ccf237e956204a1e237af44504f817c136dd1862 /searchcore | |
parent | 7cf63413a6b1873d901acea154e40ccbf4d8147b (diff) |
fix tsan warnings related to match phase limiting
This fixes the tsan warnings. The consequences of 'wrong' would
probably be incorrect coverage result or similar. However, the fact
that the race warning indicates that we read the was_used/estimate
BEFORE writing them could indicate that not all threads agree on
whether we want to limit the search or not (they should). Not sure if
this is a real issue or how serious it is.
Diffstat (limited to 'searchcore')
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/matching/attribute_limiter.cpp | 14 | ||||
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/matching/attribute_limiter.h | 6 |
2 files changed, 16 insertions, 4 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/matching/attribute_limiter.cpp b/searchcore/src/vespa/searchcore/proton/matching/attribute_limiter.cpp index 335a3dc70fb..59f44c86d92 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/attribute_limiter.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/attribute_limiter.cpp @@ -34,6 +34,18 @@ AttributeLimiter::AttributeLimiter(Searchable &searchable_attributes, { } +bool +AttributeLimiter::was_used() const +{ + return (_estimatedHits.load(std::memory_order_relaxed) >= 0); +} + +ssize_t +AttributeLimiter::getEstimatedHits() const +{ + return _estimatedHits.load(std::memory_order_relaxed); +} + AttributeLimiter::~AttributeLimiter() = default; namespace { @@ -78,7 +90,7 @@ AttributeLimiter::create_search(size_t want_hits, size_t max_group_size, bool st field.add(FieldSpec(_attribute_name, my_field_id, my_handle)); _blueprint = _searchable_attributes.createBlueprint(_requestContext, field, node); _blueprint->fetchPostings(ExecuteInfo::create(strictSearch)); - _estimatedHits = _blueprint->getState().estimate().estHits; + _estimatedHits.store(_blueprint->getState().estimate().estHits, std::memory_order_relaxed); _blueprint->freeze(); } _match_datas.push_back(layout.createMatchData()); diff --git a/searchcore/src/vespa/searchcore/proton/matching/attribute_limiter.h b/searchcore/src/vespa/searchcore/proton/matching/attribute_limiter.h index 59d32bb997d..3e4efbbd371 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/attribute_limiter.h +++ b/searchcore/src/vespa/searchcore/proton/matching/attribute_limiter.h @@ -32,8 +32,8 @@ public: DiversityCutoffStrategy diversityCutoffStrategy); ~AttributeLimiter(); search::queryeval::SearchIterator::UP create_search(size_t want_hits, size_t max_group_size, bool strictSearch); - bool was_used() const { return ((!_match_datas.empty()) || (_blueprint.get() != nullptr)); } - ssize_t getEstimatedHits() const { return _estimatedHits; } + bool was_used() const; + ssize_t getEstimatedHits() const; static DiversityCutoffStrategy toDiversityCutoffStrategy(vespalib::stringref strategy); private: const vespalib::string & toString(DiversityCutoffStrategy strategy); @@ -45,7 +45,7 @@ private: std::mutex _lock; std::vector<search::fef::MatchData::UP> _match_datas; search::queryeval::Blueprint::UP _blueprint; - ssize_t _estimatedHits; + std::atomic<ssize_t> _estimatedHits; double _diversityCutoffFactor; DiversityCutoffStrategy _diversityCutoffStrategy; }; |