3 #include <zk/config.hpp>
6 #include <zk/types.hpp>
73 using duration_type = std::chrono::milliseconds;
114 const optional<std::
string>&
source_file()
const {
return _source_file; }
161 std::map<server_id, std::string>
servers()
const;
172 std::string hostname,
190 void save(std::ostream& stream)
const;
205 using line_list = std::vector<std::string>;
207 template <
typename T>
211 setting(T value, std::
size_t line) noexcept;
217 template <typename T, typename FEncode>
218 void set(setting<T>& target, optional<T> value, string_view key, const FEncode& encode);
220 template <typename T>
221 void set(setting<T>& target, optional<T> value, string_view key);
227 optional<std::
string> _source_file;
229 setting<std::uint16_t> _client_port;
230 setting<std::
string> _data_directory;
231 setting<duration_type> _tick_time;
232 setting<std::
size_t> _init_limit;
233 setting<std::
size_t> _sync_limit;
234 setting<
bool> _leader_serves;
235 std::
map<
server_id, setting<std::
string>> _server_paths;
236 std::
map<std::
string, setting<std::
string>> _unknown_settings;
247 struct hash<zk::server::server_id>
250 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.
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 std::uint16_t default_leader_port
The default value for leader_port.
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.
static std::uint16_t default_client_port
The default value for client_port.
server_id(std::size_t value)
Create an instance from the given value.
static std::size_t default_sync_limit
The default value for sync_limit.
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 configuration from_stream(std::istream &stream)
Load configuration from the provided stream.
duration_type tick_time() const
static configuration from_string(string_view value)
Load configuration directly from the in-memory value.
std::size_t init_limit() const
static std::size_t default_init_limit
The default value for init_limit.
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.
static duration_type default_tick_time
The default value for tick_time.
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)
void save_file(std::string filename)
Save this configuration to filename.
static std::uint16_t default_peer_port
The default value for peer_port.
std::size_t sync_limit() const
std::uint16_t client_port() const
optional< bool > leader_serves() 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.
configuration & add_setting(std::string key, std::string value)
Add an arbitrary setting with the key and value.