aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/reference/gid_to_lid_change_listener.cpp
blob: 7767fc206190575f4e05b1fcbbc9c14a2ecd72c4 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "gid_to_lid_change_listener.h"
#include <vespa/vespalib/util/gate.h>
#include <future>

using vespalib::RetainGuard;

namespace proton {

GidToLidChangeListener::GidToLidChangeListener(vespalib::ISequencedTaskExecutor & executor,
                                               std::shared_ptr<search::attribute::ReferenceAttribute> attr,
                                               RetainGuard retainGuard,
                                               const vespalib::string &name,
                                               const vespalib::string &docTypeName)
    : _executor(executor),
      _executorId(_executor.getExecutorIdFromName(attr->getNamePrefix())),
      _attr(std::move(attr)),
      _retainGuard(std::move(retainGuard)),
      _name(name),
      _docTypeName(docTypeName)
{ }

GidToLidChangeListener::~GidToLidChangeListener()
{
    vespalib::Gate gate;
    _executor.executeLambda(_executorId, [&gate]() { gate.countDown(); });
    gate.await();
}

void
GidToLidChangeListener::notifyPutDone(IDestructorCallbackSP context, document::GlobalId gid, uint32_t lid)
{
    _executor.executeLambda(_executorId,
                            [this, context=std::move(context), gid, lid]() {
                                            (void) context;
                                            _attr->notifyReferencedPut(gid, lid);
                                        });
}

void
GidToLidChangeListener::notifyRemove(IDestructorCallbackSP context, document::GlobalId gid)
{
    _executor.executeLambda(_executorId,
                            [this, context = std::move(context), gid]() {
                                            (void) context;
                                            _attr->notifyReferencedRemove(gid);
                                        });
}

void
GidToLidChangeListener::notifyRegistered(const std::vector<document::GlobalId>& removes)
{
    std::promise<void> promise;
    auto future = promise.get_future();
    _executor.executeLambda(_executorId,
                            [this, &promise, removes(std::move(removes))]() {
                                            _attr->populateTargetLids(removes);
                                            promise.set_value();
                                        });
    future.wait();
}

const vespalib::string &
GidToLidChangeListener::getName() const
{
    return _name;
}

const vespalib::string &
GidToLidChangeListener::getDocTypeName() const
{
    return _docTypeName;
}

} // namespace proton