0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Config.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
28 #include <Common/Compat.h>
29 #include <Common/Version.h>
30 #include <Common/Logger.h>
31 #include <Common/String.h>
32 #include <Common/Path.h>
33 #include <Common/FileUtils.h>
34 #include <Common/Config.h>
35 #include <Common/SystemInfo.h>
36 
37 #include <fstream>
38 #include <iostream>
39 #include <mutex>
40 
41 #include <errno.h>
42 
43 namespace Hypertable { namespace Config {
44 
45 // singletons
46 std::recursive_mutex rec_mutex;
49 static bool file_loaded = false;
50 static bool allow_unregistered = false;
51 
52 static Desc *cmdline_descp = NULL;
53 static Desc *cmdline_hidden_descp = NULL;
55 static Desc *file_descp = NULL;
56 
57 static int terminal_line_length() {
58  int n = System::term_info().num_cols;
59  return n > 0 ? n : 80;
60 }
61 
62 static String usage_str(const char *usage) {
63  if (!usage)
64  usage = "Usage: %s [options]\n\nOptions";
65 
66  if (strstr(usage, "%s"))
67  return format(usage, System::exe_name.c_str());
68 
69  return usage;
70 }
71 
72 Desc &cmdline_desc(const char *usage) {
73  std::lock_guard<std::recursive_mutex> lock(rec_mutex);
74 
75  if (!cmdline_descp)
76  cmdline_descp = new Desc(usage_str(usage), terminal_line_length());
77 
78  return *cmdline_descp;
79 }
80 
82  std::lock_guard<std::recursive_mutex> lock(rec_mutex);
83 
84  if (!cmdline_hidden_descp)
85  cmdline_hidden_descp = new Desc();
86 
87  return *cmdline_hidden_descp;
88 }
89 
91  std::lock_guard<std::recursive_mutex> lock(rec_mutex);
92 
93  if (!cmdline_positional_descp)
94  cmdline_positional_descp = new PositionalDesc();
95 
97 }
98 
99 void cmdline_desc(const Desc &desc) {
100  std::lock_guard<std::recursive_mutex> lock(rec_mutex);
101 
102  if (cmdline_descp)
103  delete cmdline_descp;
104 
105  cmdline_descp = new Desc(desc);
106 }
107 
108 Desc &file_desc(const char *usage) {
109  std::lock_guard<std::recursive_mutex> lock(rec_mutex);
110 
111  if (!file_descp)
112  file_descp = new Desc(usage ? usage : "Config Properties",
114 
115  return *file_descp;
116 }
117 
118 void file_desc(const Desc &desc) {
119  std::lock_guard<std::recursive_mutex> lock(rec_mutex);
120 
121  if (file_descp)
122  delete file_descp;
123 
124  file_descp = new Desc(desc);
125 }
126 
128  String default_config;
130 
131  // Detect installed path and assume the layout, otherwise assume the
132  // default config file in the current directory.
133  if (System::install_dir == boost::filesystem::current_path().string()) {
134  Path exe(System::proc_info().exe);
135  default_config = exe.parent_path() == System::install_dir
136  ? "hypertable.cfg" : "conf/hypertable.cfg";
137  }
138  else {
139  Path config(System::install_dir);
140  config /= "conf/hypertable.cfg";
141  default_config = config.string();
142  }
143  String default_data_dir = System::install_dir;
144 
145  cmdline_desc().add_options()
146  ("help,h", "Show this help message and exit")
147  ("help-config", "Show help message for config properties")
148  ("version", "Show version information and exit")
149  ("verbose,v", boo()->zero_tokens()->default_value(false),
150  "Show more verbose output")
151  ("debug", boo()->zero_tokens()->default_value(false),
152  "Show debug output (shortcut of --logging-level debug)")
153  ("quiet", boo()->zero_tokens()->default_value(false), "Negate verbose")
154  ("silent", boo()->zero_tokens()->default_value(false),
155  "Show as little output as possible")
156  ("logging-level,l", str()->default_value("info"),
157  "Logging level: debug, info, notice, warn, error, crit, alert, fatal")
158  ("config", str()->default_value(default_config), "Configuration file.\n")
159  ("induce-failure", str(), "Arguments for inducing failure")
160  ("timeout,t", i32(), "System wide timeout in milliseconds")
161  ;
162  alias("logging-level", "Hypertable.Logging.Level");
163  alias("verbose", "Hypertable.Verbose");
164  alias("silent", "Hypertable.Silent");
165  alias("timeout", "Hypertable.Request.Timeout");
166 
167  // pre boost 1.35 doesn't support allow_unregistered, so we have to have the
168  // full cfg definition here, which might not be a bad thing.
169  file_desc().add_options()
170  ("Comm.DispatchDelay", i32()->default_value(0), "[TESTING ONLY] "
171  "Delay dispatching of read requests by this number of milliseconds")
172  ("Comm.UsePoll", boo()->default_value(false), "Use POSIX poll() interface")
173  ("Hypertable.Cluster.Name", str(),
174  "Name of cluster used in Monitoring UI and admin notification messages")
175  ("Hypertable.Verbose", boo()->default_value(false),
176  "Enable verbose output (system wide)")
177  ("Hypertable.Silent", boo()->default_value(false),
178  "Disable verbose output (system wide)")
179  ("Hypertable.Logging.Level", str()->default_value("info"),
180  "Set system wide logging level (default: info)")
181  ("Hypertable.DataDirectory", str()->default_value(default_data_dir),
182  "Hypertable data directory root")
183  ("Hypertable.Client.Workers", i32()->default_value(20),
184  "Number of client worker threads created")
185  ("Hypertable.Connection.Retry.Interval", i32()->default_value(10000),
186  "Average time, in milliseconds, between connection retry atempts")
187  ("Hypertable.LogFlushMethod.Meta", str()->default_value("SYNC"),
188  "Log flush method for metadata (FLUSH flushes data to replicas, SYNC "
189  "persists data all the way down to physical storage)")
190  ("Hypertable.LogFlushMethod.User", str()->default_value("FLUSH"),
191  "Log flush method for user data (FLUSH flushes data to replicas, SYNC "
192  "persists data all the way down to physical storage)")
193  ("Hypertable.Metrics.Ganglia.Disable", boo()->default_value(false),
194  "Disable publishing of metrics to Ganglia")
195  ("Hypertable.Metrics.Ganglia.Port", i16()->default_value(15860),
196  "UDP Port on which Hypertable gmond python extension module listens for metrics")
197  ("Hypertable.LoadMetrics.Interval", i32()->default_value(3600), "Period of "
198  "time, in seconds, between writing metrics to sys/RS_METRICS")
199  ("Hypertable.Request.Timeout", i32()->default_value(600000), "Length of "
200  "time, in milliseconds, before timing out requests (system wide)")
201  ("Hypertable.MetaLog.HistorySize", i32()->default_value(30), "Number "
202  "of old MetaLog files to retain for historical purposes")
203  ("Hypertable.MetaLog.MaxFileSize", i64()->default_value(100*M), "Maximum "
204  "size a MetaLog file can grow before it is compacted")
205  ("Hypertable.MetaLog.SkipErrors", boo()->default_value(false), "Skipping "
206  "errors instead of throwing exceptions on metalog errors")
207  ("Hypertable.MetaLog.WriteInterval", i32()->default_value(30),
208  "Minimum write interval for Metalog in milliseconds")
209  ("Hypertable.Network.Interface", str(),
210  "Use this interface for network communication")
211  ("CephBroker.Port", i16(),
212  "Port number on which to listen (read by CephBroker only)")
213  ("CephBroker.Workers", i32()->default_value(20),
214  "Number of Ceph broker worker threads created, maybe")
215  ("CephBroker.MonAddr", str(),
216  "Ceph monitor address to connect to")
217  ("HdfsBroker.SyncBlock", boo()->default_value(true),
218  "Pass SYNC_BLOCK flag to Filesystem.create() when creating files")
219  ("HdfsBroker.Port", i16(),
220  "Port number on which to listen (read by HdfsBroker only)")
221  ("HdfsBroker.Hadoop.ConfDir", str(), "Hadoop configuration directory "
222  "(e.g. /etc/hadoop/conf or /usr/lib/hadoop/conf)")
223  ("HdfsBroker.fs.default.name", str(), "Hadoop Filesystem "
224  "default name, same as fs.default.name property in Hadoop config "
225  "(e.g. hdfs://localhost:9000)")
226  ("DfsBroker.Hdfs.NameNode.Host", str()->default_value("default"),
227  "Name of host on which HDFS NameNode is running")
228  ("DfsBroker.Hdfs.NameNode.Port", i16()->default_value(0),
229  "Port number on which HDFS NameNode is running")
230  ("HdfsBroker.Workers", i32(),
231  "Number of HDFS broker worker threads created")
232  ("HdfsBroker.Reactors", i32(),
233  "Number of HDFS broker communication reactor threads created")
234  ("Kfs.Broker.Workers", i32()->default_value(20), "Number of worker "
235  "threads for Kfs broker")
236  ("Kfs.Broker.Reactors", i32(), "Number of Kfs broker reactor threads")
237  ("Kfs.MetaServer.Name", str(), "Hostname of Kosmos meta server")
238  ("Kfs.MetaServer.Port", i16(), "Port number for Kosmos meta server")
239  ("Qfs.Broker.Workers", i32()->default_value(20), "Number of worker "
240  "threads for Qfs broker")
241  ("Qfs.Broker.Reactors", i32(), "Number of Qfs broker reactor threads")
242  ("Qfs.MetaServer.Name", str()->default_value("localhost"), "Hostname of "
243  "QFS meta server")
244  ("Qfs.MetaServer.Port", i16()->default_value(20000), "Port number for QFS "
245  "meta server")
246  ("DfsBroker.Local.DirectIO", boo(),
247  "DEPRECATED: renamed to FsBroker.Local.DirectIO")
248  ("DfsBroker.Local.Port", i16(),
249  "DEPRECATED: renamed to FsBroker.Local.Port")
250  ("DfsBroker.Local.Root", str(), "DEPRECATED: renamed to FsBroker.Local.Root")
251  ("DfsBroker.Local.Workers", i32(),
252  "DEPRECATED: renamed to FsBroker.Local.Workers")
253  ("DfsBroker.Local.Reactors", i32(),
254  "DEPRECATED: renamed to FsBroker.Local.Reactors")
255  ("DfsBroker.Host", str(), "DEPRECATED: renamed to FsBroker.Host")
256  ("DfsBroker.Port", i16(), "DEPRECATED: renamed to FsBroker.Port")
257  ("DfsBroker.Timeout", i32(), "DEPRECATED: renamed to FsBroker.Timeout")
258  ("FsBroker.DisableFileRemoval", boo()->default_value(false),
259  "Rename files with .deleted extension instead of removing (for testing)")
260  ("FsBroker.Local.DirectIO", boo()->default_value(false),
261  "Read and write files using direct i/o")
262  ("FsBroker.Local.Port", i16()->default_value(15863),
263  "Port number on which to listen (read by LocalBroker only)")
264  ("FsBroker.Local.Root", str(), "Root of file and directory "
265  "hierarchy for local broker (if relative path, then is relative to "
266  "the Hypertable data directory root)")
267  ("FsBroker.Local.Workers", i32()->default_value(20),
268  "Number of local broker worker threads created")
269  ("FsBroker.Local.Reactors", i32(),
270  "Number of local broker communication reactor threads created")
271  ("FsBroker.Host", str()->default_value("localhost"),
272  "Host on which the FS broker is running (read by clients only)")
273  ("FsBroker.Port", i16()->default_value(15863),
274  "Port number on which FS broker is listening (read by clients only)")
275  ("FsBroker.Timeout", i32(), "Length of time, "
276  "in milliseconds, to wait before timing out FS Broker requests. This "
277  "takes precedence over Hypertable.Request.Timeout")
278  ("Hyperspace.Timeout", i32()->default_value(30000), "Timeout (millisec) "
279  "for hyperspace requests (preferred to Hypertable.Request.Timeout")
280  ("Hyperspace.Maintenance.Interval", i32()->default_value(60000), "Hyperspace "
281  " maintenance interval (checkpoint BerkeleyDB, log cleanup etc)")
282  ("Hyperspace.Checkpoint.Size", i32()->default_value(1*M), "Run BerkeleyDB checkpoint"
283  " when logs exceed this size limit")
284  ("Hyperspace.Client.Datagram.SendPort", i16()->default_value(0),
285  "Client UDP send port for keepalive packets")
286  ("Hyperspace.LogGc.Interval", i32()->default_value(60000), "Check for unused BerkeleyDB "
287  "log files after this much time")
288  ("Hyperspace.LogGc.MaxUnusedLogs", i32()->default_value(200), "Number of unused BerkeleyDB "
289  "to keep around in case of lagging replicas")
290  ("Hyperspace.Replica.Host", strs(), "Hostname of Hyperspace replica")
291  ("Hyperspace.Replica.Port", i16()->default_value(15861),
292  "Port number on which Hyperspace is or should be listening for requests")
293  ("Hyperspace.Replica.Replication.Port", i16()->default_value(15862),
294  "Hyperspace replication port ")
295  ("Hyperspace.Replica.Replication.Timeout", i32()->default_value(10000),
296  "Hyperspace replication master dies if it doesn't receive replication acknowledgement "
297  "within this period")
298  ("Hyperspace.Replica.Workers", i32()->default_value(20),
299  "Number of Hyperspace Replica worker threads created")
300  ("Hyperspace.Replica.Reactors", i32(),
301  "Number of Hyperspace Master communication reactor threads created")
302  ("Hyperspace.Replica.Dir", str()->default_value("hyperspace"),
303  "Root of hyperspace file and directory "
304  "heirarchy in local filesystem (if relative path, then is relative to "
305  "the Hypertable data directory root)")
306  ("Hyperspace.KeepAlive.Interval", i32()->default_value(30000),
307  "Hyperspace Keepalive interval (see Chubby paper)")
308  ("Hyperspace.Lease.Interval", i32()->default_value(60000),
309  "Hyperspace Lease interval (see Chubby paper)")
310  ("Hyperspace.GracePeriod", i32()->default_value(60000),
311  "Hyperspace Grace period (see Chubby paper)")
312  ("Hyperspace.Session.Reconnect", boo()->default_value(false),
313  "Reconnect to Hyperspace on session expiry")
314  ("Hypertable.Directory", str()->default_value("hypertable"),
315  "Top-level hypertable directory name")
316  ("Hypertable.Monitoring.Interval", i32()->default_value(30000),
317  "Monitoring statistics gathering interval (in milliseconds)")
318  ("Hypertable.Monitoring.Disable", boo()->default_value(false),
319  "Disables the generation of monitoring statistics")
320  ("Hypertable.LoadBalancer.Enable", boo()->default_value(true),
321  "Enable automatic load balancing")
322  ("Hypertable.LoadBalancer.Crontab", str()->default_value("0 0 * * *"),
323  "Crontab entry to control when load balancer is run")
324  ("Hypertable.LoadBalancer.BalanceDelay.Initial", i32()->default_value(86400),
325  "Amount of time to wait after start up before running balancer")
326  ("Hypertable.LoadBalancer.BalanceDelay.NewServer", i32()->default_value(60),
327  "Amount of time to wait before running balancer when a new RangeServer is detected")
328  ("Hypertable.LoadBalancer.LoadavgThreshold", f64()->default_value(0.25),
329  "Servers with loadavg above this much above the mean will be considered by the "
330  "load balancer to be overloaded")
331  ("Hypertable.HqlInterpreter.Mutator.NoLogSync", boo()->default_value(false),
332  "Suspends CommitLog sync operation on updates until command completion")
333  ("Hypertable.RangeLocator.MetadataReadaheadCount", i32()->default_value(10),
334  "Number of rows that the RangeLocator fetches from the METADATA")
335  ("Hypertable.RangeLocator.MaxErrorQueueLength", i32()->default_value(4),
336  "Maximum numbers of errors to be stored")
337  ("Hypertable.RangeLocator.MetadataRetryInterval", i32()->default_value(3000),
338  "Retry interval when connecting to a RangeServer to fetch metadata")
339  ("Hypertable.RangeLocator.RootMetadataRetryInterval", i32()->default_value(3000),
340  "Retry interval when connecting to the Root RangeServer")
341  ("Hypertable.Mutator.FlushDelay", i32()->default_value(0), "Number of "
342  "milliseconds to wait prior to flushing scatter buffers (for testing)")
343  ("Hypertable.Mutator.ScatterBuffer.FlushLimit.PerServer",
344  i32()->default_value(10*M), "Amount of updates (bytes) accumulated for a "
345  "single server to trigger a scatter buffer flush")
346  ("Hypertable.Mutator.ScatterBuffer.FlushLimit.Aggregate",
347  i64()->default_value(50*M), "Amount of updates (bytes) accumulated for "
348  "all servers to trigger a scatter buffer flush")
349  ("Hypertable.Scanner.QueueSize",
350  i32()->default_value(5), "Size of Scanner ScanBlock queue")
351  ("Hypertable.LocationCache.MaxEntries", i64()->default_value(1*M),
352  "Size of range location cache in number of entries")
353  ("Hypertable.Master.Host", str(),
354  "Host on which Hypertable Master is running")
355  ("Hypertable.Master.Port", i16()->default_value(15864),
356  "Port number on which Hypertable Master is or should be listening")
357  ("Hypertable.Master.Workers", i32()->default_value(100),
358  "Number of Hypertable Master worker threads created")
359  ("Hypertable.Master.Reactors", i32(),
360  "Number of Hypertable Master communication reactor threads created")
361  ("Hypertable.Master.Gc.Interval", i32()->default_value(300000),
362  "Garbage collection interval in milliseconds by Master")
363  ("Hypertable.Master.Locations.IncludeMasterHash", boo()->default_value(false),
364  "Includes master hash (host:port) in RangeServer location id")
365  ("Hypertable.Master.Split.SoftLimitEnabled", boo()->default_value(true),
366  "Enable aggressive splitting of tables with little data to spread out ranges")
367  ("Hypertable.Master.DiskThreshold.Percentage", i32()->default_value(90),
368  "Stop assigning ranges to RangeServers if disk usage is above this threshold")
369  ("Hypertable.Master.FailedRangeServerLimit.Percentage", i32()->default_value(80),
370  "Fail hard if less than this percentage of the RangeServers are unavailable "
371  "at a given time")
372  ("Hypertable.Master.NotificationInterval", i32()->default_value(3600),
373  "Notification interval (in seconds) of abnormal state")
374  ("Hypertable.Master.RecordGraphvizStream", boo()->default_value(false),
375  "Appends Graphviz output to run/op-graphviz-stream on each DAG change")
376  ("Hypertable.Failover.GracePeriod", i32()->default_value(30000),
377  "Master wait this long before trying to recover a RangeServer")
378  ("Hypertable.Failover.Timeout", i32()->default_value(300000),
379  "Timeout for failover operations")
380  ("Hypertable.Failover.Quorum.Percentage", i32()->default_value(90),
381  "Percentage of live RangeServers required for failover to proceed")
382  ("Hypertable.Failover.RecoverInSeries", boo()->default_value(false),
383  "Carry out USER log recovery for failed servers in series")
384  ("Hypertable.RangeServer.AccessGroup.GarbageThreshold.Percentage",
385  i32()->default_value(20), "Perform major compaction when garbage accounts "
386  "for this percentage of the data")
387  ("Hypertable.RangeServer.ControlFile.CheckInterval", i32()->default_value(30000),
388  "Minimum time interval (milliseconds) to check for control files in run/ directory")
389  ("Hypertable.RangeServer.LoadSystemTablesOnly", boo()->default_value(false),
390  "Instructs the RangeServer to only load system tables (for debugging)")
391  ("Hypertable.RangeServer.LowActivityPeriod",
392  strs()->default_value(std::vector<std::string>(), ""),
393  "Periods of low activity during which RangeServer can perform heavy "
394  "maintenance (specified in crontab format)")
395  ("Hypertable.RangeServer.MemoryLimit", i64(), "RangeServer memory limit")
396  ("Hypertable.RangeServer.MemoryLimit.Percentage", i32()->default_value(60),
397  "RangeServer memory limit specified as percentage of physical RAM")
398  ("Hypertable.RangeServer.LowMemoryLimit.Percentage", i32()->default_value(10),
399  "Amount of memory to free in low memory condition as percentage of RangeServer memory limit")
400  ("Hypertable.RangeServer.MemoryLimit.EnsureUnused", i64(), "Amount of unused physical memory")
401  ("Hypertable.RangeServer.MemoryLimit.EnsureUnused.Percentage", i32(),
402  "Amount of unused physical memory specified as percentage of physical RAM")
403  ("Hypertable.RangeServer.Port", i16()->default_value(15865),
404  "Port number on which range servers are or should be listening")
405  ("Hypertable.RangeServer.AccessGroup.CellCache.PageSize",
406  i32()->default_value(512*KiB), "Page size for CellCache pool allocator")
407  ("Hypertable.RangeServer.AccessGroup.CellCache.ScannerCacheSize",
408  i32()->default_value(1024), "CellCache scanner cache size")
409  ("Hypertable.RangeServer.AccessGroup.ShadowCache",
410  boo()->default_value(false), "Enable CellStore shadow caching")
411  ("Hypertable.RangeServer.AccessGroup.MaxMemory", i64()->default_value(1*G),
412  "Maximum bytes consumed by an Access Group")
413  ("Hypertable.RangeServer.CellStore.TargetSize.Minimum",
414  i64()->default_value(10*MiB),
415  "Merging compaction target CellStore size during normal activity period")
416  ("Hypertable.RangeServer.CellStore.TargetSize.Maximum",
417  i64()->default_value(50*MiB),
418  "Merging compaction target CellStore size during low activity period")
419  ("Hypertable.RangeServer.CellStore.TargetSize.Window",
420  i64()->default_value(30*MiB), "Size window above target minimum for "
421  "CellStores in which merges will be considered")
422  ("Hypertable.RangeServer.CellStore.Merge.RunLengthThreshold", i32()->default_value(5),
423  "Trigger a merge if an adjacent run of merge candidate CellStores exceeds this length")
424  ("Hypertable.RangeServer.CellStore.DefaultBlockSize",
425  i32()->default_value(64*KiB), "Default block size for cell stores")
426  ("Hypertable.RangeServer.Data.DefaultReplication",
427  i32()->default_value(-1), "Default replication for data")
428  ("Hypertable.RangeServer.CellStore.DefaultCompressor",
429  str()->default_value("snappy"), "Default compressor for cell stores")
430  ("Hypertable.RangeServer.CellStore.DefaultBloomFilter",
431  str()->default_value("rows"), "Default bloom filter for cell stores")
432  ("Hypertable.RangeServer.CellStore.SkipBad",
433  boo()->default_value(false), "Skip over cell stores that are corrupt")
434  ("Hypertable.RangeServer.CellStore.SkipNotFound",
435  boo()->default_value(false), "Skip over cell stores that are non-existent")
436  ("Hypertable.RangeServer.IgnoreClockSkewErrors",
437  boo()->default_value(false), "Ignore clock skew errors")
438  ("Hypertable.RangeServer.CommitInterval", i32()->default_value(50),
439  "Default minimum group commit interval in milliseconds")
440  ("Hypertable.RangeServer.BlockCache.Compressed", boo()->default_value(true),
441  "Controls whether or not block cache stores compressed blocks")
442  ("Hypertable.RangeServer.BlockCache.MinMemory", i64()->default_value(0),
443  "Minimum size of block cache")
444  ("Hypertable.RangeServer.BlockCache.MaxMemory", i64()->default_value(-1),
445  "Maximum (target) size of block cache")
446  ("Hypertable.RangeServer.QueryCache.EnableMutexStatistics",
447  boo()->default_value(true), "Enable query cache mutex statistics")
448  ("Hypertable.RangeServer.QueryCache.MaxMemory", i64()->default_value(50*M),
449  "Maximum size of query cache")
450  ("Hypertable.RangeServer.Range.RowSize.Unlimited", boo()->default_value(false),
451  "Marks range active and unsplittable upon encountering row overflow condition. "
452  "Can cause ranges to grow extremely large. Use with caution!")
453  ("Hypertable.RangeServer.Range.IgnoreCellsWithClockSkew", boo()->default_value(false),
454  "Forces Ranges to ingore inserted cells whose revision number is older than latest"
455  "revision found in CellStores.")
456  ("Hypertable.RangeServer.Range.SplitSize", i64()->default_value(512*MiB),
457  "Size of range in bytes before splitting")
458  ("Hypertable.RangeServer.Range.MaximumSize", i64()->default_value(3*G),
459  "Maximum size of a range in bytes before updates get throttled")
460  ("Hypertable.RangeServer.Range.MetadataSplitSize", i64(), "Size of METADATA "
461  "range in bytes before splitting (for testing)")
462  ("Hypertable.RangeServer.Range.SplitOff", str()->default_value("high"),
463  "Portion of range to split off (high or low)")
464  ("Hypertable.RangeServer.ClockSkew.Max", i32()->default_value(3*M),
465  "Maximum amount of clock skew (microseconds) the system will tolerate")
466  ("Hypertable.RangeServer.CommitLog.DfsBroker.Host", str(),
467  "Host of DFS Broker to use for Commit Log")
468  ("Hypertable.RangeServer.CommitLog.DfsBroker.Port", i16(),
469  "Port of DFS Broker to use for Commit Log")
470  ("Hypertable.RangeServer.CommitLog.FragmentRemoval.RangeReferenceRequired", boo()->default_value(true),
471  "Only remove linked log fragments if they're part of a transfer log referenced by a range")
472  ("Hypertable.RangeServer.CommitLog.PruneThreshold.Min", i64()->default_value(1*G),
473  "Lower threshold for amount of outstanding commit log before pruning")
474  ("Hypertable.RangeServer.CommitLog.PruneThreshold.Max", i64(),
475  "Upper threshold for amount of outstanding commit log before pruning")
476  ("Hypertable.RangeServer.CommitLog.PruneThreshold.Max.MemoryPercentage",
477  i32()->default_value(50), "Upper threshold in terms of % RAM for "
478  "amount of outstanding commit log before pruning")
479  ("Hypertable.RangeServer.CommitLog.RollLimit", i64()->default_value(100*M),
480  "Roll commit log after this many bytes")
481  ("Hypertable.RangeServer.CommitLog.Compressor",
482  str()->default_value("quicklz"),
483  "Commit log compressor to use (zlib, lzo, quicklz, snappy, bmz, none)")
484  ("Hypertable.RangeServer.Testing.MaintenanceNeeded.PauseInterval", i32()->default_value(0),
485  "TESTING: After update, if range needs maintenance, pause for this number of milliseconds")
486  ("Hypertable.RangeServer.UpdateCoalesceLimit", i64()->default_value(5*M),
487  "Amount of update data to coalesce into single commit log sync")
488  ("Hypertable.RangeServer.Failover.FlushLimit.PerRange",
489  i32()->default_value(10*M), "Amount of updates (bytes) accumulated for a "
490  "single range to trigger a replay buffer flush")
491  ("Hypertable.RangeServer.Failover.FlushLimit.Aggregate",
492  i64()->default_value(100*M), "Amount of updates (bytes) accumulated for "
493  "all range to trigger a replay buffer flush")
494  ("Hypertable.RangeServer.ReadyStatus", str()->default_value("WARNING"),
495  "Status code indicating RangeServer is ready for operation")
496  ("Hypertable.Metadata.Replication", i32()->default_value(-1),
497  "Replication factor for commit log files")
498  ("Hypertable.CommitLog.RollLimit", i64()->default_value(100*M),
499  "Roll commit log after this many bytes")
500  ("Hypertable.CommitLog.Compressor", str()->default_value("quicklz"),
501  "Commit log compressor to use (zlib, lzo, quicklz, snappy, bmz, none)")
502  ("Hypertable.CommitLog.SkipErrors", boo()->default_value(false),
503  "Skip over any corruption encountered in the commit log")
504  ("Hypertable.RangeServer.Scanner.Ttl", i32()->default_value(1800*K),
505  "Number of milliseconds of inactivity before destroying scanners")
506  ("Hypertable.RangeServer.Scanner.BufferSize", i64()->default_value(1*M),
507  "Size of transfer buffer for scan results")
508  ("Hypertable.RangeServer.Timer.Interval", i32()->default_value(20000),
509  "Timer interval in milliseconds (reaping scanners, purging commit logs, etc.)")
510  ("Hypertable.RangeServer.Maintenance.Interval", i32()->default_value(30000),
511  "Maintenance scheduling interval in milliseconds")
512  ("Hypertable.RangeServer.Maintenance.LowMemoryPrioritization", boo()->default_value(true),
513  "Use low memory prioritization algorithm for freeing memory in low memory mode")
514  ("Hypertable.RangeServer.Maintenance.MaxAppQueuePause", i32()->default_value(120000),
515  "Each time application queue is paused, keep it paused for no more than this many milliseconds")
516  ("Hypertable.RangeServer.Maintenance.MergesPerInterval", i32(),
517  "Limit on number of merging tasks to create per maintenance interval")
518  ("Hypertable.RangeServer.Maintenance.MergingCompaction.Delay", i32()->default_value(900000),
519  "Millisecond delay before scheduling merging compactions in non-low memory mode")
520  ("Hypertable.RangeServer.Maintenance.MoveCompactionsPerInterval", i32()->default_value(2),
521  "Limit on number of major compactions due to move per maintenance interval")
522  ("Hypertable.RangeServer.Maintenance.InitializationPerInterval", i32(),
523  "Limit on number of initialization tasks to create per maintenance interval")
524  ("Hypertable.RangeServer.Monitoring.DataDirectories", str()->default_value("/"),
525  "Comma-separated list of directory mount points of disk volumes to monitor")
526  ("Hypertable.RangeServer.Workers", i32()->default_value(50),
527  "Number of Range Server worker threads created")
528  ("Hypertable.RangeServer.Reactors", i32(),
529  "Number of Range Server communication reactor threads created")
530  ("Hypertable.RangeServer.MaintenanceThreads", i32(),
531  "Number of maintenance threads. Default is min(2, number-of-cores).")
532  ("Hypertable.RangeServer.UpdateDelay", i32()->default_value(0),
533  "Number of milliseconds to wait before carrying out an update (TESTING)")
534  ("Hypertable.RangeServer.ProxyName", str()->default_value(""),
535  "Use this value for the proxy name (if set) instead of reading from run dir.")
536  ("ThriftBroker.Timeout", i32(), "Timeout (ms) for thrift broker")
537  ("ThriftBroker.Host", str()->default_value("localhost"),
538  "Host on which the ThriftBroker is running (read by clients only)")
539  ("ThriftBroker.Port", i16()->default_value(15867), "Port number for "
540  "thrift broker")
541  ("ThriftBroker.Future.Capacity", i32()->default_value(50*M), "Capacity "
542  "of result queue (in bytes) for Future objects")
543  ("ThriftBroker.NextThreshold", i32()->default_value(512*K), "Total size "
544  "threshold for (size of cell data) for thrift broker next calls")
545  ("ThriftBroker.API.Logging", boo()->default_value(false), "Enable or "
546  "disable Thrift API logging")
547  ("ThriftBroker.Mutator.FlushInterval", i32()->default_value(1000),
548  "Maximum flush interval in milliseconds")
549  ("ThriftBroker.Workers", i32()->default_value(50), "Number of "
550  "worker threads for thrift broker")
551  ("ThriftBroker.Hyperspace.Session.Reconnect", boo()->default_value(true),
552  "ThriftBroker will reconnect to Hyperspace on session expiry")
553  ("ThriftBroker.SlowQueryLog.Enable", boo()->default_value(true),
554  "Enable slow query logging")
555  ("ThriftBroker.SlowQueryLog.LatencyThreshold", i32()->default_value(10000),
556  "Latency threshold above which a query is considered slow")
557  ;
558  alias("Hypertable.RangeServer.CommitLog.RollLimit",
559  "Hypertable.CommitLog.RollLimit");
560  alias("Hypertable.RangeServer.CommitLog.Compressor",
561  "Hypertable.CommitLog.Compressor");
562  // add config file desc to cmdline hidden desc, so people can override
563  // any config values on the command line
565 }
566 
567 void parse_args(int argc, char *argv[]) {
568  std::lock_guard<std::recursive_mutex> lock(rec_mutex);
569 
570  HT_TRY("parsing init arguments",
571  properties->parse_args(argc, argv, cmdline_desc(), cmdline_hidden_descp,
572  cmdline_positional_descp, allow_unregistered));
573  // some built-in behavior
574  if (has("help")) {
575  std::cout << cmdline_desc() << std::flush;
576  std::quick_exit(EXIT_SUCCESS);
577  }
578 
579  if (has("help-config")) {
580  std::cout << file_desc() << std::flush;
581  std::quick_exit(EXIT_SUCCESS);
582  }
583 
584  if (has("version")) {
585  std::cout << version_string() << std::endl;
586  std::quick_exit(EXIT_SUCCESS);
587  }
588 
589  filename = get_str("config");
590 
591  // Only try to parse config file if it exists or not default
592  if (FileUtils::exists(filename)) {
593  parse_file(filename, cmdline_hidden_desc());
594  file_loaded = true;
595  }
596  else if (!defaulted("config"))
597  HT_THROW(Error::FILE_NOT_FOUND, filename);
598 
599  sync_aliases(); // call before use
600 }
601 
602 void
603 parse_file(const String &fname, const Desc &desc) {
604  properties->load(fname, desc, allow_unregistered);
605 }
606 
607 void alias(const String &cmdline_opt, const String &file_opt, bool overwrite) {
608  properties->alias(cmdline_opt, file_opt, overwrite);
609 }
610 
611 void sync_aliases() {
612  properties->sync_aliases();
613 }
614 
616  String loglevel = get_str("logging-level");
617  bool verbose = get_bool("verbose");
618 
619  if (verbose && get_bool("quiet")) {
620  verbose = false;
621  properties->set("verbose", false);
622  }
623  if (get_bool("debug")) {
624  loglevel = "debug";
625  properties->set("logging-level", loglevel);
626  }
627 
628  if (loglevel == "info")
630  else if (loglevel == "debug")
632  else if (loglevel == "notice")
634  else if (loglevel == "warn")
636  else if (loglevel == "error")
638  else if (loglevel == "crit")
640  else if (loglevel == "alert")
642  else if (loglevel == "fatal")
644  else {
645  HT_ERROR_OUT << "unknown logging level: "<< loglevel << HT_END;
646  std::quick_exit(EXIT_SUCCESS);
647  }
648  if (verbose) {
649  HT_NOTICE_OUT << "Initializing " << System::exe_name << " (Hypertable "
650  << version_string() << ")..." << HT_END;
651  }
652 }
653 
654 bool allow_unregistered_options(bool choice) {
655  std::lock_guard<std::recursive_mutex> lock(rec_mutex);
656  bool old = allow_unregistered;
657  allow_unregistered = choice;
658  return old;
659 }
660 
662  std::lock_guard<std::recursive_mutex> lock(rec_mutex);
663  return allow_unregistered;
664 }
665 
666 void cleanup() {
667  std::lock_guard<std::recursive_mutex> lock(rec_mutex);
668  properties = 0;
669  if (cmdline_descp) {
670  delete cmdline_descp;
671  cmdline_descp = 0;
672  }
673  if (cmdline_hidden_descp) {
674  delete cmdline_hidden_descp;
675  cmdline_hidden_descp = 0;
676  }
677  if (cmdline_positional_descp) {
679  cmdline_positional_descp = 0;
680  }
681  if (file_descp) {
682  delete file_descp;
683  file_descp = 0;
684  }
685 }
686 
687 }} // namespace Hypertable::Config
static int terminal_line_length()
Definition: Config.cc:57
static Desc * cmdline_hidden_descp
Definition: Config.cc:53
Path parent_path() const
Definition: Path.h:61
static String filename
Definition: Config.cc:48
static bool allow_unregistered
Definition: Config.cc:50
PropertiesPtr properties
This singleton map stores all options.
Definition: Config.cc:47
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
Compatibility class for boost::filesystem::path.
Po::positional_options_description PositionalDesc
Definition: Properties.h:201
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Definition: String.cc:37
Po::typed_value< uint16_t > * i16(uint16_t *v=0)
Definition: Properties.h:174
Po::typed_value< String > * str(String *v=0)
Definition: Properties.h:166
static const ProcInfo & proc_info()
Retrieves updated Process information (see SystemInfo.h)
Definition: SystemInfo.cc:373
PropertiesDesc Desc
Definition: Config.h:44
static bool exists(const String &fname)
Checks if a file or directory exists.
Definition: FileUtils.cc:420
const uint64_t MiB
Definition: Properties.h:157
void parse_file(const String &fname, const Desc &desc)
Parses a configuration file and stores all configuration options into the option descriptor.
Definition: Config.cc:603
Desc & cmdline_desc(const char *usage)
A macro which definds global functions like get_bool(), get_str(), get_i16() etc. ...
Definition: Config.cc:72
bool has(const String &name)
Check existence of a configuration value.
Definition: Config.h:57
#define HT_EXPECT(_e_, _code_)
Definition: Logger.h:388
const uint64_t KiB
Definition: Properties.h:155
static bool file_loaded
Definition: Config.cc:49
const uint64_t G
Definition: Properties.h:158
Compatibility class for boost::filesystem::path.
Definition: Path.h:45
File system utility functions.
Po::typed_value< int64_t > * i64(int64_t *v=0)
Definition: Properties.h:182
Po::typed_value< int32_t > * i32(int32_t *v=0)
Definition: Properties.h:178
static String exe_name
The exe file name.
Definition: System.h:120
static String usage_str(const char *usage)
Definition: Config.cc:62
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
Logging routines and macros.
const uint64_t K
Definition: Properties.h:154
Desc & file_desc(const char *usage)
Get the config file options description.
Definition: Config.cc:108
Compatibility Macros for C/C++.
void cleanup()
Free all resources used.
Definition: Config.cc:666
Po::typed_value< bool > * boo(bool *v=0)
Definition: Properties.h:162
#define HT_END
Definition: Logger.h:220
bool defaulted(const String &name)
Check if a configuration value is defaulted.
Definition: Config.h:67
void parse_args(int argc, char *argv[])
Initialization helper; parses the argc/argv parameters into properties, reads the configuration file...
Definition: Config.cc:567
#define HT_ERROR_OUT
Definition: Logger.h:301
static Desc * cmdline_descp
Definition: Config.cc:52
bool allow_unregistered_options(bool choice)
Toggle allow unregistered options.
Definition: Config.cc:654
Po::typed_value< Strings > * strs(Strings *v=0)
Definition: Properties.h:170
Hypertable definitions
static PositionalDesc * cmdline_positional_descp
Definition: Config.cc:54
void sync_aliases()
Sync alias values.
Definition: Config.cc:611
#define HT_NOTICE_OUT
Definition: Logger.h:281
static Desc * file_descp
Definition: Config.cc:55
LogWriter * get()
Accessor for the LogWriter singleton instance.
Definition: Logger.cc:49
std::recursive_mutex rec_mutex
A global (recursive) configuration mutex.
Definition: Config.cc:46
static String install_dir
The installation directory.
Definition: System.h:114
const uint64_t M
Definition: Properties.h:156
A String class based on std::string.
void set_level(int level)
Sets the message level; all messages with a higher level are discarded.
Definition: Logger.h:83
static const TermInfo & term_info()
Retrieves updated Terminal information (see SystemInfo.h)
Definition: SystemInfo.cc:390
Configuration settings.
#define HT_TRY(_s_, _code_)
Definition: Error.h:517
Po::typed_value< double > * f64(double *v=0)
Definition: Properties.h:190
void alias(const String &cmdline_opt, const String &file_opt, bool overwrite)
Setup command line option alias for config file option.
Definition: Config.cc:607
Desc & cmdline_hidden_desc()
Get the command line hidden options description (for positional options)
Definition: Config.cc:81
System information and statistics based on libsigar.
PositionalDesc & cmdline_positional_desc()
Get the command line positional options description.
Definition: Config.cc:90
#define HT_THROW(_code_, _msg_)
Definition: Error.h:478
const char * version_string()
Definition: Version.cc:37