zookeeper-cpp
ZooKeeper Client for C++
|
Represents a configuration which should be run by server instance. More...
#include <zk/server/configuration.hpp>
Public Types | |
using | duration_type = std::chrono::milliseconds |
Public Member Functions | |
const optional< std::string > & | source_file () const |
Get the source file. This will only have a value if this was created by from_file. More... | |
bool | is_minimal () const |
Check if this is a "minimal" configuration – meaning it only has a data_directory and client_port set. More... | |
std::map< server_id, std::string > | servers () const |
Get the servers which are part of the ZooKeeper ensemble. More... | |
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. More... | |
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 this library. More... | |
configuration & | add_setting (std::string key, std::string value) |
Add an arbitrary setting with the key and value. More... | |
void | save (std::ostream &stream) const |
Write this configuration to the provided stream. More... | |
void | save_file (std::string filename) |
Save this configuration to filename. More... | |
std::uint16_t | client_port () const |
configuration & | client_port (optional< std::uint16_t > port) |
const optional< std::string > & | data_directory () const |
configuration & | data_directory (optional< std::string > path) |
duration_type | tick_time () const |
configuration & | tick_time (optional< duration_type > time) |
std::size_t | init_limit () const |
configuration & | init_limit (optional< std::size_t > limit) |
std::size_t | sync_limit () const |
configuration & | sync_limit (optional< std::size_t > limit) |
bool | leader_serves () const |
configuration & | leader_serves (optional< bool > serve) |
const std::set< std::string > & | four_letter_word_whitelist () const |
configuration & | four_letter_word_whitelist (optional< std::set< std::string >> words) |
Static Public Member Functions | |
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. More... | |
static configuration | from_file (std::string filename) |
Load the configuration from a file. More... | |
static configuration | from_stream (std::istream &stream) |
Load configuration from the provided stream. More... | |
static configuration | from_lines (std::vector< std::string > lines) |
Load configuration from the provided lines. More... | |
static configuration | from_string (string_view value) |
Load configuration directly from the in-memory value. More... | |
Static Public Attributes | |
static const std::uint16_t | default_client_port = std::uint16_t(2181) |
The default value for client_port. More... | |
static const std::uint16_t | default_peer_port = std::uint16_t(2888) |
The default value for peer_port. More... | |
static const std::uint16_t | default_leader_port = std::uint16_t(3888) |
The default value for leader_port. More... | |
static const duration_type | default_tick_time = std::chrono::milliseconds(2000) |
The default value for tick_time. More... | |
static const std::size_t | default_init_limit = 10U |
The default value for init_limit. More... | |
static const std::size_t | default_sync_limit = 5U |
The default value for sync_limit. More... | |
static const std::set < std::string > | default_four_letter_word_whitelist = { "srvr" } |
The default value for four_letter_word_whitelist. More... | |
static const std::set < std::string > | all_four_letter_word_whitelist = { "*" } |
A value for four_letter_word_whitelist that enables all commands. More... | |
static const std::set < std::string > | known_four_letter_word_whitelist |
All known values allowed in four_letter_word_whitelist. More... | |
Friends | |
bool | operator== (const configuration &lhs, const configuration &rhs) |
bool | operator!= (const configuration &lhs, const configuration &rhs) |
Represents a configuration which should be run by server instance.
This can also be used to modify an existing ZooKeeper server configuration file in a safer manner than the unfortunate operating practice of sed
, awk
, and perl
.
This can be used to quickly create a quorum peer, ready to connect to 3 servers.
Definition at line 71 of file configuration.hpp.
configuration & zk::server::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.
id | The cluster unique ID of this server. |
hostname | The address of the server to connect to. |
peer_port | The port used to move ZooKeeper data on. |
leader_port | The port used for leader election. |
std::out_of_range | if the id is not in the valid range of IDs (see server_id). |
std::runtime_error | if there is already a server with the given id. |
Definition at line 368 of file configuration.cpp.
configuration & zk::server::configuration::add_setting | ( | std::string | key, |
std::string | value | ||
) |
Add an arbitrary setting with the key and value.
Definition at line 398 of file configuration.cpp.
std::uint16_t zk::server::configuration::client_port | ( | ) | const |
The port a client should use to connect to this server.
Definition at line 259 of file configuration.cpp.
const optional< std::string > & zk::server::configuration::data_directory | ( | ) | const |
The directory for "myid" file and "version-2" directory (containing the log, snapshot, and epoch files).
Definition at line 270 of file configuration.cpp.
const std::set< std::string > & zk::server::configuration::four_letter_word_whitelist | ( | ) | const |
A list of comma separated four letter words commands that user wants to use. A valid four letter words command must be put in this list or the ZooKeeper server will not enable the command. If unspecified, the whitelist only contains "srvr" command (default_four_letter_word_whitelist).
words | is the list of four letter words to allow or nullopt to clear the setting. If specified as an empty set, this explicitly disables all words, which is different than setting this value to nullopt . |
std::invalid_argument | if words contains the all value ("*" ) but it is not the only value in the set. |
default_four_letter_word_whitelist all_four_letter_word_whitelist known_four_letter_word_whitelist
Definition at line 325 of file configuration.cpp.
|
static |
Load the configuration from a file.
Definition at line 201 of file configuration.cpp.
|
static |
Load configuration from the provided lines.
Definition at line 118 of file configuration.cpp.
|
static |
Load configuration from the provided stream.
Definition at line 185 of file configuration.cpp.
|
static |
Load configuration directly from the in-memory value.
Definition at line 209 of file configuration.cpp.
std::size_t zk::server::configuration::init_limit | ( | ) | const |
The number of ticks that the initial synchronization phase can take. This limits the length of time the ZooKeeper servers in quorum have to connect to a leader.
Definition at line 292 of file configuration.cpp.
bool zk::server::configuration::is_minimal | ( | ) | const |
Check if this is a "minimal" configuration – meaning it only has a data_directory
and client_port
set.
Configurations which are minimal can be started directly from the command line.
Definition at line 216 of file configuration.cpp.
bool zk::server::configuration::leader_serves | ( | ) | const |
Should an elected leader accepts client connections? For higher update throughput at the slight expense of read latency, the leader can be configured to not accept clients and focus on coordination. The default to this value is true
, which means that a leader will accept client connections.
Definition at line 314 of file configuration.cpp.
|
static |
Creates a minimal configuration, setting the four needed values.
The resulting configuration can be run through a file with save
or it can run directly from the command line.
Definition at line 77 of file configuration.cpp.
void zk::server::configuration::save | ( | std::ostream & | stream | ) | const |
Write this configuration to the provided stream.
Definition at line 413 of file configuration.cpp.
void zk::server::configuration::save_file | ( | std::string | filename | ) |
Save this configuration to filename.
On successful save, source_file
will but updated to reflect the new file.
Definition at line 421 of file configuration.cpp.
std::map< server_id, std::string > zk::server::configuration::servers | ( | ) | const |
Get the servers which are part of the ZooKeeper ensemble.
Definition at line 359 of file configuration.cpp.
|
inline |
Get the source file. This will only have a value if this was created by from_file.
Definition at line 126 of file configuration.hpp.
std::size_t zk::server::configuration::sync_limit | ( | ) | const |
Limits how far out of date a server can be from a leader.
Definition at line 303 of file configuration.cpp.
configuration::duration_type zk::server::configuration::tick_time | ( | ) | const |
The time between server "ticks." This value is used to translate init_limit and sync_limit into clock times.
Definition at line 281 of file configuration.cpp.
std::map< std::string, std::string > zk::server::configuration::unknown_settings | ( | ) | const |
Get settings that were in the configuration file (or manually added with add_setting) but unknown to this library.
Definition at line 389 of file configuration.cpp.
|
friend |
Check for equality of configuration. This does not check the specification in lines, but the values of the settings. In other words, two configurations with tick_time
set to 1 second are equal, even if the source files are different and "tickTime=1000"
was set on different lines.
Definition at line 431 of file configuration.cpp.
|
static |
A value for four_letter_word_whitelist that enables all commands.
Note that this is not a list of all allowed words, but simply the string "*"
.
Definition at line 100 of file configuration.hpp.
|
static |
The default value for client_port.
Definition at line 78 of file configuration.hpp.
|
static |
The default value for four_letter_word_whitelist.
Definition at line 96 of file configuration.hpp.
|
static |
The default value for init_limit.
Definition at line 90 of file configuration.hpp.
|
static |
The default value for leader_port.
Definition at line 84 of file configuration.hpp.
|
static |
The default value for peer_port.
Definition at line 81 of file configuration.hpp.
|
static |
The default value for sync_limit.
Definition at line 93 of file configuration.hpp.
|
static |
The default value for tick_time.
Definition at line 87 of file configuration.hpp.
|
static |
All known values allowed in four_letter_word_whitelist.
This set comes from what ZooKeeper server 3.5.3 supported, so it is possible the version of ZooKeeper you are running supports a different set.
Definition at line 104 of file configuration.hpp.