forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgossiping_property_file_snitch.hh
143 lines (122 loc) · 4.26 KB
/
gossiping_property_file_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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Modified by Cloudius Systems.
* Copyright 2015 Cloudius Systems.
*/
#pragma once
#include <sstream>
#include <string>
#include <chrono>
#include <boost/algorithm/string.hpp>
#include <experimental/optional>
#include "production_snitch_base.hh"
#include "exceptions/exceptions.hh"
#include "service/storage_service.hh"
#include "core/file.hh"
#include "log.hh"
namespace locator {
class bad_property_file_error : public std::exception {};
/**
* cassandra-rackdc.properties file has the following format:
*
* dc=<Data Center name>
* rack=<Rack name>
* prefer_local=<true|false>
*/
class gossiping_property_file_snitch : public production_snitch_base {
public:
static constexpr const char* snitch_properties_filename = "cassandra-rackdc.properties";
// Check the property file for changes every 60s.
static constexpr timer<>::duration reload_property_file_period() {
return std::chrono::seconds(60);
}
virtual void gossiper_starting() override;
virtual future<> stop() override;
private:
template <typename SnitchClass, typename... A>
friend future<snitch_ptr> make_snitch(A&&... a);
gossiping_property_file_snitch(
const sstring& fname = snitch_properties_filename);
static logging::logger& logger() {
static thread_local logging::logger l("gossiping_property_file_snitch");
return l;
}
template <typename... Args>
void err(const char* fmt, Args&&... args) const {
logger().error(fmt, std::forward<Args>(args)...);
}
template <typename... Args>
void warn(const char* fmt, Args&&... args) const {
logger().warn(fmt, std::forward<Args>(args)...);
}
void throw_double_declaration(const sstring& key) const {
err("double \"{}\" declaration in {}", key, _fname);
throw bad_property_file_error();
}
void throw_bad_format(const sstring& line) const {
err("Bad format in properties file {}: {}", _fname, line);
throw bad_property_file_error();
}
void throw_incomplete_file() const {
err("Property file {} is incomplete. Both \"dc\" and \"rack\" "
"labels have to be defined.", _fname);
throw bad_property_file_error();
}
/**
* Parse the property file and indicate the StorageService and a Gossiper if
* there was a configuration change.
*
* @return a ready-future when we are done
*/
future<> reload_configuration();
/**
* Check if the property file has been modified since the last time we
* parsed it.
*
* @return TRUE if property file has been modified
*/
future<bool> property_file_was_modified();
/**
* Read the propery file if it has changed since the last time we read it.
*/
future<> read_property_file();
/**
* TODO: this function is expected to trigger a Gossiper to reconnect
* according to the new "prefer_local" value, namely use either an internal
* or extenal IP address.
*
* This is currently relevant to EC2/GCE(?) only.
*/
void reload_gossiper_state();
/**
* Indicate that the snitch has stopped its I/O.
*/
void set_stopped();
private:
sstring _fname;
timer<> _file_reader;
lw_shared_ptr<file> _sf;
std::experimental::optional<timespec> _last_file_mod;
size_t _fsize;
std::string _srting_buf;
std::istringstream _istrm;
bool _gossip_started = false;
bool _prefer_local = false;
bool _file_reader_runs = false;
};
} // namespace locator