summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirst@oath.com>2017-09-11 15:12:02 +0000
committerGeir Storli <geirst@oath.com>2017-09-11 15:12:02 +0000
commit67bf5f95c79f9452112931714fc1f273a19a5eb9 (patch)
tree4e54c19ab09085d9299a23a140b24da8f524cdb5
parentfcefafb47a56d9893834d27eb6de1759c8286193 (diff)
Keep a document meta store read guard together with bitvector posting list in search cache for imported attributes.
This is to ensure that no lids that are cached in the bitvector are re-used until the guard is released.
-rw-r--r--searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp3
-rw-r--r--searchcore/src/tests/proton/attribute/attribute_test.cpp1
-rw-r--r--searchcore/src/tests/proton/attribute/imported_attributes_context/imported_attributes_context_test.cpp1
-rw-r--r--searchcore/src/tests/proton/attribute/imported_attributes_repo/imported_attributes_repo_test.cpp1
-rw-r--r--searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp1
-rw-r--r--searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp1
-rw-r--r--searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp2
-rw-r--r--searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp6
-rw-r--r--searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.h5
-rw-r--r--searchcore/src/vespa/searchcore/proton/reference/i_document_db_reference_resolver.h3
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp1
-rw-r--r--searchlib/src/tests/attribute/bitvector_search_cache/bitvector_search_cache_test.cpp3
-rw-r--r--searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h9
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h15
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_search_context.h2
-rw-r--r--searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h30
21 files changed, 87 insertions, 18 deletions
diff --git a/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp b/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp
index 5b64fa80d39..6a5932d2b3a 100644
--- a/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp
+++ b/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp
@@ -133,7 +133,8 @@ struct ImportedAttributesRepoBuilder {
void add(const vespalib::string &name) {
auto refAttr = std::make_shared<ReferenceAttribute>(name + "_ref", AVConfig(BasicType::REFERENCE));
auto targetAttr = search::AttributeFactory::createAttribute(name + "_target", INT32_SINGLE);
- auto importedAttr = std::make_shared<ImportedAttributeVector>(name, refAttr, targetAttr, false);
+ auto documentMetaStore = std::shared_ptr<search::IDocumentMetaStoreContext>();
+ auto importedAttr = std::make_shared<ImportedAttributeVector>(name, refAttr, targetAttr, documentMetaStore, false);
_repo->add(name, importedAttr);
}
ImportedAttributesRepo::UP build() {
diff --git a/searchcore/src/tests/proton/attribute/attribute_test.cpp b/searchcore/src/tests/proton/attribute/attribute_test.cpp
index 1112cf75570..badb42d4be4 100644
--- a/searchcore/src/tests/proton/attribute/attribute_test.cpp
+++ b/searchcore/src/tests/proton/attribute/attribute_test.cpp
@@ -723,6 +723,7 @@ createImportedAttribute(const vespalib::string &name)
auto result = std::make_shared<ImportedAttributeVector>(name,
ReferenceAttribute::SP(),
AttributeVector::SP(),
+ std::shared_ptr<search::IDocumentMetaStoreContext>(),
true);
result->getSearchCache()->insert("foo", BitVectorSearchCache::Entry::SP());
return result;
diff --git a/searchcore/src/tests/proton/attribute/imported_attributes_context/imported_attributes_context_test.cpp b/searchcore/src/tests/proton/attribute/imported_attributes_context/imported_attributes_context_test.cpp
index d95d79fbd11..f221b2140c1 100644
--- a/searchcore/src/tests/proton/attribute/imported_attributes_context/imported_attributes_context_test.cpp
+++ b/searchcore/src/tests/proton/attribute/imported_attributes_context/imported_attributes_context_test.cpp
@@ -71,6 +71,7 @@ struct Fixture {
auto attr = std::make_shared<ImportedAttributeVector>(name,
createReferenceAttribute(name + "_ref"),
createTargetAttribute(name + "_target"),
+ std::shared_ptr<search::IDocumentMetaStoreContext>(),
false);
repo.add(name, attr);
return *this;
diff --git a/searchcore/src/tests/proton/attribute/imported_attributes_repo/imported_attributes_repo_test.cpp b/searchcore/src/tests/proton/attribute/imported_attributes_repo/imported_attributes_repo_test.cpp
index c41b88be2b4..e23c308050b 100644
--- a/searchcore/src/tests/proton/attribute/imported_attributes_repo/imported_attributes_repo_test.cpp
+++ b/searchcore/src/tests/proton/attribute/imported_attributes_repo/imported_attributes_repo_test.cpp
@@ -22,6 +22,7 @@ createAttr(const vespalib::string &name)
return std::make_shared<ImportedAttributeVector>(name,
ReferenceAttribute::SP(),
AttributeVector::SP(),
+ std::shared_ptr<search::IDocumentMetaStoreContext>(),
false);
}
diff --git a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp
index 211adce5f48..412c7abac5b 100644
--- a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp
+++ b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp
@@ -143,6 +143,7 @@ struct EmptyConstantValueFactory : public vespalib::eval::ConstantValueFactory {
struct MyDocumentDBReferenceResolver : public IDocumentDBReferenceResolver {
std::unique_ptr<ImportedAttributesRepo> resolve(const search::IAttributeManager &,
const search::IAttributeManager &,
+ const std::shared_ptr<search::IDocumentMetaStoreContext> &,
fastos::TimeStamp) override {
return std::make_unique<ImportedAttributesRepo>();
}
diff --git a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp
index 8cd57b1b0cb..0b88471a1f5 100644
--- a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp
+++ b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp
@@ -110,6 +110,7 @@ struct MyMetricsWireService : public DummyWireService
struct MyDocumentDBReferenceResolver : public IDocumentDBReferenceResolver {
std::unique_ptr<ImportedAttributesRepo> resolve(const search::IAttributeManager &,
const search::IAttributeManager &,
+ const std::shared_ptr<search::IDocumentMetaStoreContext> &,
fastos::TimeStamp) override {
return std::make_unique<ImportedAttributesRepo>();
}
diff --git a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp
index a6576d11279..40f9ed9b749 100644
--- a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp
+++ b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp
@@ -226,7 +226,7 @@ struct Fixture {
}
ImportedAttributesRepo::UP resolve(fastos::TimeStamp visibilityDelay) {
DocumentDBReferenceResolver resolver(registry, docModel.childDocType, importedFieldsCfg, docModel.childDocType, _gidToLidChangeListenerRefCount, _attributeFieldWriter);
- return resolver.resolve(attrMgr, oldAttrMgr, visibilityDelay);
+ return resolver.resolve(attrMgr, oldAttrMgr, std::shared_ptr<search::IDocumentMetaStoreContext>(), visibilityDelay);
}
ImportedAttributesRepo::UP resolve() {
return resolve(fastos::TimeStamp(0));
diff --git a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp
index c56aa18c1f7..5932742baf9 100644
--- a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp
+++ b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp
@@ -136,6 +136,7 @@ DocumentDBReferenceResolver::listenToGidToLidChanges(const IAttributeManager &at
ImportedAttributesRepo::UP
DocumentDBReferenceResolver::createImportedAttributesRepo(const IAttributeManager &attrMgr,
+ const std::shared_ptr<search::IDocumentMetaStoreContext> &documentMetaStore,
bool useSearchCache)
{
auto result = std::make_unique<ImportedAttributesRepo>();
@@ -143,7 +144,7 @@ DocumentDBReferenceResolver::createImportedAttributesRepo(const IAttributeManage
ReferenceAttribute::SP refAttr = getReferenceAttribute(attr.referencefield, attrMgr);
AttributeVector::SP targetAttr = getTargetDocumentDB(refAttr->getName())->getAttribute(attr.targetfield);
ImportedAttributeVector::SP importedAttr =
- std::make_shared<ImportedAttributeVector>(attr.name, refAttr, targetAttr, useSearchCache);
+ std::make_shared<ImportedAttributeVector>(attr.name, refAttr, targetAttr, documentMetaStore, useSearchCache);
result->add(importedAttr->getName(), importedAttr);
}
return result;
@@ -173,12 +174,13 @@ DocumentDBReferenceResolver::~DocumentDBReferenceResolver()
ImportedAttributesRepo::UP
DocumentDBReferenceResolver::resolve(const IAttributeManager &newAttrMgr,
const IAttributeManager &oldAttrMgr,
+ const std::shared_ptr<search::IDocumentMetaStoreContext> &documentMetaStore,
fastos::TimeStamp visibilityDelay)
{
connectReferenceAttributesToGidMapper(newAttrMgr);
detectOldListeners(oldAttrMgr);
listenToGidToLidChanges(newAttrMgr);
- return createImportedAttributesRepo(newAttrMgr, (visibilityDelay > 0));
+ return createImportedAttributesRepo(newAttrMgr, documentMetaStore, (visibilityDelay > 0));
}
void
diff --git a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.h b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.h
index 8e0a4178622..fc8b3751ea2 100644
--- a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.h
+++ b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.h
@@ -7,7 +7,8 @@
#include <map>
namespace document { class DocumentType; class DocumentTypeRepo; }
-namespace search { class ISequencedTaskExecutor; class IAttributeManager; namespace attribute { class IAttributeVector; class ReferenceAttribute; } }
+namespace search { class ISequencedTaskExecutor; class IAttributeManager; class IDocumentMetaStoreContext;
+ namespace attribute { class IAttributeVector; class ReferenceAttribute; } }
namespace vespa { namespace config { namespace search { namespace internal { class InternalImportedFieldsType; } } } }
namespace proton {
@@ -37,6 +38,7 @@ private:
std::shared_ptr<IDocumentDBReference> getTargetDocumentDB(const vespalib::string &refAttrName) const;
void connectReferenceAttributesToGidMapper(const search::IAttributeManager &attrMgr);
std::unique_ptr<ImportedAttributesRepo> createImportedAttributesRepo(const search::IAttributeManager &attrMgr,
+ const std::shared_ptr<search::IDocumentMetaStoreContext> &documentMetaStore,
bool useSearchCache);
void detectOldListeners(const search::IAttributeManager &attrMgr);
void listenToGidToLidChanges(const search::IAttributeManager &attrMgr);
@@ -52,6 +54,7 @@ public:
virtual std::unique_ptr<ImportedAttributesRepo> resolve(const search::IAttributeManager &newAttrMgr,
const search::IAttributeManager &oldAttrMgr,
+ const std::shared_ptr<search::IDocumentMetaStoreContext> &documentMetaStore,
fastos::TimeStamp visibilityDelay) override;
virtual void teardown(const search::IAttributeManager &oldAttrMgr) override;
};
diff --git a/searchcore/src/vespa/searchcore/proton/reference/i_document_db_reference_resolver.h b/searchcore/src/vespa/searchcore/proton/reference/i_document_db_reference_resolver.h
index 7e5b26ac34c..0aa44539f22 100644
--- a/searchcore/src/vespa/searchcore/proton/reference/i_document_db_reference_resolver.h
+++ b/searchcore/src/vespa/searchcore/proton/reference/i_document_db_reference_resolver.h
@@ -4,7 +4,7 @@
#include <vespa/fastos/timestamp.h>
#include <memory>
-namespace search { class IAttributeManager; }
+namespace search { class IAttributeManager; class IDocumentMetaStoreContext; }
namespace proton {
@@ -17,6 +17,7 @@ struct IDocumentDBReferenceResolver {
virtual ~IDocumentDBReferenceResolver() {}
virtual std::unique_ptr<ImportedAttributesRepo> resolve(const search::IAttributeManager &newAttrMgr,
const search::IAttributeManager &oldAttrMgr,
+ const std::shared_ptr<search::IDocumentMetaStoreContext> &documentMetaStore,
fastos::TimeStamp visibilityDelay) = 0;
virtual void teardown(const search::IAttributeManager &oldAttrMgr) = 0;
};
diff --git a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp
index 03ada12c4f2..e7e6c213eb2 100644
--- a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp
+++ b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp
@@ -211,6 +211,7 @@ SearchableDocSubDBConfigurer::reconfigure(const DocumentDBConfig &newConfig,
if (params.shouldAttributeManagerChange()) {
IAttributeManager::SP newAttrMgr = attrMgr->create(attrSpec);
newAttrMgr->setImportedAttributes(resolver.resolve(*newAttrMgr, *attrMgr,
+ searchView->getDocumentMetaStore(),
newConfig.getMaintenanceConfigSP()->getVisibilityDelay()));
IAttributeManager::SP oldAttrMgr = attrMgr;
attrMgr = newAttrMgr;
diff --git a/searchlib/src/tests/attribute/bitvector_search_cache/bitvector_search_cache_test.cpp b/searchlib/src/tests/attribute/bitvector_search_cache/bitvector_search_cache_test.cpp
index 1f738a209df..0072f83bc54 100644
--- a/searchlib/src/tests/attribute/bitvector_search_cache/bitvector_search_cache_test.cpp
+++ b/searchlib/src/tests/attribute/bitvector_search_cache/bitvector_search_cache_test.cpp
@@ -3,6 +3,7 @@
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/searchlib/attribute/bitvector_search_cache.h>
#include <vespa/searchlib/common/bitvector.h>
+#include <vespa/searchlib/common/i_document_meta_store_context.h>
using namespace search;
using namespace search::attribute;
@@ -13,7 +14,7 @@ using Entry = BitVectorSearchCache::Entry;
Entry::SP
makeEntry()
{
- return std::make_shared<Entry>(BitVector::create(5), 10);
+ return std::make_shared<Entry>(IDocumentMetaStoreContext::IReadGuard::UP(), BitVector::create(5), 10);
}
struct Fixture {
diff --git a/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp b/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
index f6ab6bb50bf..4ab0ed878cf 100644
--- a/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
+++ b/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
@@ -370,7 +370,7 @@ makeSearchCacheEntry(const std::vector<uint32_t> docIds, uint32_t docIdLimit)
for (uint32_t docId : docIds) {
bitVector->setBit(docId);
}
- return std::make_shared<BitVectorSearchCache::Entry>(bitVector, docIdLimit);
+ return std::make_shared<BitVectorSearchCache::Entry>(IDocumentMetaStoreContext::IReadGuard::UP(), bitVector, docIdLimit);
}
TEST_F("Bit vector from search cache is used if found", SearchCacheFixture)
@@ -382,6 +382,7 @@ TEST_F("Bit vector from search cache is used if found", SearchCacheFixture)
TermFieldMatchData match;
auto iter = f.create_strict_iterator(*ctx, match);
TEST_DO(f.assertSearch({2, 6}, *iter)); // Note: would be {3, 5} if cache was not used
+ EXPECT_EQUAL(0u, f.document_meta_store->get_read_guard_cnt);
}
void
@@ -405,6 +406,7 @@ TEST_F("Entry is inserted into search cache if bit vector posting list is used",
auto cacheEntry = f.imported_attr->getSearchCache()->find("5678");
EXPECT_EQUAL(cacheEntry->docIdLimit, f.imported_attr->getNumDocs());
TEST_DO(assertBitVector({3, 5}, *cacheEntry->bitVector));
+ EXPECT_EQUAL(1u, f.document_meta_store->get_read_guard_cnt);
}
}
diff --git a/searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h b/searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h
index 73fb95e1752..a889120f8df 100644
--- a/searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h
+++ b/searchlib/src/vespa/searchlib/attribute/bitvector_search_cache.h
@@ -2,6 +2,7 @@
#pragma once
+#include <vespa/searchlib/common/i_document_meta_store_context.h>
#include <vespa/vespalib/stllike/hash_map.h>
#include <vespa/vespalib/stllike/string.h>
#include <memory>
@@ -21,13 +22,17 @@ namespace attribute {
class BitVectorSearchCache {
public:
using BitVectorSP = std::shared_ptr<BitVector>;
+ using ReadGuardUP = IDocumentMetaStoreContext::IReadGuard::UP;
struct Entry {
using SP = std::shared_ptr<Entry>;
+ // We need to keep a document meta store read guard to ensure that no lids that are cached
+ // in the bit vector are re-used until the guard is released.
+ ReadGuardUP dmsReadGuard;
BitVectorSP bitVector;
uint32_t docIdLimit;
- Entry(BitVectorSP bitVector_, uint32_t docIdLimit_)
- : bitVector(std::move(bitVector_)), docIdLimit(docIdLimit_) {}
+ Entry(ReadGuardUP dmsReadGuard_, BitVectorSP bitVector_, uint32_t docIdLimit_)
+ : dmsReadGuard(std::move(dmsReadGuard_)), bitVector(std::move(bitVector_)), docIdLimit(docIdLimit_) {}
};
private:
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp
index 9efac9ce541..a085e21d6ae 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp
@@ -14,10 +14,12 @@ ImportedAttributeVector::ImportedAttributeVector(
vespalib::stringref name,
std::shared_ptr<ReferenceAttribute> reference_attribute,
std::shared_ptr<AttributeVector> target_attribute,
+ std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
bool use_search_cache)
: _name(name),
_reference_attribute(std::move(reference_attribute)),
_target_attribute(std::move(target_attribute)),
+ _document_meta_store(std::move(document_meta_store)),
_search_cache(use_search_cache ? std::make_shared<BitVectorSearchCache>() :
std::shared_ptr<BitVectorSearchCache>())
{
@@ -26,10 +28,12 @@ ImportedAttributeVector::ImportedAttributeVector(
ImportedAttributeVector::ImportedAttributeVector(vespalib::stringref name,
std::shared_ptr<ReferenceAttribute> reference_attribute,
std::shared_ptr<AttributeVector> target_attribute,
+ std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
std::shared_ptr<BitVectorSearchCache> search_cache)
: _name(name),
_reference_attribute(std::move(reference_attribute)),
_target_attribute(std::move(target_attribute)),
+ _document_meta_store(std::move(document_meta_store)),
_search_cache(std::move(search_cache))
{
}
@@ -41,7 +45,7 @@ std::unique_ptr<ImportedAttributeVector>
ImportedAttributeVector::makeReadGuard(bool stableEnumGuard) const
{
return std::make_unique<ImportedAttributeVectorReadGuard>
- (getName(), getReferenceAttribute(), getTargetAttribute(), getSearchCache(), stableEnumGuard);
+ (getName(), getReferenceAttribute(), getTargetAttribute(), getDocumentMetaStore(), getSearchCache(), stableEnumGuard);
}
const vespalib::string& search::attribute::ImportedAttributeVector::getName() const {
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h
index c94eda3d4db..7d272c42d9e 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h
+++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h
@@ -11,6 +11,7 @@ namespace search {
class AttributeGuard;
class AttributeEnumGuard;
+class IDocumentMetaStoreContext;
namespace attribute {
@@ -32,10 +33,12 @@ public:
ImportedAttributeVector(vespalib::stringref name,
std::shared_ptr<ReferenceAttribute> reference_attribute,
std::shared_ptr<AttributeVector> target_attribute,
+ std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
bool use_search_cache);
ImportedAttributeVector(vespalib::stringref name,
std::shared_ptr<ReferenceAttribute> reference_attribute,
std::shared_ptr<AttributeVector> target_attribute,
+ std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
std::shared_ptr<BitVectorSearchCache> search_cache);
~ImportedAttributeVector();
@@ -72,6 +75,9 @@ public:
const std::shared_ptr<AttributeVector>& getTargetAttribute() const noexcept {
return _target_attribute;
}
+ const std::shared_ptr<IDocumentMetaStoreContext> &getDocumentMetaStore() const {
+ return _document_meta_store;
+ }
const std::shared_ptr<BitVectorSearchCache> &getSearchCache() const {
return _search_cache;
}
@@ -88,10 +94,11 @@ protected:
const common::BlobConverter * bc) const override;
- vespalib::string _name;
- std::shared_ptr<ReferenceAttribute> _reference_attribute;
- std::shared_ptr<AttributeVector> _target_attribute;
- std::shared_ptr<BitVectorSearchCache> _search_cache;
+ vespalib::string _name;
+ std::shared_ptr<ReferenceAttribute> _reference_attribute;
+ std::shared_ptr<AttributeVector> _target_attribute;
+ std::shared_ptr<IDocumentMetaStoreContext> _document_meta_store;
+ std::shared_ptr<BitVectorSearchCache> _search_cache;
};
} // attribute
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp
index 4eedb6ce915..2860769235d 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp
@@ -9,9 +9,11 @@ ImportedAttributeVectorReadGuard::ImportedAttributeVectorReadGuard(
vespalib::stringref name,
std::shared_ptr<ReferenceAttribute> reference_attribute,
std::shared_ptr<AttributeVector> target_attribute,
+ std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
std::shared_ptr<BitVectorSearchCache> search_cache,
bool stableEnumGuard)
- : ImportedAttributeVector(name, std::move(reference_attribute), std::move(target_attribute), std::move(search_cache)),
+ : ImportedAttributeVector(name, std::move(reference_attribute), std::move(target_attribute),
+ std::move(document_meta_store), std::move(search_cache)),
_referencedLids(),
_reference_attribute_guard(_reference_attribute),
_target_attribute_guard(stableEnumGuard ? std::shared_ptr<AttributeVector>() : _target_attribute),
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h
index 7b226d2556a..1937953df66 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h
+++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h
@@ -31,6 +31,7 @@ public:
ImportedAttributeVectorReadGuard(vespalib::stringref name,
std::shared_ptr<ReferenceAttribute> reference_attribute,
std::shared_ptr<AttributeVector> target_attribute,
+ std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
std::shared_ptr<BitVectorSearchCache> search_cache,
bool stableEnumGuard);
~ImportedAttributeVectorReadGuard();
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp b/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp
index d2dc52ec2c7..a21ecacccdb 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/imported_search_context.cpp
@@ -29,6 +29,8 @@ ImportedSearchContext::ImportedSearchContext(
_useSearchCache(_imported_attribute.getSearchCache().get() != nullptr),
_searchCacheLookup((_useSearchCache ? _imported_attribute.getSearchCache()->find(_queryTerm) :
std::shared_ptr<BitVectorSearchCache::Entry>())),
+ _dmsReadGuard((_useSearchCache && !_searchCacheLookup) ? imported_attribute.getDocumentMetaStore()->getReadGuard() :
+ std::unique_ptr<IDocumentMetaStoreContext::IReadGuard>()),
_reference_attribute(*_imported_attribute.getReferenceAttribute()),
_target_attribute(*_imported_attribute.getTargetAttribute()),
_target_search_context(_target_attribute.getSearch(std::move(term), params)),
@@ -36,6 +38,7 @@ ImportedSearchContext::ImportedSearchContext(
_merger(_reference_attribute.getCommittedDocIdLimit()),
_fetchPostingsDone(false)
{
+
}
ImportedSearchContext::~ImportedSearchContext() {
@@ -215,7 +218,8 @@ void
ImportedSearchContext::considerAddSearchCacheEntry()
{
if (_useSearchCache && _merger.hasBitVector()) {
- auto cacheEntry = std::make_shared<BitVectorSearchCache::Entry>(_merger.getBitVectorSP(), _merger.getDocIdLimit());
+ assert(_dmsReadGuard);
+ auto cacheEntry = std::make_shared<BitVectorSearchCache::Entry>(std::move(_dmsReadGuard), _merger.getBitVectorSP(), _merger.getDocIdLimit());
_imported_attribute.getSearchCache()->insert(_queryTerm, std::move(cacheEntry));
}
}
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_search_context.h b/searchlib/src/vespa/searchlib/attribute/imported_search_context.h
index 0f6f8125cf8..0ddca8c9fe5 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_search_context.h
+++ b/searchlib/src/vespa/searchlib/attribute/imported_search_context.h
@@ -6,6 +6,7 @@
#include "bitvector_search_cache.h"
#include <vespa/searchcommon/attribute/i_search_context.h>
#include <vespa/searchlib/attribute/posting_list_merger.h>
+#include <vespa/searchlib/common/i_document_meta_store_context.h>
#include <vespa/vespalib/util/arrayref.h>
namespace search::fef { class TermFieldMatchData; }
@@ -30,6 +31,7 @@ class ImportedSearchContext : public ISearchContext {
vespalib::string _queryTerm;
bool _useSearchCache;
BitVectorSearchCache::Entry::SP _searchCacheLookup;
+ IDocumentMetaStoreContext::IReadGuard::UP _dmsReadGuard;
const ReferenceAttribute& _reference_attribute;
const AttributeVector& _target_attribute;
std::unique_ptr<AttributeVector::SearchContext> _target_search_context;
diff --git a/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h
index 3620a1df725..f9e3de79144 100644
--- a/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h
+++ b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h
@@ -12,6 +12,7 @@
#include <vespa/searchlib/attribute/integerbase.h>
#include <vespa/searchlib/attribute/not_implemented_attribute.h>
#include <vespa/searchlib/attribute/stringbase.h>
+#include <vespa/searchlib/common/i_document_meta_store_context.h>
#include <vespa/searchlib/query/queryterm.h>
#include <vespa/searchcommon/attribute/attributecontent.h>
#include <vespa/vespalib/testkit/testapp.h>
@@ -23,6 +24,27 @@
#include <vector>
namespace search {
+
+struct MockDocumentMetaStoreContext : public IDocumentMetaStoreContext {
+
+ struct MockReadGuard : public IDocumentMetaStoreContext::IReadGuard {
+ virtual const search::IDocumentMetaStore &get() const override {
+ search::IDocumentMetaStore *nullStore = nullptr;
+ return static_cast<search::IDocumentMetaStore &>(*nullStore);
+ }
+ };
+
+ mutable size_t get_read_guard_cnt;
+
+ using SP = std::shared_ptr<MockDocumentMetaStoreContext>;
+ MockDocumentMetaStoreContext() : get_read_guard_cnt(0) {}
+
+ virtual IReadGuard::UP getReadGuard() const override {
+ ++get_read_guard_cnt;
+ return std::make_unique<MockReadGuard>();
+ }
+};
+
namespace attribute {
using document::DocumentId;
@@ -39,6 +61,10 @@ std::shared_ptr<ReferenceAttribute> create_reference_attribute(vespalib::stringr
return std::make_shared<ReferenceAttribute>(name, Config(BasicType::REFERENCE));
}
+MockDocumentMetaStoreContext::SP create_document_meta_store() {
+ return std::make_shared<MockDocumentMetaStoreContext>();
+}
+
enum class FastSearchConfig {
ExplicitlyEnabled,
Default
@@ -105,6 +131,7 @@ struct ImportedAttributeFixture {
bool use_search_cache;
std::shared_ptr<AttributeVector> target_attr;
std::shared_ptr<ReferenceAttribute> reference_attr;
+ MockDocumentMetaStoreContext::SP document_meta_store;
std::shared_ptr<ImportedAttributeVector> imported_attr;
std::shared_ptr<MockGidToLidMapperFactory> mapper_factory;
@@ -130,7 +157,7 @@ struct ImportedAttributeFixture {
std::shared_ptr<ImportedAttributeVector>
create_attribute_vector_from_members(vespalib::stringref name = default_imported_attr_name()) {
- return std::make_shared<ImportedAttributeVector>(name, reference_attr, target_attr, use_search_cache);
+ return std::make_shared<ImportedAttributeVector>(name, reference_attr, target_attr, document_meta_store, use_search_cache);
}
template<typename AttrVecType>
@@ -225,6 +252,7 @@ ImportedAttributeFixture::ImportedAttributeFixture(bool use_search_cache_)
: use_search_cache(use_search_cache_),
target_attr(create_single_attribute<IntegerAttribute>(BasicType::INT32)),
reference_attr(create_reference_attribute()),
+ document_meta_store(create_document_meta_store()),
imported_attr(create_attribute_vector_from_members()),
mapper_factory(std::make_shared<MockGidToLidMapperFactory>()) {
reference_attr->setGidToLidMapperFactory(mapper_factory);