aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/attribute/i_attribute_writer.h
blob: 591383dc4d51eb041927451e3877ae74a4472b69 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "i_attribute_manager.h"
#include <vespa/searchcore/proton/feedoperation/lidvectorcontext.h>
#include <vespa/searchlib/attribute/attributeguard.h>
#include <vespa/searchlib/query/base.h>
#include <vespa/searchlib/common/commit_param.h>

namespace vespalib { class IDestructorCallback; }
namespace document {
    class DocumentUpdate;
    class Document;
}

namespace proton {

struct IFieldUpdateCallback;

/**
 * Interface for an attribute writer that handles writes in form of put, update and remove
 * to an underlying set of attribute vectors.
 */
class IAttributeWriter {
public:
    using UP = std::unique_ptr<IAttributeWriter>;
    using SP = std::shared_ptr<IAttributeWriter>;
    using LidVector = LidVectorContext::LidVector;
    using SerialNum = search::SerialNum;
    using CommitParam = search::CommitParam;
    using DocumentIdT = search::DocumentIdT;
    using DocumentUpdate = document::DocumentUpdate;
    using Document = document::Document;
    using OnWriteDoneType = const std::shared_ptr<vespalib::IDestructorCallback> &;

    virtual ~IAttributeWriter() = default;

    virtual std::vector<search::AttributeVector *> getWritableAttributes() const = 0;
    virtual search::AttributeVector *getWritableAttribute(const vespalib::string &attrName) const = 0;
    virtual void put(SerialNum serialNum, const Document &doc, DocumentIdT lid, OnWriteDoneType onWriteDone) = 0;
    virtual void remove(SerialNum serialNum, DocumentIdT lid, OnWriteDoneType onWriteDone) = 0;
    virtual void remove(const LidVector &lidVector, SerialNum serialNum, OnWriteDoneType onWriteDone) = 0;
    /**
     * Update the underlying attributes based on the content of the given DocumentUpdate.
     * The OnWriteDoneType instance should ensure the lifetime of the given DocumentUpdate instance.
     */
    virtual void update(SerialNum serialNum, const DocumentUpdate &upd, DocumentIdT lid,
                        OnWriteDoneType onWriteDone, IFieldUpdateCallback & onUpdate) = 0;
    /*
     * Update the underlying struct field attributes based on updated document.
     */
    virtual void update(SerialNum serialNum, const Document &doc, DocumentIdT lid, OnWriteDoneType onWriteDone) = 0;
    virtual void heartBeat(SerialNum serialNum, OnWriteDoneType onDone) = 0;
    /**
     * Compact the lid space of the underlying attribute vectors.
     */
    virtual void compactLidSpace(uint32_t wantedLidLimit, SerialNum serialNum) = 0;
    virtual const proton::IAttributeManager::SP &getAttributeManager() const = 0;

    /**
     * Commit all underlying attribute vectors with the given param.
     */
    virtual void forceCommit(const CommitParam & param, OnWriteDoneType onWriteDone) = 0;

    virtual void onReplayDone(uint32_t docIdLimit) = 0;
    virtual bool hasStructFieldAttribute() const = 0;
    virtual void drain(OnWriteDoneType onWriteDone) = 0;
};

} // namespace proton