blob: e2bf97837106abfac2f6cd0fbd1dae2bd2897ff7 (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/searchcorespi/flush/iflushtarget.h>
namespace proton {
/**
* Implements a flush target that caches the flushable memory and flush cost of
* a decorated target. This is used by the flush engine to avoid recalculating
* these during selection of flush target.
*/
class CachedFlushTarget : public searchcorespi::IFlushTarget {
private:
using FlushStats = searchcorespi::FlushStats;
using IFlushTarget = searchcorespi::IFlushTarget;
IFlushTarget::SP _target;
SerialNum _flushedSerialNum;
Time _lastFlushTime;
MemoryGain _memoryGain;
DiskGain _diskGain;
bool _needUrgentFlush;
uint64_t _approxBytesToWriteToDisk;
public:
/**
* Constructs a new instance of this class. This will immediately call
* getFlushableMemory(), getFlushCost() and getLowSerialNum() on the
* argument target.
*
* @param target The target to decorate.
*/
CachedFlushTarget(const IFlushTarget::SP &target);
/**
* Returns the decorated flush target. This should not be used for anything
* but testing, as invoking a method on the returned target beats the
* purpose of decorating it.
*
* @return The decorated flush target.
*/
const IFlushTarget::SP & getFlushTarget() { return _target; }
// Implements IFlushTarget.
virtual MemoryGain getApproxMemoryGain() const override { return _memoryGain; }
virtual DiskGain getApproxDiskGain() const override { return _diskGain; }
virtual SerialNum getFlushedSerialNum() const override { return _flushedSerialNum; }
virtual Time getLastFlushTime() const override { return _lastFlushTime; }
virtual bool needUrgentFlush() const override { return _needUrgentFlush; }
virtual Task::UP initFlush(SerialNum currentSerial) override { return _target->initFlush(currentSerial); }
virtual FlushStats getLastFlushStats() const override { return _target->getLastFlushStats(); }
virtual uint64_t getApproxBytesToWriteToDisk() const override;
};
} // namespace proton
|