aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp
blob: f6a33165f0c96640d45beeeaa9670710ff2dfc82 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "imported_attribute_vector.h"
#include "imported_attribute_vector_read_guard.h"
#include "imported_search_context.h"
#include <vespa/vespalib/util/memoryusage.h>

namespace search::attribute {

ImportedAttributeVector::ImportedAttributeVector(
            vespalib::stringref name,
            std::shared_ptr<ReferenceAttribute> reference_attribute,
            std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
            std::shared_ptr<ReadableAttributeVector> target_attribute,
            std::shared_ptr<const IDocumentMetaStoreContext> target_document_meta_store,
            bool use_search_cache)
    : _name(name),
      _reference_attribute(std::move(reference_attribute)),
      _document_meta_store(std::move(document_meta_store)),
      _target_attribute(std::move(target_attribute)),
      _target_document_meta_store(std::move(target_document_meta_store)),
      _search_cache(use_search_cache ? std::make_shared<BitVectorSearchCache>() :
                    std::shared_ptr<BitVectorSearchCache>())
{
}

ImportedAttributeVector::ImportedAttributeVector(vespalib::stringref name,
                                                 std::shared_ptr<ReferenceAttribute> reference_attribute,
                                                 std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
                                                 std::shared_ptr<ReadableAttributeVector> target_attribute,
                                                 std::shared_ptr<const IDocumentMetaStoreContext> target_document_meta_store,
                                                 std::shared_ptr<BitVectorSearchCache> search_cache)
    : _name(name),
      _reference_attribute(std::move(reference_attribute)),
      _document_meta_store(std::move(document_meta_store)),
      _target_attribute(std::move(target_attribute)),
      _target_document_meta_store(std::move(target_document_meta_store)),
      _search_cache(std::move(search_cache))
{
}

ImportedAttributeVector::~ImportedAttributeVector() = default;

std::unique_ptr<AttributeReadGuard>
ImportedAttributeVector::makeReadGuard(bool stableEnumGuard) const
{
    return makeReadGuard(_target_document_meta_store->getReadGuard(), stableEnumGuard);
}

std::unique_ptr<AttributeReadGuard>
ImportedAttributeVector::makeReadGuard(std::shared_ptr<MetaStoreReadGuard> targetMetaStoreReadGuard,  bool stableEnumGuard) const
{
    return std::make_unique<ImportedAttributeVectorReadGuard>(std::move(targetMetaStoreReadGuard), *this, stableEnumGuard);
}

void ImportedAttributeVector::clearSearchCache() {
    if (_search_cache) {
        _search_cache->clear();
    }
}

vespalib::MemoryUsage
ImportedAttributeVector::get_memory_usage() const
{
    constexpr auto self_memory_usage = sizeof(ImportedAttributeVector);
    vespalib::MemoryUsage result(self_memory_usage, self_memory_usage, 0, 0);
    if (_search_cache) {
        result.merge(_search_cache->get_memory_usage());
    }
    return result;
}

}