summaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/fast_access_feed_view.cpp
blob: 485a03276a596b2c08d81146e990713ff2a7bee7 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "fast_access_feed_view.h"
#include "forcecommitcontext.h"
#include "operationdonecontext.h"
#include "removedonecontext.h"
#include "putdonecontext.h"

using document::Document;
using document::DocumentUpdate;
using document::FieldUpdate;
using search::index::Schema;

namespace proton {

FastAccessFeedView::UpdateScope
FastAccessFeedView::getUpdateScope(const DocumentUpdate &upd)
{
    UpdateScope updateScope;
    for (const auto &update : upd.getUpdates()) {
        const vespalib::string &fieldName = update.getField().getName();
        if (!fastPartialUpdateAttribute(fieldName)) {
            updateScope._nonAttributeFields = true;
            break;
        }
    }
    if (!upd.getFieldPathUpdates().empty()) {
        updateScope._nonAttributeFields = true;
    }
    return updateScope;
}

/**
 * NOTE: For both put, update and remove we only need to pass the 'onWriteDone'
 * instance when we are going to commit as part of handling the operation.
 * Otherwise we can drop it and ack the operation right away.
 */
void
FastAccessFeedView::putAttributes(SerialNum serialNum,
                                  search::DocumentIdT lid,
                                  const Document &doc,
                                  bool immediateCommit,
                                  OnPutDoneType onWriteDone)
{
    _attributeWriter->put(serialNum, doc, lid, immediateCommit, onWriteDone);
    if (immediateCommit && onWriteDone) {
        onWriteDone->registerPutLid(lid, &_docIdLimit);
    }
}

void
FastAccessFeedView::updateAttributes(SerialNum serialNum,
                                     search::DocumentIdT lid,
                                     const DocumentUpdate &upd,
                                     bool immediateCommit,
                                     OnOperationDoneType onWriteDone)
{
    _attributeWriter->update(serialNum, upd, lid, immediateCommit, onWriteDone);
}

void
FastAccessFeedView::removeAttributes(SerialNum serialNum,
                                     search::DocumentIdT lid,
                                     bool immediateCommit,
                                     OnRemoveDoneType onWriteDone)
{
    _attributeWriter->remove(serialNum, lid, immediateCommit, onWriteDone);
}

void
FastAccessFeedView::removeAttributes(SerialNum serialNum,
                                     const LidVector &lidsToRemove,
                                     bool immediateCommit,
                                     OnWriteDoneType onWriteDone)
{
    _attributeWriter->remove(lidsToRemove, serialNum, immediateCommit, onWriteDone);
}

void
FastAccessFeedView::heartBeatAttributes(SerialNum serialNum)
{
    _attributeWriter->heartBeat(serialNum);
}

FastAccessFeedView::FastAccessFeedView(const StoreOnlyFeedView::Context &storeOnlyCtx,
                                       const PersistentParams &params,
                                       const Context &ctx)
    : Parent(storeOnlyCtx, params),
      _attributeWriter(ctx._attrWriter),
      _docIdLimit(ctx._docIdLimit)
{}

FastAccessFeedView::~FastAccessFeedView() {}

void
FastAccessFeedView::handleCompactLidSpace(const CompactLidSpaceOperation &op)
{
    // Drain pending PutDoneContext and ForceCommitContext objects
    _writeService.sync();
    _docIdLimit.set(op.getLidLimit());
    getAttributeWriter()->compactLidSpace(op.getLidLimit(), op.getSerialNum());
    Parent::handleCompactLidSpace(op);
}

void
FastAccessFeedView::forceCommit(SerialNum serialNum,
                                OnForceCommitDoneType onCommitDone)
{
    _attributeWriter->commit(serialNum, onCommitDone);
    onCommitDone->registerCommittedDocIdLimit(_metaStore.getCommittedDocIdLimit(), &_docIdLimit);
    Parent::forceCommit(serialNum, onCommitDone);
}


void
FastAccessFeedView::sync()
{
    _writeService.attributeFieldWriter().sync();
    _writeService.summary().sync();
}


} // namespace proton