aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/datastore/compaction_strategy.cpp
blob: eea49e801350b17535573ad55914549a9fd44491 (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 "compaction_strategy.h"
#include "compaction_spec.h"
#include <vespa/vespalib/util/memoryusage.h>
#include <vespa/vespalib/util/address_space.h>
#include <iostream>
#include <limits>

namespace vespalib::datastore {

bool
CompactionStrategy::should_compact_memory(const MemoryUsage& memory_usage) const noexcept
{
    return should_compact_memory(memory_usage.usedBytes(), memory_usage.deadBytes());
}

bool
CompactionStrategy::should_compact_address_space(const AddressSpace& address_space) const noexcept
{
    return should_compact_address_space(address_space.used(), address_space.dead());
}

CompactionSpec
CompactionStrategy::should_compact(const MemoryUsage& memory_usage, const AddressSpace& address_space) const noexcept
{
    return CompactionSpec(should_compact_memory(memory_usage), should_compact_address_space(address_space));
}

std::ostream& operator<<(std::ostream& os, const CompactionStrategy& compaction_strategy)
{
    os << "{maxDeadBytesRatio=" << compaction_strategy.getMaxDeadBytesRatio() <<
        ", maxDeadAddressSpaceRatio=" << compaction_strategy.getMaxDeadAddressSpaceRatio() <<
        "}";
    return os;
}

CompactionStrategy
CompactionStrategy::make_compact_all_active_buffers_strategy() noexcept
{
    return CompactionStrategy(0.0, 0.0, std::numeric_limits<uint32_t>::max(), 1.0);
}

}