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

#include "simpleflush.h"
#include <algorithm>
#include <cinttypes>

#include <vespa/log/log.h>
LOG_SETUP(".proton.server.simpleflush");

namespace proton {

SimpleFlush::SimpleFlush() = default;

FlushContext::List
SimpleFlush::getFlushTargets(const FlushContext::List& targetList,
                             const flushengine::TlsStatsMap&,
                             const flushengine::ActiveFlushStats&) const
{
    FlushContext::List fv(targetList);
    std::sort(fv.begin(), fv.end(), CompareTarget());
    return fv;
}

bool
SimpleFlush::CompareTarget::compare(const IFlushTarget & lhs, const IFlushTarget & rhs) const
{
    IFlushTarget::MemoryGain lhsMgain(lhs.getApproxMemoryGain());
    IFlushTarget::SerialNum lhsSerial(lhs.getFlushedSerialNum());

    IFlushTarget::MemoryGain rhsMgain(rhs.getApproxMemoryGain());
    IFlushTarget::SerialNum rhsSerial(rhs.getFlushedSerialNum());


    bool ret = lhsSerial < rhsSerial;
    LOG(spam, "SimpleFlush::compare("
        "[name = '%s', before = %" PRIu64 ", after = %" PRIu64 ", serial = %" PRIu64 "], "
        "[name = '%s', before = %" PRIu64 ", after = %" PRIu64 ", serial = %" PRIu64 "]) => %d",
        lhs.getName().c_str(), lhsMgain.getBefore(), lhsMgain.getAfter(), lhsSerial,
        rhs.getName().c_str(), rhsMgain.getBefore(), rhsMgain.getAfter(), rhsSerial,
        ret ? 1 : 0);
    return ret;
}

} // namespace proton