forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gossip_digest.hh
73 lines (60 loc) · 1.76 KB
/
gossip_digest.hh
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
/*
*
* Modified by ScyllaDB
* Copyright (C) 2015-present ScyllaDB
*/
/*
* SPDX-License-Identifier: (AGPL-3.0-or-later and Apache-2.0)
*/
#pragma once
#include <seastar/core/sstring.hh>
#include "utils/serialization.hh"
#include "gms/inet_address.hh"
namespace gms {
/**
* Contains information about a specified list of Endpoints and the largest version
* of the state they have generated as known by the local endpoint.
*/
class gossip_digest { // implements Comparable<GossipDigest>
private:
using inet_address = gms::inet_address;
inet_address _endpoint;
int32_t _generation;
int32_t _max_version;
public:
gossip_digest()
: _endpoint(0)
, _generation(0)
, _max_version(0) {
}
gossip_digest(inet_address ep, int32_t gen, int32_t version)
: _endpoint(ep)
, _generation(gen)
, _max_version(version) {
}
inet_address get_endpoint() const {
return _endpoint;
}
int32_t get_generation() const {
return _generation;
}
int32_t get_max_version() const {
return _max_version;
}
int32_t compare_to(gossip_digest d) const {
if (_generation != d.get_generation()) {
return (_generation - d.get_generation());
}
return (_max_version - d.get_max_version());
}
friend bool operator<(const gossip_digest& x, const gossip_digest& y) {
if (x._generation != y._generation) {
return x._generation < y._generation;
}
return x._max_version < y._max_version;
}
friend inline std::ostream& operator<<(std::ostream& os, const gossip_digest& d) {
return os << d._endpoint << ":" << d._generation << ":" << d._max_version;
}
}; // class gossip_digest
} // namespace gms