aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/bmcluster/bm_node_stats.cpp
blob: 1f1671f6b8686d69d03055dd6ce629066d994ea6 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "bm_node_stats.h"
#include <cassert>

namespace search::bmcluster {

namespace {

template <class Stats>
void merge(std::optional<Stats> &lhs, const Stats &rhs)
{
    if (lhs) {
        auto value = lhs.value();
        value += rhs;
        lhs = value;
    } else {
        lhs = rhs;
    }
}

template <class Stats>
void merge(std::optional<Stats> &lhs, const std::optional<Stats> &rhs)
{
    if (rhs) {
        merge(lhs, rhs.value());
    }
}

}

BmNodeStats::BmNodeStats()
    : _buckets(),
      _document_db(),
      _merges()
{
}


BmNodeStats::~BmNodeStats() = default;

BmNodeStats&
BmNodeStats::operator+=(const BmNodeStats& rhs)
{
    merge(_buckets, rhs._buckets);
    merge(_document_db, rhs._document_db);
    merge(_merges, rhs._merges);
    return *this;
}

bool
BmNodeStats::operator==(const BmNodeStats &rhs) const
{
    return ((_buckets == rhs._buckets) &&
            (_document_db == rhs._document_db) &&
            (_merges == rhs._merges));
}

void
BmNodeStats::set_document_db_stats(const BmDocumentDbStats &document_db)
{
    assert(!_document_db);
    _document_db = document_db;
}

void
BmNodeStats::merge_bucket_stats(const BmBucketsStats &buckets)
{
    merge(_buckets, buckets);
}

void
BmNodeStats::set_merge_stats(const BmMergeStats &merges)
{
    assert(!_merges);
    _merges = merges;
}

}