aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/flushengine/threadedflushtarget.h
blob: 888585e8ad62793aa0ff108d951ddaa7156a042d (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "flushtargetproxy.h"

namespace vespalib { class Executor; }

namespace proton {

class IGetSerialNum;

/**
 * Implements a flush target that runs initFlush() as a task in the given
 * executor. This is used by the DocumentDB to ensure that initFlush() in the
 * underlying flush targets are run in the updater thread.
 */
class ThreadedFlushTarget : public FlushTargetProxy
{
private:
    using IFlushTarget = searchcorespi::IFlushTarget;
    vespalib::Executor  &_executor;
    const IGetSerialNum &_getSerialNum;

public:
    /**
     * Constructs a new instance of this class. If the argument executor is
     * the same as the one calling initFlush() on this object, make sure
     * that it has more than 1 thread to avoid a deadlock.
     *
     * @param executor The executor to submit the task to.
     * @param target   The target to decorate.
     */
    ThreadedFlushTarget(vespalib::Executor &executor,
                        const IGetSerialNum &getSerialNum,
                        const IFlushTarget::SP &target);

    /**
     * Constructs a new instance of this class. If the argument executor is
     * the same as the one calling initFlush() on this object, make sure
     * that it has more than 1 thread to avoid a deadlock.
     *
     * @param executor The executor to submit the task to.
     * @param target   The target to decorate.
     * @param prefix   The prefix to prepend to the target
     */
    ThreadedFlushTarget(vespalib::Executor &executor,
                        const IGetSerialNum &getSerialNum,
                        const IFlushTarget::SP &target,
                        const vespalib::string & prefix);

    Task::UP initFlush(SerialNum currentSerial, std::shared_ptr<search::IFlushToken> flush_token) override;
};

} // namespace proton