blob: 4ceee985f59f440bc75a636fa5a11d475f60cd29 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "iflushhandler.h"
#include <vespa/vespalib/util/executor.h>
namespace proton {
/**
* This class is used by FlushEngine to hold the necessary context for flushing
* a single IFlushTarget.
*/
class FlushContext {
private:
using IFlushTarget = searchcorespi::IFlushTarget;
vespalib::string _name;
IFlushHandler::SP _handler;
IFlushTarget::SP _target;
searchcorespi::FlushTask::UP _task;
search::SerialNum _lastSerial;
public:
using SP = std::shared_ptr<FlushContext>;
using List = std::vector<SP>;
FlushContext(const FlushContext &) = delete;
FlushContext & operator = (const FlushContext &) = delete;
/**
* Create a name of the handler and the target.
*
* @param handler The flush handler that contains the given target.
* @param target The target to flush.
* @return the name created.
*/
static vespalib::string createName(const IFlushHandler & handler, const IFlushTarget & target);
/**
* Create a combined name of the handler name and the target name.
*/
static vespalib::string create_name(const vespalib::string& handler_name,
const vespalib::string& target_name);
/**
* Constructs a new instance of this class.
*
* @param handler The flush handler that contains the given target.
* @param target The target to flush.
*/
FlushContext(const IFlushHandler::SP &handler,
const IFlushTarget::SP &target,
search::SerialNum lastSerial);
/**
* Destructor. Will log a warning if it contains an unexecuted task.
*/
~FlushContext();
/**
* This method proxies initFlush() in IFlushTarget, but simplifies the call
* signature. If this method returns true, the task to complete the flush is
* available through getTask().
*
* @return True if a flush was initiated.
*/
bool initFlush(std::shared_ptr<search::IFlushToken> flush_token);
/**
* Returns the unique name of this context. This is the concatenation of the
* handler and target names.
*
* @return The name of this.
*/
const vespalib::string & getName() const { return _name; }
/**
* Returns the flush handler of this context.
*
* @return The handler.
*/
const IFlushHandler::SP & getHandler() const { return _handler; }
/**
* Returns the flush target of this context.
*
* @return The target.
*/
const IFlushTarget::SP & getTarget() const { return _target; }
/**
* Returns the last serial number.
*
* @return The last serial number
*/
search::SerialNum getLastSerial() const { return _lastSerial; }
/**
* Returns the task required to be run to complete an initiated flush. This
* is null until initFlush() has been called.
*
* @return The flush completion task.
*/
searchcorespi::FlushTask::UP getTask() { return std::move(_task); }
};
} // namespace proton
|