summaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/attribute/filter_attribute_manager.h
blob: 9d09aef8faf858f0cef6b152af4b1497d25e5ac5 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "i_attribute_manager.h"
#include <set>

namespace proton {

/**
 * An attribute manager that wraps another attribute manager and only gives access to a
 * subset of the attribute vectors in the wrapped manager.
 *
 * This manager only implements the subset of functions needed when used by
 * and attribute writer in the context of an attribute populator.
 */
class FilterAttributeManager : public IAttributeManager
{
public:
    typedef std::set<vespalib::string> AttributeSet;

private:
    AttributeSet          _acceptedAttributes;
    IAttributeManager::SP _mgr;
    std::vector<search::AttributeVector *> _acceptedWritableAttributes;

    bool acceptAttribute(const vespalib::string &name) const;

public:
    FilterAttributeManager(const AttributeSet &acceptedAttributes,
                           IAttributeManager::SP mgr);
    ~FilterAttributeManager() override;

    // Implements search::IAttributeManager
    search::AttributeGuard::UP getAttribute(const vespalib::string &name) const override;
    void getAttributeList(std::vector<search::AttributeGuard> &list) const override;
    search::SerialNum getFlushedSerialNum(const vespalib::string &name) const override;
    search::attribute::IAttributeContext::UP createContext() const override;
    std::unique_ptr<search::attribute::AttributeReadGuard> getAttributeReadGuard(const vespalib::string &name, bool stableEnumGuard) const override;

    // Implements proton::IAttributeManager
    IAttributeManager::SP create(const AttributeCollectionSpec &) const override;
    std::vector<searchcorespi::IFlushTarget::SP> getFlushTargets() const override;
    search::SerialNum getOldestFlushedSerialNumber() const override;
    search::SerialNum getNewestFlushedSerialNumber() const override;
    void getAttributeListAll(std::vector<search::AttributeGuard> &) const override;
    void pruneRemovedFields(search::SerialNum serialNum) override;
    const IAttributeFactory::SP &getFactory() const override;
    vespalib::ISequencedTaskExecutor & getAttributeFieldWriter() const override;
    vespalib::ThreadExecutor& get_shared_executor() const override;

    search::AttributeVector * getWritableAttribute(const vespalib::string &name) const override;
    const std::vector<search::AttributeVector *> & getWritableAttributes() const override;
    void asyncForEachAttribute(std::shared_ptr<IConstAttributeFunctor> func) const override;
    ExclusiveAttributeReadAccessor::UP getExclusiveReadAccessor(const vespalib::string &name) const override;
    void setImportedAttributes(std::unique_ptr<ImportedAttributesRepo> attributes) override;
    const ImportedAttributesRepo *getImportedAttributes() const override;
    std::shared_ptr<search::attribute::ReadableAttributeVector> readable_attribute_vector(const string& name) const override;

    void asyncForAttribute(const vespalib::string &name, std::unique_ptr<IAttributeFunctor> func) const override;
};

} // namespace proton