wafsamba: fix pidl dependencies to rebuild on pidl changes
[Samba.git] / ctdb / common / tunable.c
blobf516d8c537424ce77bb8d2d4f703f934e2a02782
1 /*
2 Tunables utilities
4 Copyright (C) Amitay Isaacs 2016
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program 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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "replace.h"
21 #include "system/locale.h"
22 #include "system/network.h"
24 #include <talloc.h>
26 #include "protocol/protocol.h"
28 #include "common/tunable.h"
30 static struct {
31 const char *label;
32 uint32_t value;
33 bool obsolete;
34 size_t offset;
35 } tunable_map[] = {
36 { "MaxRedirectCount", 3, true,
37 offsetof(struct ctdb_tunable_list, max_redirect_count) },
38 { "SeqnumInterval", 1000, false,
39 offsetof(struct ctdb_tunable_list, seqnum_interval) },
40 { "ControlTimeout", 60, false,
41 offsetof(struct ctdb_tunable_list, control_timeout) },
42 { "TraverseTimeout", 20, false,
43 offsetof(struct ctdb_tunable_list, traverse_timeout) },
44 { "KeepaliveInterval", 5, false,
45 offsetof(struct ctdb_tunable_list, keepalive_interval) },
46 { "KeepaliveLimit", 5, false,
47 offsetof(struct ctdb_tunable_list, keepalive_limit) },
48 { "RecoverTimeout", 30, false,
49 offsetof(struct ctdb_tunable_list, recover_timeout) },
50 { "RecoverInterval", 1, false,
51 offsetof(struct ctdb_tunable_list, recover_interval) },
52 { "ElectionTimeout", 3, false,
53 offsetof(struct ctdb_tunable_list, election_timeout) },
54 { "TakeoverTimeout", 9, false,
55 offsetof(struct ctdb_tunable_list, takeover_timeout) },
56 { "MonitorInterval", 15, false,
57 offsetof(struct ctdb_tunable_list, monitor_interval) },
58 { "TickleUpdateInterval", 20, false,
59 offsetof(struct ctdb_tunable_list, tickle_update_interval) },
60 { "EventScriptTimeout", 30, false,
61 offsetof(struct ctdb_tunable_list, script_timeout) },
62 { "MonitorTimeoutCount", 20, false,
63 offsetof(struct ctdb_tunable_list, monitor_timeout_count) },
64 { "EventScriptUnhealthyOnTimeout", 0, true,
65 offsetof(struct ctdb_tunable_list, script_unhealthy_on_timeout) },
66 { "RecoveryGracePeriod", 120, false,
67 offsetof(struct ctdb_tunable_list, recovery_grace_period) },
68 { "RecoveryBanPeriod", 300, false,
69 offsetof(struct ctdb_tunable_list, recovery_ban_period) },
70 { "DatabaseHashSize", 100001, false,
71 offsetof(struct ctdb_tunable_list, database_hash_size) },
72 { "DatabaseMaxDead", 5, false,
73 offsetof(struct ctdb_tunable_list, database_max_dead) },
74 { "RerecoveryTimeout", 10, false,
75 offsetof(struct ctdb_tunable_list, rerecovery_timeout) },
76 { "EnableBans", 1, false,
77 offsetof(struct ctdb_tunable_list, enable_bans) },
78 { "DeterministicIPs", 0, true,
79 offsetof(struct ctdb_tunable_list, deterministic_public_ips) },
80 { "LCP2PublicIPs", 1, true,
81 offsetof(struct ctdb_tunable_list, lcp2_public_ip_assignment) },
82 { "ReclockPingPeriod", 60, true,
83 offsetof(struct ctdb_tunable_list, reclock_ping_period) },
84 { "NoIPFailback", 0, false,
85 offsetof(struct ctdb_tunable_list, no_ip_failback) },
86 { "DisableIPFailover", 0, true,
87 offsetof(struct ctdb_tunable_list, disable_ip_failover) },
88 { "VerboseMemoryNames", 0, false,
89 offsetof(struct ctdb_tunable_list, verbose_memory_names) },
90 { "RecdPingTimeout", 60, false,
91 offsetof(struct ctdb_tunable_list, recd_ping_timeout) },
92 { "RecdFailCount", 10, false,
93 offsetof(struct ctdb_tunable_list, recd_ping_failcount) },
94 { "LogLatencyMs", 0, false,
95 offsetof(struct ctdb_tunable_list, log_latency_ms) },
96 { "RecLockLatencyMs", 1000, false,
97 offsetof(struct ctdb_tunable_list, reclock_latency_ms) },
98 { "RecoveryDropAllIPs", 120, false,
99 offsetof(struct ctdb_tunable_list, recovery_drop_all_ips) },
100 { "VerifyRecoveryLock", 1, true,
101 offsetof(struct ctdb_tunable_list, verify_recovery_lock) },
102 { "VacuumInterval", 10, false,
103 offsetof(struct ctdb_tunable_list, vacuum_interval) },
104 { "VacuumMaxRunTime", 120, false,
105 offsetof(struct ctdb_tunable_list, vacuum_max_run_time) },
106 { "RepackLimit", 10*1000, false,
107 offsetof(struct ctdb_tunable_list, repack_limit) },
108 { "VacuumLimit", 5*1000, false,
109 offsetof(struct ctdb_tunable_list, vacuum_limit) },
110 { "VacuumFastPathCount", 60, false,
111 offsetof(struct ctdb_tunable_list, vacuum_fast_path_count) },
112 { "MaxQueueDropMsg", 1000*1000, false,
113 offsetof(struct ctdb_tunable_list, max_queue_depth_drop_msg) },
114 { "AllowUnhealthyDBRead", 0, false,
115 offsetof(struct ctdb_tunable_list, allow_unhealthy_db_read) },
116 { "StatHistoryInterval", 1, false,
117 offsetof(struct ctdb_tunable_list, stat_history_interval) },
118 { "DeferredAttachTO", 120, false,
119 offsetof(struct ctdb_tunable_list, deferred_attach_timeout) },
120 { "AllowClientDBAttach", 1, false,
121 offsetof(struct ctdb_tunable_list, allow_client_db_attach) },
122 { "RecoverPDBBySeqNum", 1, true,
123 offsetof(struct ctdb_tunable_list, recover_pdb_by_seqnum) },
124 { "DeferredRebalanceOnNodeAdd", 300, true,
125 offsetof(struct ctdb_tunable_list, deferred_rebalance_on_node_add) },
126 { "FetchCollapse", 1, false,
127 offsetof(struct ctdb_tunable_list, fetch_collapse) },
128 { "HopcountMakeSticky", 50, false,
129 offsetof(struct ctdb_tunable_list, hopcount_make_sticky) },
130 { "StickyDuration", 600, false,
131 offsetof(struct ctdb_tunable_list, sticky_duration) },
132 { "StickyPindown", 200, false,
133 offsetof(struct ctdb_tunable_list, sticky_pindown) },
134 { "NoIPTakeover", 0, false,
135 offsetof(struct ctdb_tunable_list, no_ip_takeover) },
136 { "DBRecordCountWarn", 100*1000, false,
137 offsetof(struct ctdb_tunable_list, db_record_count_warn) },
138 { "DBRecordSizeWarn", 10*1000*1000, false,
139 offsetof(struct ctdb_tunable_list, db_record_size_warn) },
140 { "DBSizeWarn", 100*1000*1000, false,
141 offsetof(struct ctdb_tunable_list, db_size_warn) },
142 { "PullDBPreallocation", 10*1024*1024, false,
143 offsetof(struct ctdb_tunable_list, pulldb_preallocation_size) },
144 { "NoIPHostOnAllDisabled", 1, true,
145 offsetof(struct ctdb_tunable_list, no_ip_host_on_all_disabled) },
146 { "Samba3AvoidDeadlocks", 0, true,
147 offsetof(struct ctdb_tunable_list, samba3_hack) },
148 { "TDBMutexEnabled", 1, true,
149 offsetof(struct ctdb_tunable_list, mutex_enabled) },
150 { "LockProcessesPerDB", 200, false,
151 offsetof(struct ctdb_tunable_list, lock_processes_per_db) },
152 { "RecBufferSizeLimit", 1000*1000, false,
153 offsetof(struct ctdb_tunable_list, rec_buffer_size_limit) },
154 { "QueueBufferSize", 1024, false,
155 offsetof(struct ctdb_tunable_list, queue_buffer_size) },
156 { "IPAllocAlgorithm", 2, false,
157 offsetof(struct ctdb_tunable_list, ip_alloc_algorithm) },
158 { "AllowMixedVersions", 0, false,
159 offsetof(struct ctdb_tunable_list, allow_mixed_versions) },
160 { NULL, 0, true, }
163 void ctdb_tunable_set_defaults(struct ctdb_tunable_list *tun_list)
165 int i;
167 for (i=0; tunable_map[i].label != NULL; i++) {
168 size_t offset = tunable_map[i].offset;
169 uint32_t value = tunable_map[i].value;
170 uint32_t *value_ptr;
172 value_ptr = (uint32_t *)((uint8_t *)tun_list + offset);
173 *value_ptr = value;
177 bool ctdb_tunable_get_value(struct ctdb_tunable_list *tun_list,
178 const char *tunable_str, uint32_t *value)
180 int i;
182 for (i=0; tunable_map[i].label != NULL; i++) {
183 if (strcasecmp(tunable_map[i].label, tunable_str) == 0) {
184 uint32_t *value_ptr;
186 value_ptr = (uint32_t *)((uint8_t *)tun_list +
187 tunable_map[i].offset);
188 *value = *value_ptr;
189 return true;
193 return false;
196 bool ctdb_tunable_set_value(struct ctdb_tunable_list *tun_list,
197 const char *tunable_str, uint32_t value,
198 bool *obsolete)
200 int i;
202 for (i=0; tunable_map[i].label != NULL; i++) {
203 if (strcasecmp(tunable_map[i].label, tunable_str) == 0) {
204 uint32_t *value_ptr;
206 value_ptr = (uint32_t *)((uint8_t *)tun_list +
207 tunable_map[i].offset);
208 *value_ptr = value;
209 if (obsolete != NULL) {
210 *obsolete = tunable_map[i].obsolete;
212 return true;
216 return false;
219 struct ctdb_var_list *ctdb_tunable_names(TALLOC_CTX *mem_ctx)
221 struct ctdb_var_list *list;
222 int i;
224 list = talloc_zero(mem_ctx, struct ctdb_var_list);
225 if (list == NULL) {
226 return NULL;
229 for (i=0; tunable_map[i].label != NULL; i++) {
230 if (tunable_map[i].obsolete) {
231 continue;
234 list->var = talloc_realloc(list, list->var, const char *,
235 list->count + 1);
236 if (list->var == NULL) {
237 goto fail;
240 list->var[list->count] = talloc_strdup(list,
241 tunable_map[i].label);
242 if (list->var[list->count] == NULL) {
243 goto fail;
246 list->count += 1;
249 return list;
251 fail:
252 TALLOC_FREE(list);
253 return NULL;
256 char *ctdb_tunable_names_to_string(TALLOC_CTX *mem_ctx)
258 char *str = NULL;
259 int i;
261 str = talloc_strdup(mem_ctx, ":");
262 if (str == NULL) {
263 return NULL;
266 for (i=0; tunable_map[i].label != NULL; i++) {
267 if (tunable_map[i].obsolete) {
268 continue;
271 str = talloc_asprintf_append(str, "%s:",
272 tunable_map[i].label);
273 if (str == NULL) {
274 return NULL;
278 /* Remove the last ':' */
279 str[strlen(str)-1] = '\0';
281 return str;