summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/attribute/sourceselector/sourceselector_test.cpp35
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributevector.h11
-rw-r--r--searchlib/src/vespa/searchlib/attribute/fixedsourceselector.cpp10
-rw-r--r--searchlib/src/vespa/searchlib/attribute/fixedsourceselector.h3
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/isourceselector.h7
5 files changed, 54 insertions, 12 deletions
diff --git a/searchlib/src/tests/attribute/sourceselector/sourceselector_test.cpp b/searchlib/src/tests/attribute/sourceselector/sourceselector_test.cpp
index a223b87a73f..75a0ccf6ab9 100644
--- a/searchlib/src/tests/attribute/sourceselector/sourceselector_test.cpp
+++ b/searchlib/src/tests/attribute/sourceselector/sourceselector_test.cpp
@@ -41,7 +41,7 @@ private:
void requireThatSelectorCanCloneAndSubtract();
void requireThatSelectorCanCloneAndSubtract();
template <typename SelectorType>
- void requireThatSelectorCanSaveAndLoad();
+ void requireThatSelectorCanSaveAndLoad(bool compactLidSpace);
void requireThatSelectorCanSaveAndLoad();
template <typename SelectorType>
void requireThatCompleteSourceRangeIsHandled();
@@ -49,6 +49,7 @@ private:
template <typename SelectorType>
void requireThatSourcesAreCountedCorrectly();
void requireThatSourcesAreCountedCorrectly();
+ void requireThatDocIdLimitIsCorrect();
};
int
@@ -64,6 +65,7 @@ Test::Main()
TEST_DO(requireThatSelectorCanSaveAndLoad());
TEST_DO(requireThatCompleteSourceRangeIsHandled());
TEST_DO(requireThatSourcesAreCountedCorrectly());
+ TEST_DO(requireThatDocIdLimitIsCorrect());
TEST_DONE();
}
@@ -140,12 +142,15 @@ Test::requireThatSelectorCanCloneAndSubtract()
template <typename SelectorType>
void
-Test::requireThatSelectorCanSaveAndLoad()
+Test::requireThatSelectorCanSaveAndLoad(bool compactLidSpace)
{
SelectorType selector(default_source, base_file_name2);
setSources(selector);
selector.setBaseId(base_id);
selector.setSource(maxDocId + 1, default_source);
+ if (compactLidSpace) {
+ selector.compactLidSpace(maxDocId - 4);
+ }
FastOS_FileInterface::EmptyAndRemoveDirectory(index_dir.c_str());
FastOS_FileInterface::MakeDirIfNotPresentOrExit(index_dir.c_str());
@@ -155,9 +160,13 @@ Test::requireThatSelectorCanSaveAndLoad()
save_info->save(TuneFileAttributes(), DummyFileHeaderContext());
typename SelectorType::UP
selector2(SelectorType::load(base_file_name));
- testSourceSelector(docs, arraysize(docs), default_source, *selector2);
+ testSourceSelector(docs, arraysize(docs) - compactLidSpace, default_source, *selector2);
EXPECT_EQUAL(base_id, selector2->getBaseId());
- EXPECT_EQUAL(maxDocId + 2, selector2->getDocIdLimit());
+ if (compactLidSpace) {
+ EXPECT_EQUAL(maxDocId - 4, selector2->getDocIdLimit());
+ } else {
+ EXPECT_EQUAL(maxDocId + 2, selector2->getDocIdLimit());
+ }
FastOS_FileInterface::EmptyAndRemoveDirectory(index_dir.c_str());
}
@@ -165,7 +174,8 @@ Test::requireThatSelectorCanSaveAndLoad()
void
Test::requireThatSelectorCanSaveAndLoad()
{
- requireThatSelectorCanSaveAndLoad<FixedSourceSelector>();
+ requireThatSelectorCanSaveAndLoad<FixedSourceSelector>(false);
+ requireThatSelectorCanSaveAndLoad<FixedSourceSelector>(true);
}
template <typename SelectorType>
@@ -211,6 +221,21 @@ Test::requireThatSourcesAreCountedCorrectly()
requireThatSourcesAreCountedCorrectly<FixedSourceSelector>();
}
+void
+Test::requireThatDocIdLimitIsCorrect()
+{
+ FixedSourceSelector selector(default_source, base_file_name);
+ EXPECT_EQUAL(0u, selector.getDocIdLimit());
+ selector.setSource(8, 10);
+ EXPECT_EQUAL(9u, selector.getDocIdLimit());
+ selector.compactLidSpace(4);
+ EXPECT_EQUAL(4u, selector.getDocIdLimit());
+ selector.setSource(6, 10);
+ EXPECT_EQUAL(7u, selector.getDocIdLimit());
+ auto selector2 = selector.cloneAndSubtract(base_file_name2, 3);
+ EXPECT_EQUAL(7u, selector2->getDocIdLimit());
+}
+
} // namespace
TEST_APPHOOK(Test);
diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.h b/searchlib/src/vespa/searchlib/attribute/attributevector.h
index ab590f807bf..1e8dfd6658a 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributevector.h
+++ b/searchlib/src/vespa/searchlib/attribute/attributevector.h
@@ -256,12 +256,6 @@ protected:
EnumModifier getEnumModifier();
ValueModifier getValueModifier() { return ValueModifier(*this); }
- void updateUncommittedDocIdLimit(DocId doc) {
- if (_uncommittedDocIdLimit <= doc) {
- _uncommittedDocIdLimit = doc + 1;
- }
- }
-
void updateCommittedDocIdLimit() {
if (_uncommittedDocIdLimit != 0) {
if (_uncommittedDocIdLimit > _committedDocIdLimit) {
@@ -413,6 +407,11 @@ public:
void setCommittedDocIdLimit(uint32_t committedDocIdLimit) {
_committedDocIdLimit = committedDocIdLimit;
}
+ void updateUncommittedDocIdLimit(DocId doc) {
+ if (_uncommittedDocIdLimit <= doc) {
+ _uncommittedDocIdLimit = doc + 1;
+ }
+ }
const Status & getStatus() const { return _status; }
Status & getStatus() { return _status; }
diff --git a/searchlib/src/vespa/searchlib/attribute/fixedsourceselector.cpp b/searchlib/src/vespa/searchlib/attribute/fixedsourceselector.cpp
index ae2f0234e60..c2d43bf63ec 100644
--- a/searchlib/src/vespa/searchlib/attribute/fixedsourceselector.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/fixedsourceselector.cpp
@@ -45,6 +45,7 @@ FixedSourceSelector::cloneAndSubtract(const vespalib::string & attrBaseFileName,
}
selector->_source.commit();
selector->setBaseId(getBaseId() + diff);
+ selector->_source.setCommittedDocIdLimit(_source.getCommittedDocIdLimit());
return selector;
}
@@ -85,7 +86,16 @@ FixedSourceSelector::setSource(uint32_t docId, queryeval::Source source)
**/
reserve(docId+1);
_source.update(docId, source);
+ _source.updateUncommittedDocIdLimit(docId + 1);
_source.commit();
}
+void
+FixedSourceSelector::compactLidSpace(uint32_t lidLimit)
+{
+ if (lidLimit < _source.getCommittedDocIdLimit()) {
+ _source.compactLidSpace(lidLimit + 1);
+ }
+}
+
} // namespace search
diff --git a/searchlib/src/vespa/searchlib/attribute/fixedsourceselector.h b/searchlib/src/vespa/searchlib/attribute/fixedsourceselector.h
index 4dbfc22c270..f92bb1e0eb2 100644
--- a/searchlib/src/vespa/searchlib/attribute/fixedsourceselector.h
+++ b/searchlib/src/vespa/searchlib/attribute/fixedsourceselector.h
@@ -38,8 +38,9 @@ public:
// Inherit doc from ISourceSelector
void setSource(uint32_t docId, queryeval::Source source) final override;
uint32_t getDocIdLimit() const final override {
- return _source.getNumDocs() - 1;
+ return _source.getCommittedDocIdLimit() - 1;
}
+ void compactLidSpace(uint32_t lidLimit) override;
std::unique_ptr<IIterator> createIterator() const final override {
return std::make_unique<Iterator>(*this);
}
diff --git a/searchlib/src/vespa/searchlib/queryeval/isourceselector.h b/searchlib/src/vespa/searchlib/queryeval/isourceselector.h
index 88a3cb57a8a..7151a785c26 100644
--- a/searchlib/src/vespa/searchlib/queryeval/isourceselector.h
+++ b/searchlib/src/vespa/searchlib/queryeval/isourceselector.h
@@ -73,6 +73,13 @@ public:
virtual uint32_t getDocIdLimit() const = 0;
/**
+ * Sets the lid limit in this selector.
+ *
+ * @param lidLimit the new lid limit (one above highest valid doc id).
+ */
+ virtual void compactLidSpace(uint32_t lidLimit) = 0;
+
+ /**
* Create a new iterator over the data held by this source
* selector.
*