3 #include <zk/config.hpp>
6 #include <zk/types.hpp>
74 using duration_type = std::chrono::milliseconds;
126 const optional<std::
string>&
source_file()
const {
return _source_file; }
196 std::map<server_id, std::string>
servers()
const;
207 std::string hostname,
225 void save(std::ostream& stream)
const;
240 using line_list = std::vector<std::string>;
242 template <
typename T>
246 setting(T value, std::
size_t line) noexcept;
252 template <typename T, typename FEncode>
253 void set(setting<T>& target, optional<T> value, string_view key, const FEncode& encode);
255 template <typename T>
256 void set(setting<T>& target, optional<T> value, string_view key);
262 optional<std::
string> _source_file;
264 setting<std::uint16_t> _client_port;
265 setting<std::
string> _data_directory;
266 setting<duration_type> _tick_time;
267 setting<std::
size_t> _init_limit;
268 setting<std::
size_t> _sync_limit;
269 setting<
bool> _leader_serves;
270 setting<std::set<std::
string>> _four_letter_word_whitelist;
271 std::
map<
server_id, setting<std::
string>> _server_paths;
272 std::
map<std::
string, setting<std::
string>> _unknown_settings;
283 struct hash<zk::server::server_id>
286 using result_type = std::size_t;
auto map(FUnary &&transform, const optional< T > &...x) -> optional< decltype(transform(x.value()...))>
Apply transform with the arguments in x iff all of them have a value. Otherwise, nullopt will be retu...
std::map< server_id, std::string > servers() const
Get the servers which are part of the ZooKeeper ensemble.
Represents the ID of a server in the ensemble.
Base type for creating strong ID types.
static const std::size_t default_sync_limit
The default value for sync_limit.
const optional< std::string > & source_file() const
Get the source file. This will only have a value if this was created by from_file.
bool is_minimal() const
Check if this is a "minimal" configuration – meaning it only has a data_directory and client_port se...
const optional< std::string > & data_directory() const
Imports of optional and nullopt_t types, as well as the nullopt constexpr.
static configuration from_lines(std::vector< std::string > lines)
Load configuration from the provided lines.
static configuration make_minimal(std::string data_directory, std::uint16_t client_port=default_client_port)
Creates a minimal configuration, setting the four needed values.
server_id(std::size_t value)
Create an instance from the given value.
bool leader_serves() const
static const std::set< std::string > all_four_letter_word_whitelist
A value for four_letter_word_whitelist that enables all commands.
const std::set< std::string > & four_letter_word_whitelist() const
std::map< std::string, std::string > unknown_settings() const
Get settings that were in the configuration file (or manually added with add_setting) but unknown to ...
static configuration from_file(std::string filename)
Load the configuration from a file.
static const std::set< std::string > known_four_letter_word_whitelist
All known values allowed in four_letter_word_whitelist.
static configuration from_stream(std::istream &stream)
Load configuration from the provided stream.
static const std::uint16_t default_client_port
The default value for client_port.
static const std::uint16_t default_leader_port
The default value for leader_port.
duration_type tick_time() const
static const std::size_t default_init_limit
The default value for init_limit.
static const std::uint16_t default_peer_port
The default value for peer_port.
static configuration from_string(string_view value)
Load configuration directly from the in-memory value.
std::size_t init_limit() const
friend std::ostream & operator<<(std::ostream &, const server_id &)
Debug print for this instance.
void ensure_valid() const
Check that this ID is a valid one.
Imports the string_view type as std::string_view.
Represents a configuration which should be run by server instance.
void save(std::ostream &stream) const
Write this configuration to the provided stream.
friend bool operator==(const configuration &lhs, const configuration &rhs)
static const duration_type default_tick_time
The default value for tick_time.
void save_file(std::string filename)
Save this configuration to filename.
std::size_t sync_limit() const
std::uint16_t client_port() const
std::size_t hash(const acl_rule &self)
Compute a hash for the given rule.
configuration & add_server(server_id id, std::string hostname, std::uint16_t peer_port=default_peer_port, std::uint16_t leader_port=default_leader_port)
Add a new server to the configuration.
value_type value
Underlying value of this ID.
static const std::set< std::string > default_four_letter_word_whitelist
The default value for four_letter_word_whitelist.
configuration & add_setting(std::string key, std::string value)
Add an arbitrary setting with the key and value.