aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-10-03 21:20:19 +0200
committerGitHub <noreply@github.com>2022-10-03 21:20:19 +0200
commit906b57fc1b720bd31faf25f3e355cd1e55ab7be6 (patch)
treebb81eca665422d52c961b7dc9ae92c3224d37679
parent1fafdfd0af3631cb38a6e2e880ea9494bdf70ff4 (diff)
parente5594f3503a2ffb1fdf04d076205ccb6e194e18e (diff)
Merge pull request #24281 from vespa-engine/balder/cap-hits-and-offset-against-numdocsv8.62.51
To prevent against damages caused by excessive hits/offset param bein…
-rw-r--r--searchcore/src/tests/proton/matching/matching_test.cpp40
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/match_params.cpp14
-rw-r--r--searchlib/src/vespa/searchlib/engine/searchrequest.h2
3 files changed, 39 insertions, 17 deletions
diff --git a/searchcore/src/tests/proton/matching/matching_test.cpp b/searchcore/src/tests/proton/matching/matching_test.cpp
index df8f2a9476b..70f6cf73a72 100644
--- a/searchcore/src/tests/proton/matching/matching_test.cpp
+++ b/searchcore/src/tests/proton/matching/matching_test.cpp
@@ -934,8 +934,8 @@ TEST("require that getSummaryFeatures prefers cached query setup") {
}
TEST("require that match params are set up straight with ranking on") {
- MatchParams p(1, 2, 4, 0.7, 0, 1, true, true);
- ASSERT_EQUAL(1u, p.numDocs);
+ MatchParams p(10, 2, 4, 0.7, 0, 1, true, true);
+ ASSERT_EQUAL(10u, p.numDocs);
ASSERT_EQUAL(2u, p.heapSize);
ASSERT_EQUAL(4u, p.arraySize);
ASSERT_EQUAL(0.7, p.rankDropLimit);
@@ -945,8 +945,8 @@ TEST("require that match params are set up straight with ranking on") {
}
TEST("require that match params can turn off rank-drop-limit") {
- MatchParams p(1, 2, 4, -std::numeric_limits<feature_t>::quiet_NaN(), 0, 1, true, true);
- ASSERT_EQUAL(1u, p.numDocs);
+ MatchParams p(10, 2, 4, -std::numeric_limits<feature_t>::quiet_NaN(), 0, 1, true, true);
+ ASSERT_EQUAL(10u, p.numDocs);
ASSERT_EQUAL(2u, p.heapSize);
ASSERT_EQUAL(4u, p.arraySize);
ASSERT_TRUE(std::isnan(p.rankDropLimit));
@@ -957,8 +957,8 @@ TEST("require that match params can turn off rank-drop-limit") {
TEST("require that match params are set up straight with ranking on arraySize is atleast the size of heapSize") {
- MatchParams p(1, 6, 4, 0.7, 1, 1, true, true);
- ASSERT_EQUAL(1u, p.numDocs);
+ MatchParams p(10, 6, 4, 0.7, 1, 1, true, true);
+ ASSERT_EQUAL(10u, p.numDocs);
ASSERT_EQUAL(6u, p.heapSize);
ASSERT_EQUAL(6u, p.arraySize);
ASSERT_EQUAL(0.7, p.rankDropLimit);
@@ -967,8 +967,8 @@ TEST("require that match params are set up straight with ranking on arraySize is
}
TEST("require that match params are set up straight with ranking on arraySize is atleast the size of hits+offset") {
- MatchParams p(1, 6, 4, 0.7, 4, 4, true, true);
- ASSERT_EQUAL(1u, p.numDocs);
+ MatchParams p(10, 6, 4, 0.7, 4, 4, true, true);
+ ASSERT_EQUAL(10u, p.numDocs);
ASSERT_EQUAL(6u, p.heapSize);
ASSERT_EQUAL(8u, p.arraySize);
ASSERT_EQUAL(0.7, p.rankDropLimit);
@@ -976,9 +976,29 @@ TEST("require that match params are set up straight with ranking on arraySize is
ASSERT_EQUAL(4u, p.hits);
}
-TEST("require that match params are set up straight with ranking off array and heap size is 0") {
- MatchParams p(1, 6, 4, 0.7, 4, 4, true, false);
+TEST("require that match params are capped by numDocs") {
+ MatchParams p(1, 6, 4, 0.7, 4, 4, true, true);
ASSERT_EQUAL(1u, p.numDocs);
+ ASSERT_EQUAL(1u, p.heapSize);
+ ASSERT_EQUAL(1u, p.arraySize);
+ ASSERT_EQUAL(0.7, p.rankDropLimit);
+ ASSERT_EQUAL(1u, p.offset);
+ ASSERT_EQUAL(0u, p.hits);
+}
+
+TEST("require that match params are capped by numDocs and hits adjusted down") {
+ MatchParams p(5, 6, 4, 0.7, 4, 4, true, true);
+ ASSERT_EQUAL(5u, p.numDocs);
+ ASSERT_EQUAL(5u, p.heapSize);
+ ASSERT_EQUAL(5u, p.arraySize);
+ ASSERT_EQUAL(0.7, p.rankDropLimit);
+ ASSERT_EQUAL(4u, p.offset);
+ ASSERT_EQUAL(1u, p.hits);
+}
+
+TEST("require that match params are set up straight with ranking off array and heap size is 0") {
+ MatchParams p(10, 6, 4, 0.7, 4, 4, true, false);
+ ASSERT_EQUAL(10u, p.numDocs);
ASSERT_EQUAL(0u, p.heapSize);
ASSERT_EQUAL(0u, p.arraySize);
ASSERT_EQUAL(0.7, p.rankDropLimit);
diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_params.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_params.cpp
index 7465088d8f0..68a6f74fa50 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/match_params.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/match_params.cpp
@@ -8,7 +8,8 @@ namespace proton::matching {
namespace {
-uint32_t computeArraySize(uint32_t hitsPlussOffset, uint32_t heapSize, uint32_t arraySize)
+uint32_t
+computeArraySize(uint32_t hitsPlussOffset, uint32_t heapSize, uint32_t arraySize)
{
return std::max(hitsPlussOffset, std::max(heapSize, arraySize));
}
@@ -24,16 +25,17 @@ MatchParams::MatchParams(uint32_t numDocs_in,
bool hasFinalRank,
bool needRanking)
: numDocs(numDocs_in),
- heapSize((hasFinalRank && needRanking) ? heapSize_in : 0),
+ heapSize((hasFinalRank && needRanking) ? std::min(numDocs_in, heapSize_in) : 0),
arraySize((needRanking && ((heapSize_in + arraySize_in) > 0))
- ? computeArraySize(hits_in + offset_in, heapSize, arraySize_in)
+ ? std::min(numDocs_in, computeArraySize(hits_in + offset_in, heapSize, arraySize_in))
: 0),
- offset(offset_in),
- hits(hits_in),
+ offset(std::min(numDocs_in, offset_in)),
+ hits(std::min(numDocs_in - offset, hits_in)),
rankDropLimit(rankDropLimit_in)
{ }
-bool MatchParams::has_rank_drop_limit() const {
+bool
+MatchParams::has_rank_drop_limit() const {
return ! std::isnan(rankDropLimit);
}
diff --git a/searchlib/src/vespa/searchlib/engine/searchrequest.h b/searchlib/src/vespa/searchlib/engine/searchrequest.h
index 7b598735b42..ec1bc7550b5 100644
--- a/searchlib/src/vespa/searchlib/engine/searchrequest.h
+++ b/searchlib/src/vespa/searchlib/engine/searchrequest.h
@@ -23,7 +23,7 @@ public:
SearchRequest();
explicit SearchRequest(RelativeTime relativeTime);
- ~SearchRequest();
+ ~SearchRequest() override;
};
}