Class: ZK::Server::Config
- Inherits:
-
Object
- Object
- ZK::Server::Config
- Defined in:
- lib/zk-server/config.rb
Overview
Constant Summary collapse
- DEFAULT_JVM_FLAGS =
%w[ -server -Xmx256m -Dzookeeper.serverCnxnFactory=org.apache.zookeeper.server.NettyServerCnxnFactory ].freeze
- DEFAULT_JMX_ARGS =
the com.sun.managemnt.jmxremote.port arg will be filled in dynamically based on the #jmx_port value
%w[ -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false ].freeze
- ZOO_MAIN =
'org.apache.zookeeper.server.quorum.QuorumPeerMain'.freeze
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
The top level directory we will store all of our data under.
-
#client_port ⇒ Object
(also: #port)
what port should the server listen on for connections? (default 2181).
-
#client_port_address ⇒ Object
default: nil.
-
#cnx_timeout ⇒ Object
default: nil .
-
#data_dir ⇒ Object
writeonly
defaults to
#{base_dir}/data
. -
#data_log_dir ⇒ Object
defaults to nil, and zookeeper will just use the default value (being the same as #data_dir.
-
#enable_jmx ⇒ Object
if truthy, will enable jmx (defaults to false) note that our defualt jmx config has all security and auth turned off if you want to customize this, then use jvm_flags and set this to false.
-
#force_sync ⇒ Object
This value can make testing go faster, as zookeeper doesn't have to issue an fsync() call for each snapshot write.
-
#global_outstanding_limit ⇒ Object
default is nil, and will not be specified in the config.
-
#init_limit ⇒ Object
necessary for cluster nodes (default 5).
-
#jmx_port ⇒ Object
default jmx port is 22222.
-
#jvm_flags ⇒ Object
array to which additional JVM flags should be added.
-
#leader_serves ⇒ Object
default: nil.
-
#max_client_cnxns ⇒ Object
maximum number of client connections (defaults to 100).
-
#max_session_timeout ⇒ Object
default: nil.
-
#min_session_timeout ⇒ Object
default: nil.
-
#myid ⇒ Object
what cluster id should this zookeeper use for itself? (default 1).
-
#pre_alloc_size ⇒ Object
default: nil.
-
#skip_acl ⇒ Object
default: nil.
-
#snap_count ⇒ Object
from the admin guide.
-
#sync_limit ⇒ Object
necessary for cluster nodes (default 2).
-
#tick_time ⇒ Object
defaults to 2000.
-
#zoo_cfg_hash ⇒ Object
a hash that will be used to provide extra values for the zoo.cfg file.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Config
constructor
A new instance of Config.
-
#to_config_file_str ⇒ Object
renders this config as a string that can be written to zoo.cfg.
Constructor Details
#initialize(opts = {}) ⇒ Config
Returns a new instance of Config.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/zk-server/config.rb', line 202 def initialize(opts={}) $stderr.puts "#{self.class}#initialize #{opts.inspect}" @base_dir = self.class.default_base_dir @zoo_cfg_hash = {} @tick_time = 2000 @client_port = 2181 @snap_count = nil @force_sync = nil @jmx_port = 22222 @enable_jmx = false @jvm_flags = DEFAULT_JVM_FLAGS.dup @myid = 1 @init_limit = 5 @sync_limit = 2 @max_client_cnxns = 100 opts.each { |k,v| __send__(:"#{k}=", v) } end |
Instance Attribute Details
#base_dir ⇒ Object
The top level directory we will store all of our data under. used as the
basis for all other path generation. Defaults to File.join(Dir.getwd, 'zookeeper')
29 30 31 |
# File 'lib/zk-server/config.rb', line 29 def base_dir @base_dir end |
#client_port ⇒ Object Also known as: port
what port should the server listen on for connections? (default 2181)
60 61 62 |
# File 'lib/zk-server/config.rb', line 60 def client_port @client_port end |
#client_port_address ⇒ Object
default: nil
the address (ipv4, ipv6 or hostname) to listen for client connections; that is, the address that clients attempt to connect to. This is optional, by default we bind in such a way that any connection to the clientPort for any address/interface/nic on the server will be accepted.
138 139 140 |
# File 'lib/zk-server/config.rb', line 138 def client_port_address @client_port_address end |
#cnx_timeout ⇒ Object
default: nil
by default this is not specified
Sets the timeout value for opening connections for leader election notifications.
173 174 175 |
# File 'lib/zk-server/config.rb', line 173 def cnx_timeout @cnx_timeout end |
#data_dir=(value) ⇒ Object
40 41 42 |
# File 'lib/zk-server/config.rb', line 40 def data_dir=(value) @data_dir = value end |
#data_log_dir ⇒ Object
defaults to nil, and zookeeper will just use the default value (being the same as #data_dir
This option will direct the machine to write the transaction log to the dataLogDir rather than the dataDir. This allows a dedicated log device to be used, and helps avoid competition between logging and snaphots.
49 50 51 |
# File 'lib/zk-server/config.rb', line 49 def data_log_dir @data_log_dir end |
#enable_jmx ⇒ Object
if truthy, will enable jmx (defaults to false) note that our defualt jmx config has all security and auth turned off if you want to customize this, then use jvm_flags and set this to false
188 189 190 |
# File 'lib/zk-server/config.rb', line 188 def enable_jmx @enable_jmx end |
#force_sync ⇒ Object
This value can make testing go faster, as zookeeper doesn't have to issue an fsync() call for each snapshot write. It is however DANGEROUS if you care about the data. (I set it to false for running tests)
if true: 'yes', false: 'no', nil not specified in the config
default: no value set
120 121 122 |
# File 'lib/zk-server/config.rb', line 120 def force_sync @force_sync end |
#global_outstanding_limit ⇒ Object
default is nil, and will not be specified in the config
Clients can submit requests faster than ZooKeeper can process them, especially if there are a lot of clients. To prevent ZooKeeper from running out of memory due to queued requests, ZooKeeper will throttle clients so that there is no more than globalOutstandingLimit outstanding requests in the system. The default limit is 1,000.
81 82 83 |
# File 'lib/zk-server/config.rb', line 81 def global_outstanding_limit @global_outstanding_limit end |
#init_limit ⇒ Object
necessary for cluster nodes (default 5)
from the zookeeper admin guide:
Amount of time, in ticks (see tickTime), to allow followers to connect and sync to a leader. Increased this value as needed, if the amount of data managed by ZooKeeper is large.
90 91 92 |
# File 'lib/zk-server/config.rb', line 90 def init_limit @init_limit end |
#jmx_port ⇒ Object
default jmx port is 22222
191 192 193 |
# File 'lib/zk-server/config.rb', line 191 def jmx_port @jmx_port end |
#jvm_flags ⇒ Object
array to which additional JVM flags should be added
default is DEEFAULT_JVM_FLAGS
196 197 198 |
# File 'lib/zk-server/config.rb', line 196 def jvm_flags @jvm_flags end |
#leader_serves ⇒ Object
default: nil
If true, the value 'yes' will be used for this value, false will write 'no' to the config file. The default (nil) is not to specify a value in the config.
Leader accepts client connections. Default value is "yes". The leader machine coordinates updates. For higher update throughput at thes slight expense of read throughput the leader can be configured to not accept clients and focus on coordination. The default to this option is yes, which means that a leader will accept client connections
164 165 166 |
# File 'lib/zk-server/config.rb', line 164 def leader_serves @leader_serves end |
#max_client_cnxns ⇒ Object
maximum number of client connections (defaults to 100)
65 66 67 |
# File 'lib/zk-server/config.rb', line 65 def max_client_cnxns @max_client_cnxns end |
#max_session_timeout ⇒ Object
default: nil
the maximum session timeout in milliseconds that the server will allow the client to negotiate. Defaults to 20 times the tickTime.
151 152 153 |
# File 'lib/zk-server/config.rb', line 151 def max_session_timeout @max_session_timeout end |
#min_session_timeout ⇒ Object
default: nil
the minimum session timeout in milliseconds that the server will allow the client to negotiate. Defaults to 2 times the tickTime
145 146 147 |
# File 'lib/zk-server/config.rb', line 145 def min_session_timeout @min_session_timeout end |
#myid ⇒ Object
what cluster id should this zookeeper use for itself? (default 1)
71 72 73 |
# File 'lib/zk-server/config.rb', line 71 def myid @myid end |
#pre_alloc_size ⇒ Object
default: nil
To avoid seeks ZooKeeper allocates space in the transaction log file in blocks of preAllocSize kilobytes. The default block size is 64M. One reason for changing the size of the blocks is to reduce the block size if snapshots are taken more often. (Also, see snapCount).
128 129 130 |
# File 'lib/zk-server/config.rb', line 128 def pre_alloc_size @pre_alloc_size end |
#skip_acl ⇒ Object
default: nil
if true: 'yes', false: 'no', nil not specified in the config
this is listed as a DANGEROUS setting
Skips ACL checks. This results in a boost in throughput, but opens up full access to the data tree to everyone.
183 184 185 |
# File 'lib/zk-server/config.rb', line 183 def skip_acl @skip_acl end |
#snap_count ⇒ Object
from the admin guide
ZooKeeper logs transactions to a transaction log. After snapCount transactions are written to a log file a snapshot is started and a new transaction log file is created. The default snapCount is 100,000.
For testing, to speed up disk IO, I generally set this to 1_000_000 and force_sync to false. YMMV, understand what this does before messing with it if you care about your data.
default: unset
111 112 113 |
# File 'lib/zk-server/config.rb', line 111 def snap_count @snap_count end |
#sync_limit ⇒ Object
necessary for cluster nodes (default 2)
Amount of time, in ticks (see tickTime), to allow followers to sync with ZooKeeper. If followers fall too far behind a leader, they will be dropped.
98 99 100 |
# File 'lib/zk-server/config.rb', line 98 def sync_limit @sync_limit end |
#tick_time ⇒ Object
defaults to 2000
68 69 70 |
# File 'lib/zk-server/config.rb', line 68 def tick_time @tick_time end |
#zoo_cfg_hash ⇒ Object
a hash that will be used to provide extra values for the zoo.cfg file. keys are written as-is to the file, so they should be camel-cased.
dataDir will be set relative to #base_dir and clientPort will either use the default of 2181, or can be adjusted by #client_port=
57 58 59 |
# File 'lib/zk-server/config.rb', line 57 def zoo_cfg_hash @zoo_cfg_hash end |
Class Method Details
.default_base_dir ⇒ Object
198 199 200 |
# File 'lib/zk-server/config.rb', line 198 def self.default_base_dir File.join(Dir.getwd, 'zookeeper') end |
Instance Method Details
#to_config_file_str ⇒ Object
renders this config as a string that can be written to zoo.cfg
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/zk-server/config.rb', line 270 def to_config_file_str config = { 'dataDir' => data_dir, 'skipACL' => skip_acl, 'tickTime' => tick_time, 'initLimit' => init_limit, 'syncLimit' => sync_limit, 'forceSync' => force_sync, 'snapCount' => snap_count, 'clientPort' => client_port, 'dataLogDir' => data_log_dir, 'preAllocSize' => pre_alloc_size, 'leaderServes' => leader_serves, 'maxClientCnxns' => max_client_cnxns, 'clientPortAddress' => client_port_address, 'minSessionTimeout' => min_session_timeout, 'maxSessionTimeout' => max_session_timeout, 'globalOutstandingLimit' => global_outstanding_limit, } config = config.merge(zoo_cfg_hash) config.delete_if { |k,v| v.nil? } %w[leaderServes skipACL forceSync].each do |yorn_key| if config.has_key?(yorn_key) config[yorn_key] = config[yorn_key] ? 'yes' : 'no' end end config.sort.map {|kv| kv.join("=") }.join("\n") end |