1 | /*
|
---|
2 | ctdb tunables code
|
---|
3 |
|
---|
4 | Copyright (C) Andrew Tridgell 2007
|
---|
5 |
|
---|
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.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
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/>.
|
---|
18 | */
|
---|
19 | #include "replace.h"
|
---|
20 | #include "system/network.h"
|
---|
21 |
|
---|
22 | #include <talloc.h>
|
---|
23 | #include <tdb.h>
|
---|
24 |
|
---|
25 | #include "lib/util/debug.h"
|
---|
26 |
|
---|
27 | #include "ctdb_private.h"
|
---|
28 |
|
---|
29 | #include "common/common.h"
|
---|
30 | #include "common/logging.h"
|
---|
31 |
|
---|
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), false },
|
---|
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", 30, 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), false },
|
---|
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) },
|
---|
83 | { "FetchCollapse", 1, offsetof(struct ctdb_tunable_list, fetch_collapse) },
|
---|
84 | { "HopcountMakeSticky", 50, offsetof(struct ctdb_tunable_list, hopcount_make_sticky) },
|
---|
85 | { "StickyDuration", 600, offsetof(struct ctdb_tunable_list, sticky_duration) },
|
---|
86 | { "StickyPindown", 200, offsetof(struct ctdb_tunable_list, sticky_pindown) },
|
---|
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 },
|
---|
97 | };
|
---|
98 |
|
---|
99 | /*
|
---|
100 | set all tunables to defaults
|
---|
101 | */
|
---|
102 | void ctdb_tunables_set_defaults(struct ctdb_context *ctdb)
|
---|
103 | {
|
---|
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;
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | /*
|
---|
112 | get a tunable
|
---|
113 | */
|
---|
114 | int32_t ctdb_control_get_tunable(struct ctdb_context *ctdb, TDB_DATA indata,
|
---|
115 | TDB_DATA *outdata)
|
---|
116 | {
|
---|
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;
|
---|
122 |
|
---|
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;
|
---|
127 | }
|
---|
128 |
|
---|
129 | name = talloc_strndup(ctdb, (char*)t->name, t->length);
|
---|
130 | CTDB_NO_MEMORY(ctdb, name);
|
---|
131 |
|
---|
132 | for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
|
---|
133 | if (strcasecmp(name, tunable_map[i].name) == 0) break;
|
---|
134 | }
|
---|
135 | talloc_free(name);
|
---|
136 |
|
---|
137 | if (i == ARRAY_SIZE(tunable_map)) {
|
---|
138 | return -EINVAL;
|
---|
139 | }
|
---|
140 |
|
---|
141 | val = *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable);
|
---|
142 |
|
---|
143 | outdata->dptr = (uint8_t *)talloc(outdata, uint32_t);
|
---|
144 | CTDB_NO_MEMORY(ctdb, outdata->dptr);
|
---|
145 |
|
---|
146 | *(uint32_t *)outdata->dptr = val;
|
---|
147 | outdata->dsize = sizeof(uint32_t);
|
---|
148 |
|
---|
149 | return 0;
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | /*
|
---|
154 | set a tunable
|
---|
155 | */
|
---|
156 | int32_t ctdb_control_set_tunable(struct ctdb_context *ctdb, TDB_DATA indata)
|
---|
157 | {
|
---|
158 | struct ctdb_tunable_old *t =
|
---|
159 | (struct ctdb_tunable_old *)indata.dptr;
|
---|
160 | char *name;
|
---|
161 | int i;
|
---|
162 |
|
---|
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;
|
---|
167 | }
|
---|
168 |
|
---|
169 | name = talloc_strndup(ctdb, (char *)t->name, t->length);
|
---|
170 | CTDB_NO_MEMORY(ctdb, name);
|
---|
171 |
|
---|
172 | for (i=0;i<ARRAY_SIZE(tunable_map);i++) {
|
---|
173 | if (strcasecmp(name, tunable_map[i].name) == 0) break;
|
---|
174 | }
|
---|
175 |
|
---|
176 | talloc_free(name);
|
---|
177 |
|
---|
178 | if (i == ARRAY_SIZE(tunable_map)) {
|
---|
179 | return -1;
|
---|
180 | }
|
---|
181 |
|
---|
182 | *(uint32_t *)(tunable_map[i].offset + (uint8_t*)&ctdb->tunable) = t->value;
|
---|
183 |
|
---|
184 | if (tunable_map[i].obsolete) {
|
---|
185 | DEBUG(DEBUG_WARNING,
|
---|
186 | ("Setting obsolete tunable \"%s\"\n",
|
---|
187 | tunable_map[i].name));
|
---|
188 | return 1;
|
---|
189 | }
|
---|
190 |
|
---|
191 | return 0;
|
---|
192 | }
|
---|
193 |
|
---|
194 | /*
|
---|
195 | list tunables
|
---|
196 | */
|
---|
197 | int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata)
|
---|
198 | {
|
---|
199 | char *list = NULL;
|
---|
200 | int i;
|
---|
201 | struct ctdb_control_list_tunable *t;
|
---|
202 |
|
---|
203 | list = talloc_strdup(outdata, tunable_map[0].name);
|
---|
204 | CTDB_NO_MEMORY(ctdb, list);
|
---|
205 |
|
---|
206 | for (i=1;i<ARRAY_SIZE(tunable_map);i++) {
|
---|
207 | if (tunable_map[i].obsolete) {
|
---|
208 | continue;
|
---|
209 | }
|
---|
210 | list = talloc_asprintf_append(list, ":%s", tunable_map[i].name);
|
---|
211 | CTDB_NO_MEMORY(ctdb, list);
|
---|
212 | }
|
---|
213 |
|
---|
214 | outdata->dsize = offsetof(struct ctdb_control_list_tunable, data) +
|
---|
215 | strlen(list) + 1;
|
---|
216 | outdata->dptr = talloc_size(outdata, outdata->dsize);
|
---|
217 | CTDB_NO_MEMORY(ctdb, outdata->dptr);
|
---|
218 |
|
---|
219 | t = (struct ctdb_control_list_tunable *)outdata->dptr;
|
---|
220 | t->length = strlen(list)+1;
|
---|
221 |
|
---|
222 | memcpy(t->data, list, t->length);
|
---|
223 | talloc_free(list);
|
---|
224 |
|
---|
225 | return 0;
|
---|
226 | }
|
---|