ctdbd_conn: Use sys_poll_intr
[Samba.git] / ctdb / server / ctdb_tunables.c
blob83b57f7ed2be9d43ad6665110a99a7626a00c60f
1 /*
2 ctdb tunables code
4 Copyright (C) Andrew Tridgell 2007
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/>.
19 #include "replace.h"
20 #include "system/network.h"
22 #include <talloc.h>
23 #include <tdb.h>
25 #include "lib/util/debug.h"
27 #include "ctdb_private.h"
29 #include "common/common.h"
30 #include "common/logging.h"
32 static const struct {
33 const char *name;
34 uint32_t default_v;
35 size_t offset;
36 bool obsolete;
37 } tunable_map[] = {
38 { "MaxRedirectCount", 3, offsetof(struct ctdb_tunable_list, max_redirect_count), true },
39 { "SeqnumInterval", 1000, offsetof(struct ctdb_tunable_list, seqnum_interval), false },
40 { "ControlTimeout", 60, offsetof(struct ctdb_tunable_list, control_timeout), false },
41 { "TraverseTimeout", 20, offsetof(struct ctdb_tunable_list, traverse_timeout), false },
42 { "KeepaliveInterval", 5, offsetof(struct ctdb_tunable_list, keepalive_interval), false },
43 { "KeepaliveLimit", 5, offsetof(struct ctdb_tunable_list, keepalive_limit), false },
44 { "RecoverTimeout", 120, offsetof(struct ctdb_tunable_list, recover_timeout), false },
45 { "RecoverInterval", 1, offsetof(struct ctdb_tunable_list, recover_interval), false },
46 { "ElectionTimeout", 3, offsetof(struct ctdb_tunable_list, election_timeout), false },
47 { "TakeoverTimeout", 9, offsetof(struct ctdb_tunable_list, takeover_timeout), false },
48 { "MonitorInterval", 15, offsetof(struct ctdb_tunable_list, monitor_interval), false },
49 { "TickleUpdateInterval",20, offsetof(struct ctdb_tunable_list, tickle_update_interval), false },
50 { "EventScriptTimeout", 30, offsetof(struct ctdb_tunable_list, script_timeout), false },
51 { "MonitorTimeoutCount", 20, offsetof(struct ctdb_tunable_list, monitor_timeout_count), false },
52 { "EventScriptUnhealthyOnTimeout", 0, offsetof(struct ctdb_tunable_list, script_unhealthy_on_timeout), true },
53 { "RecoveryGracePeriod", 120, offsetof(struct ctdb_tunable_list, recovery_grace_period), false },
54 { "RecoveryBanPeriod", 300, offsetof(struct ctdb_tunable_list, recovery_ban_period), false },
55 { "DatabaseHashSize", 100001, offsetof(struct ctdb_tunable_list, database_hash_size), false },
56 { "DatabaseMaxDead", 5, offsetof(struct ctdb_tunable_list, database_max_dead), false },
57 { "RerecoveryTimeout", 10, offsetof(struct ctdb_tunable_list, rerecovery_timeout), false },
58 { "EnableBans", 1, offsetof(struct ctdb_tunable_list, enable_bans), false },
59 { "DeterministicIPs", 0, offsetof(struct ctdb_tunable_list, deterministic_public_ips), false },
60 { "LCP2PublicIPs", 1, offsetof(struct ctdb_tunable_list, lcp2_public_ip_assignment), false },
61 { "ReclockPingPeriod", 60, offsetof(struct ctdb_tunable_list, reclock_ping_period), true },
62 { "NoIPFailback", 0, offsetof(struct ctdb_tunable_list, no_ip_failback), false },
63 { "DisableIPFailover", 0, offsetof(struct ctdb_tunable_list, disable_ip_failover), false },
64 { "VerboseMemoryNames", 0, offsetof(struct ctdb_tunable_list, verbose_memory_names), false },
65 { "RecdPingTimeout", 60, offsetof(struct ctdb_tunable_list, recd_ping_timeout), false },
66 { "RecdFailCount", 10, offsetof(struct ctdb_tunable_list, recd_ping_failcount), false },
67 { "LogLatencyMs", 0, offsetof(struct ctdb_tunable_list, log_latency_ms), false },
68 { "RecLockLatencyMs", 1000, offsetof(struct ctdb_tunable_list, reclock_latency_ms), false },
69 { "RecoveryDropAllIPs", 120, offsetof(struct ctdb_tunable_list, recovery_drop_all_ips), false },
70 { "VerifyRecoveryLock", 1, offsetof(struct ctdb_tunable_list, verify_recovery_lock), true },
71 { "VacuumInterval", 10, offsetof(struct ctdb_tunable_list, vacuum_interval), false },
72 { "VacuumMaxRunTime", 120, offsetof(struct ctdb_tunable_list, vacuum_max_run_time), false },
73 { "RepackLimit", 10000, offsetof(struct ctdb_tunable_list, repack_limit), false },
74 { "VacuumLimit", 5000, offsetof(struct ctdb_tunable_list, vacuum_limit), false },
75 { "VacuumFastPathCount", 60, offsetof(struct ctdb_tunable_list, vacuum_fast_path_count), false },
76 { "MaxQueueDropMsg", 1000000, offsetof(struct ctdb_tunable_list, max_queue_depth_drop_msg), false },
77 { "AllowUnhealthyDBRead", 0, offsetof(struct ctdb_tunable_list, allow_unhealthy_db_read), false },
78 { "StatHistoryInterval", 1, offsetof(struct ctdb_tunable_list, stat_history_interval), false },
79 { "DeferredAttachTO", 120, offsetof(struct ctdb_tunable_list, deferred_attach_timeout), false },
80 { "AllowClientDBAttach", 1, offsetof(struct ctdb_tunable_list, allow_client_db_attach), false },
81 { "RecoverPDBBySeqNum", 1, offsetof(struct ctdb_tunable_list, recover_pdb_by_seqnum), false },
82 { "DeferredRebalanceOnNodeAdd", 300, offsetof(struct ctdb_tunable_list, deferred_rebalance_on_node_add), true },
83 { "FetchCollapse", 1, offsetof(struct ctdb_tunable_list, fetch_collapse), false },
84 { "HopcountMakeSticky", 50, offsetof(struct ctdb_tunable_list, hopcount_make_sticky), false },
85 { "StickyDuration", 600, offsetof(struct ctdb_tunable_list, sticky_duration), false },
86 { "StickyPindown", 200, offsetof(struct ctdb_tunable_list, sticky_pindown), false },
87 { "NoIPTakeover", 0, offsetof(struct ctdb_tunable_list, no_ip_takeover), false },
88 { "DBRecordCountWarn", 100000, offsetof(struct ctdb_tunable_list, db_record_count_warn), false },
89 { "DBRecordSizeWarn", 10000000, offsetof(struct ctdb_tunable_list, db_record_size_warn), false },
90 { "DBSizeWarn", 100000000, offsetof(struct ctdb_tunable_list, db_size_warn), false },
91 { "PullDBPreallocation", 10*1024*1024, offsetof(struct ctdb_tunable_list, pulldb_preallocation_size), false },
92 { "NoIPHostOnAllDisabled", 0, offsetof(struct ctdb_tunable_list, no_ip_host_on_all_disabled), false },
93 { "Samba3AvoidDeadlocks", 0, offsetof(struct ctdb_tunable_list, samba3_hack), false },
94 { "TDBMutexEnabled", 0, offsetof(struct ctdb_tunable_list, mutex_enabled), false },
95 { "LockProcessesPerDB", 200, offsetof(struct ctdb_tunable_list, lock_processes_per_db), false },
96 { "RecBufferSizeLimit", 1000000, offsetof(struct ctdb_tunable_list, rec_buffer_size_limit), false },
100 set all tunables to defaults
102 void ctdb_tunables_set_defaults(struct ctdb_context *ctdb)
104 int i;
105 for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
106 *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable) = tunable_map[i].default_v;
112 get a tunable
114 int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
115 TDB_DATA *outdata)
117 struct ctdb_control_get_tunable *t =
118 (struct ctdb_control_get_tunable *)indata.dptr;
119 char *name;
120 uint32_t val;
121 int i;
123 if (indata.dsize < sizeof(*t) ||
124 t->length > indata.dsize - offsetof(struct ctdb_control_get_tunable, name)) {
125 DEBUG(DEBUG_ERR,("Bad indata in ctdb_control_get_tunable\n"));
126 return -1;
129 name = talloc_strndup(ctdb, (char*)t->name, t->length);
130 CTDB_NO_MEMORY(ctdb, name);
132 for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
133 if (strcasecmp(name, tunable_map[i].name) == 0) break;
135 talloc_free(name);
137 if (i == ARRAY_SIZE(tunable_map)) {
138 return -EINVAL;
141 val = *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable);
143 outdata->dptr = (uint8_t *)talloc(outdata, uint32_t);
144 CTDB_NO_MEMORY(ctdb, outdata->dptr);
146 *(uint32_t *)outdata->dptr = val;
147 outdata->dsize = sizeof(uint32_t);
149 return 0;
154 set a tunable
156 int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata)
158 struct ctdb_tunable_old *t =
159 (struct ctdb_tunable_old *)indata.dptr;
160 char *name;
161 int i;
163 if (indata.dsize < sizeof(*t) ||
164 t->length > indata.dsize - offsetof(struct ctdb_tunable_old, name)) {
165 DEBUG(DEBUG_ERR,("Bad indata in ctdb_control_set_tunable\n"));
166 return -1;
169 name = talloc_strndup(ctdb, (char *)t->name, t->length);
170 CTDB_NO_MEMORY(ctdb, name);
172 for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
173 if (strcasecmp(name, tunable_map[i].name) == 0) break;
176 talloc_free(name);
178 if (i == ARRAY_SIZE(tunable_map)) {
179 return -1;
182 *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable) = t->value;
184 if (tunable_map[i].obsolete) {
185 DEBUG(DEBUG_WARNING,
186 ("Setting obsolete tunable \"%s\"\n",
187 tunable_map[i].name));
188 return 1;
191 return 0;
195 list tunables
197 int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata)
199 char *list = NULL;
200 int i;
201 struct ctdb_control_list_tunable *t;
203 list = talloc_strdup(outdata, ":");
204 CTDB_NO_MEMORY(ctdb, list);
206 for (i=0; i<ARRAY_SIZE(tunable_map); i++) {
207 if (tunable_map[i].obsolete) {
208 continue;
210 list = talloc_asprintf_append(list, "%s:",
211 tunable_map[i].name);
212 CTDB_NO_MEMORY(ctdb, list);
215 /* cut the last ':' */
216 list[strlen(list)-1] = '\0';
218 outdata->dsize = offsetof(struct ctdb_control_list_tunable, data) +
219 strlen(list) + 1;
220 outdata->dptr = talloc_size(outdata, outdata->dsize);
221 CTDB_NO_MEMORY(ctdb, outdata->dptr);
223 t = (struct ctdb_control_list_tunable *)outdata->dptr;
224 t->length = strlen(list)+1;
226 memcpy(t->data, list, t->length);
227 talloc_free(list);
229 return 0;