forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrack_inferring_snitch.hh
48 lines (37 loc) · 1.22 KB
/
rack_inferring_snitch.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
/*
*
* 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 "gms/inet_address.hh"
#include "snitch_base.hh"
#include "utils/fb_utilities.hh"
namespace locator {
using inet_address = gms::inet_address;
/**
* A simple endpoint snitch implementation that assumes datacenter and rack information is encoded
* in the 2nd and 3rd octets of the ip address, respectively.
*/
struct rack_inferring_snitch : public snitch_base {
rack_inferring_snitch() {
_my_dc = get_datacenter(utils::fb_utilities::get_broadcast_address());
_my_rack = get_rack(utils::fb_utilities::get_broadcast_address());
// This snitch is ready on creation
set_snitch_ready();
}
virtual sstring get_rack(inet_address endpoint) override {
return std::to_string(uint8_t(endpoint.bytes()[2]));
}
virtual sstring get_datacenter(inet_address endpoint) override {
return std::to_string(uint8_t(endpoint.bytes()[1]));
}
virtual sstring get_name() const override {
return "org.apache.cassandra.locator.RackInferringSnitch";
}
};
} // namespace locator