aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/flushengine/flushcontext.cpp
blob: 156b0c70d637f00c4b5c09d0bc48af8ef3fb5835 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "flushcontext.h"

#include <vespa/log/log.h>
LOG_SETUP(".proton.flushengine.flushcontext");

namespace proton {

FlushContext::FlushContext(
        const IFlushHandler::SP &handler,
        const IFlushTarget::SP &target,
        search::SerialNum lastSerial)
    : _name(createName(*handler, *target)),
      _handler(handler),
      _target(target),
      _task(),
      _lastSerial(lastSerial)
{ }

vespalib::string
FlushContext::createName(const IFlushHandler & handler, const IFlushTarget & target) {
    return create_name(handler.getName(), target.getName());
}

vespalib::string
FlushContext::create_name(const vespalib::string& handler_name,
                          const vespalib::string& target_name) {
    return (handler_name + "." + target_name);
}

FlushContext::~FlushContext()
{
    if (_task) {
        LOG(warning, "Unexecuted flush task for '%s' destroyed.", _name.c_str());
    }
}

bool
FlushContext::initFlush(std::shared_ptr<search::IFlushToken> flush_token)
{
    LOG(debug, "Attempting to flush '%s'.", _name.c_str());
    _task = _target->initFlush(std::max(_handler->getCurrentSerialNumber(), _lastSerial), std::move(flush_token));
    if ( ! _task ) {
        LOG(debug, "Target refused to init flush.");
        return false;
    }
    return true;
}

}