aboutsummaryrefslogtreecommitdiffstats
path: root/slobrok/src/vespa/slobrok/server/map_diff.h
blob: 57dde5cc1f4dc5c12f9f0f98f6b3159e102e66e1 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/vespalib/util/gencnt.h>
#include "service_mapping.h"

namespace slobrok {

/**
 * represents an incremental update to a name->spec map,
 * or optionally a full dump of it.
 **/
struct MapDiff {
    /** construct incremental diff */
    MapDiff(const vespalib::GenCnt &from,
            std::vector<vespalib::string> remove,
            ServiceMappingList update,
            const vespalib::GenCnt &to)
      : fromGen(from),
        removed(std::move(remove)),
        updated(std::move(update)),
        toGen(to)
    {}

    /** construct full map dump */
    MapDiff(ServiceMappingList mappings,
            const vespalib::GenCnt &to)
      : MapDiff(0, {}, std::move(mappings), to)
    {}

    MapDiff(MapDiff &&) noexcept;
    ~MapDiff();

    // is this a diff from the empty map:
    bool is_full_dump() const { return fromGen == vespalib::GenCnt(0); }

    // which generation this diff goes from:
    vespalib::GenCnt fromGen;

    // names to remove (empty if is_full_dump):
    std::vector<vespalib::string> removed;

    // name->spec pairs to add or update:
    ServiceMappingList updated;

    // which generation this diff brings you to:
    vespalib::GenCnt toGen;
};

} // namespace slobrok