| 1 | /* |
| 2 | * cfg.h |
| 3 | * |
| 4 | * Copyright (C) 2008-2016 Aerospike, Inc. |
| 5 | * |
| 6 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
| 7 | * license agreements. |
| 8 | * |
| 9 | * This program is free software: you can redistribute it and/or modify it under |
| 10 | * the terms of the GNU Affero General Public License as published by the Free |
| 11 | * Software Foundation, either version 3 of the License, or (at your option) any |
| 12 | * later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
| 17 | * details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see http://www.gnu.org/licenses/ |
| 21 | */ |
| 22 | |
| 23 | #pragma once |
| 24 | |
| 25 | //========================================================== |
| 26 | // Includes. |
| 27 | // |
| 28 | |
| 29 | #include <grp.h> |
| 30 | #include <pwd.h> |
| 31 | #include <stdbool.h> |
| 32 | #include <stdint.h> |
| 33 | |
| 34 | #include "xdr_config.h" |
| 35 | |
| 36 | #include "aerospike/mod_lua_config.h" |
| 37 | #include "citrusleaf/cf_atomic.h" |
| 38 | |
| 39 | #include "enhanced_alloc.h" |
| 40 | #include "hardware.h" |
| 41 | #include "node.h" |
| 42 | #include "socket.h" |
| 43 | #include "tls.h" |
| 44 | |
| 45 | #include "base/security_config.h" |
| 46 | #include "fabric/clustering.h" |
| 47 | #include "fabric/fabric.h" |
| 48 | #include "fabric/hb.h" |
| 49 | #include "fabric/hlc.h" |
| 50 | |
| 51 | |
| 52 | //========================================================== |
| 53 | // Forward declarations. |
| 54 | // |
| 55 | |
| 56 | struct as_namespace_s; |
| 57 | |
| 58 | |
| 59 | //========================================================== |
| 60 | // Typedefs and constants. |
| 61 | // |
| 62 | |
| 63 | #ifndef AS_NAMESPACE_SZ |
| 64 | #define AS_NAMESPACE_SZ 2 |
| 65 | #endif |
| 66 | |
| 67 | #define AS_CLUSTER_NAME_SZ 65 |
| 68 | |
| 69 | #define MAX_BATCH_THREADS 256 |
| 70 | #define MAX_TLS_SPECS 10 |
| 71 | |
| 72 | typedef struct as_config_s { |
| 73 | |
| 74 | // The order here matches that in the configuration parser's enum, |
| 75 | // cfg_case_id. This is for organizational sanity. |
| 76 | |
| 77 | //-------------------------------------------- |
| 78 | // service context. |
| 79 | // |
| 80 | |
| 81 | // Normally visible, in canonical configuration file order: |
| 82 | |
| 83 | uid_t uid; |
| 84 | gid_t gid; |
| 85 | uint32_t paxos_single_replica_limit; // cluster size at which, and below, the cluster will run with replication factor 1 |
| 86 | char* pidfile; |
| 87 | uint32_t n_proto_fd_max; |
| 88 | |
| 89 | // Normally hidden: |
| 90 | |
| 91 | // Note - advertise-ipv6 affects a cf_socket_ee.c global, so can't be here. |
| 92 | cf_topo_auto_pin auto_pin; |
| 93 | uint32_t n_batch_index_threads; |
| 94 | uint32_t batch_max_buffers_per_queue; // maximum number of buffers allowed in a buffer queue at any one time, fail batch if full |
| 95 | uint32_t batch_max_requests; // maximum count of database requests in a single batch |
| 96 | uint32_t batch_max_unused_buffers; // maximum number of buffers allowed in buffer pool at any one time |
| 97 | char cluster_name[AS_CLUSTER_NAME_SZ]; |
| 98 | as_clustering_config clustering_config; |
| 99 | bool fabric_benchmarks_enabled; |
| 100 | bool svc_benchmarks_enabled; |
| 101 | bool health_check_enabled; |
| 102 | bool info_hist_enabled; |
| 103 | const char* feature_key_file; |
| 104 | uint32_t hist_track_back; // total time span in seconds over which to cache data |
| 105 | uint32_t hist_track_slice; // period in seconds at which to cache histogram data |
| 106 | char* hist_track_thresholds; // comma-separated bucket (ms) values to track |
| 107 | uint32_t n_info_threads; |
| 108 | bool keep_caps_ssd_health; |
| 109 | // Note - log-local-time affects a cf_fault.c global, so can't be here. |
| 110 | uint32_t migrate_fill_delay; |
| 111 | uint32_t migrate_max_num_incoming; |
| 112 | uint32_t n_migrate_threads; |
| 113 | char* node_id_interface; |
| 114 | int proto_fd_idle_ms; // after this many milliseconds, connections are aborted unless transaction is in progress |
| 115 | int proto_slow_netio_sleep_ms; // dynamic only |
| 116 | uint32_t query_bsize; |
| 117 | uint64_t query_buf_size; // dynamic only |
| 118 | uint32_t query_bufpool_size; |
| 119 | bool query_in_transaction_thr; |
| 120 | uint32_t query_long_q_max_size; |
| 121 | bool query_enable_histogram; |
| 122 | bool partitions_pre_reserved; // query will reserve all partitions up front |
| 123 | uint32_t query_priority; |
| 124 | uint64_t query_sleep_us; |
| 125 | uint64_t query_rec_count_bound; |
| 126 | bool query_req_in_query_thread; |
| 127 | uint32_t query_req_max_inflight; |
| 128 | uint32_t query_short_q_max_size; |
| 129 | uint32_t query_threads; |
| 130 | uint32_t query_threshold; |
| 131 | uint64_t query_untracked_time_ms; |
| 132 | uint32_t query_worker_threads; |
| 133 | bool run_as_daemon; |
| 134 | uint32_t scan_max_done; // maximum number of finished scans kept for monitoring |
| 135 | uint32_t n_scan_threads_limit; |
| 136 | uint32_t n_service_threads; |
| 137 | uint32_t sindex_builder_threads; // secondary index builder thread pool size |
| 138 | uint32_t sindex_gc_max_rate; // Max sindex entries processed per second for gc |
| 139 | uint32_t sindex_gc_period; // same as nsup_period for sindex gc |
| 140 | uint32_t ticker_interval; |
| 141 | uint64_t transaction_max_ns; |
| 142 | uint32_t transaction_retry_ms; |
| 143 | char* work_directory; |
| 144 | |
| 145 | // For special debugging or bug-related repair: |
| 146 | |
| 147 | cf_alloc_debug debug_allocations; // how to instrument the memory allocation API |
| 148 | bool fabric_dump_msgs; // whether to log information about existing "msg" objects and queues |
| 149 | bool indent_allocations; // pointer indentation for better double-free detection |
| 150 | |
| 151 | //-------------------------------------------- |
| 152 | // network::service context. |
| 153 | // |
| 154 | |
| 155 | // Normally visible, in canonical configuration file order: |
| 156 | |
| 157 | cf_serv_spec service; // client service |
| 158 | |
| 159 | // Normally hidden: |
| 160 | |
| 161 | cf_serv_spec tls_service; // TLS client service |
| 162 | |
| 163 | //-------------------------------------------- |
| 164 | // network::heartbeat context. |
| 165 | // |
| 166 | |
| 167 | cf_serv_spec hb_serv_spec; // literal binding address spec parsed from config |
| 168 | cf_serv_spec hb_tls_serv_spec; // literal binding address spec for TLS parsed from config |
| 169 | cf_addr_list hb_multicast_groups; // literal multicast groups parsed from config |
| 170 | as_hb_config hb_config; |
| 171 | |
| 172 | //-------------------------------------------- |
| 173 | // network::fabric context. |
| 174 | // |
| 175 | |
| 176 | // Normally visible, in canonical configuration file order: |
| 177 | |
| 178 | cf_serv_spec fabric; // fabric service |
| 179 | cf_serv_spec tls_fabric; // TLS fabric service |
| 180 | |
| 181 | // Normally hidden: |
| 182 | |
| 183 | uint32_t n_fabric_channel_fds[AS_FABRIC_N_CHANNELS]; |
| 184 | uint32_t n_fabric_channel_recv_threads[AS_FABRIC_N_CHANNELS]; |
| 185 | bool fabric_keepalive_enabled; |
| 186 | int fabric_keepalive_intvl; |
| 187 | int fabric_keepalive_probes; |
| 188 | int fabric_keepalive_time; |
| 189 | uint32_t fabric_latency_max_ms; // time window for ordering |
| 190 | uint32_t fabric_recv_rearm_threshold; |
| 191 | uint32_t n_fabric_send_threads; |
| 192 | |
| 193 | //-------------------------------------------- |
| 194 | // network::info context. |
| 195 | // |
| 196 | |
| 197 | // Normally visible, in canonical configuration file order: |
| 198 | |
| 199 | cf_serv_spec info; // info service |
| 200 | |
| 201 | //-------------------------------------------- |
| 202 | // Remaining configuration top-level contexts. |
| 203 | // |
| 204 | |
| 205 | mod_lua_config mod_lua; |
| 206 | as_sec_config sec_cfg; |
| 207 | |
| 208 | uint32_t n_tls_specs; |
| 209 | cf_tls_spec tls_specs[MAX_TLS_SPECS]; |
| 210 | |
| 211 | |
| 212 | //====================================================== |
| 213 | // Not (directly) configuration. Many should probably be |
| 214 | // relocated... |
| 215 | // |
| 216 | |
| 217 | // Global variable that just shouldn't be here. |
| 218 | cf_node self_node; |
| 219 | |
| 220 | // Global variables that just shouldn't be here. |
| 221 | cf_node xdr_clmap[AS_CLUSTER_SZ]; // cluster map as known to XDR |
| 222 | xdr_node_lst xdr_peers_lst[AS_CLUSTER_SZ]; // last XDR shipping info of other nodes |
| 223 | uint64_t xdr_self_lastshiptime[DC_MAX_NUM]; // last XDR shipping by this node |
| 224 | |
| 225 | // Namespaces. |
| 226 | struct as_namespace_s* namespaces[AS_NAMESPACE_SZ]; |
| 227 | uint32_t n_namespaces; |
| 228 | |
| 229 | // To speed up transaction enqueue's determination of whether to "inline": |
| 230 | uint32_t n_namespaces_inlined; |
| 231 | uint32_t n_namespaces_not_inlined; |
| 232 | |
| 233 | } as_config; |
| 234 | |
| 235 | |
| 236 | //========================================================== |
| 237 | // Public API. |
| 238 | // |
| 239 | |
| 240 | as_config* as_config_init(const char* config_file); |
| 241 | void as_config_post_process(as_config* c, const char* config_file); |
| 242 | |
| 243 | void as_config_cluster_name_get(char* cluster_name); |
| 244 | bool as_config_cluster_name_set(const char* cluster_name); |
| 245 | bool as_config_cluster_name_matches(const char* cluster_name); |
| 246 | |
| 247 | void as_config_init_namespace(struct as_namespace_s* ns); |
| 248 | bool as_config_error_enterprise_only(); |
| 249 | bool as_config_error_enterprise_feature_only(const char* name); |
| 250 | bool as_info_error_enterprise_only(); // TODO - until we have an info split |
| 251 | |
| 252 | extern as_config g_config; |
| 253 | |
| 254 | static inline bool |
| 255 | as_config_is_cpu_pinned(void) |
| 256 | { |
| 257 | return g_config.auto_pin == CF_TOPO_AUTO_PIN_CPU || |
| 258 | g_config.auto_pin == CF_TOPO_AUTO_PIN_NUMA; |
| 259 | } |
| 260 | |
| 261 | static inline bool |
| 262 | as_config_is_numa_pinned(void) |
| 263 | { |
| 264 | return g_config.auto_pin == CF_TOPO_AUTO_PIN_NUMA || |
| 265 | g_config.auto_pin == CF_TOPO_AUTO_PIN_ADQ; |
| 266 | } |
| 267 | |
| 268 | |
| 269 | //========================================================== |
| 270 | // Private API - for enterprise separation only. |
| 271 | // |
| 272 | |
| 273 | // Parsed configuration file line. |
| 274 | typedef struct cfg_line_s { |
| 275 | int num; |
| 276 | char* name_tok; |
| 277 | char* val_tok_1; |
| 278 | char* val_tok_2; |
| 279 | char* val_tok_3; |
| 280 | } cfg_line; |
| 281 | |
| 282 | void cfg_enterprise_only(const cfg_line* p_line); |
| 283 | void cfg_post_process(); |
| 284 | cf_tls_spec* cfg_link_tls(const char* which, char** our_name); |
| 285 | |