4 Copyright (C) Andrew Tridgell 2006
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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define CTDB_IMMEDIATE_MIGRATION 0x00000001
35 structure passed to a ctdb call backend function
37 struct ctdb_call_info {
38 TDB_DATA key; /* record key */
39 TDB_DATA record_data; /* current data in the record */
40 TDB_DATA *new_data; /* optionally updated record data */
41 TDB_DATA *call_data; /* optionally passed from caller */
42 TDB_DATA *reply_data; /* optionally returned by function */
43 uint32_t status; /* optional reply status - defaults to zero */
46 #define CTDB_ERR_INVALID 1
47 #define CTDB_ERR_NOMEM 2
52 #define CTDB_FLAG_TORTURE (1<<1)
55 a message handler ID meaning "give me all messages"
57 #define CTDB_SRVID_ALL (~(uint64_t)0)
62 #define CTDB_SRVID_RECOVERY 0xF100000000000000LL
65 a message handler ID meaning that the cluster has been reconfigured
67 #define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
70 a message handler ID meaning that an IP address has been released
72 #define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
75 a message ID meaning that a nodes flags have changed
77 #define CTDB_SRVID_NODE_FLAGS_CHANGED 0xF400000000000000LL
80 a message ID meaning that a node should be banned
82 #define CTDB_SRVID_BAN_NODE 0xF500000000000000LL
85 a message ID meaning that a node should be unbanned
87 #define CTDB_SRVID_UNBAN_NODE 0xF600000000000000LL
90 /* used on the domain socket, send a pdu to the local daemon */
91 #define CTDB_CURRENT_NODE 0xF0000001
92 /* send a broadcast to all nodes in the cluster, active or not */
93 #define CTDB_BROADCAST_ALL 0xF0000002
94 /* send a broadcast to all nodes in the current vnn map */
95 #define CTDB_BROADCAST_VNNMAP 0xF0000003
96 /* send a broadcast to all connected nodes */
97 #define CTDB_BROADCAST_CONNECTED 0xF0000004
100 struct event_context;
103 initialise ctdb subsystem
105 struct ctdb_context *ctdb_init(struct event_context *ev);
110 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
113 set the directory for the local databases
115 int ctdb_set_tdb_dir(struct ctdb_context *ctdb, const char *dir);
120 void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);
123 set max acess count before a dmaster migration
125 void ctdb_set_max_lacount(struct ctdb_context *ctdb, unsigned count);
128 tell ctdb what address to listen on, in transport specific format
130 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
132 int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname);
135 tell ctdb what nodes are available. This takes a filename, which will contain
136 1 node address per line, in a transport specific format
138 int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist);
141 start the ctdb protocol
143 int ctdb_start(struct ctdb_context *ctdb);
144 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork);
147 attach to a ctdb database
149 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name);
152 find an attached ctdb_db handle given a name
154 struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb, const char *name);
157 error string for last ctdb error
159 const char *ctdb_errstr(struct ctdb_context *);
161 /* a ctdb call function */
162 typedef int (*ctdb_fn_t)(struct ctdb_call_info *);
165 setup a ctdb call function
167 int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id);
172 make a ctdb call. The associated ctdb call function will be called on the DMASTER
175 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
178 initiate an ordered ctdb cluster shutdown
179 this function will never return
181 void ctdb_shutdown(struct ctdb_context *ctdb);
183 /* return vnn of this node */
184 uint32_t ctdb_get_vnn(struct ctdb_context *ctdb);
187 return the number of nodes
189 uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
191 /* setup a handler for ctdb messages */
192 typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint64_t srvid,
193 TDB_DATA data, void *);
194 int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
195 ctdb_message_fn_t handler,
199 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
200 struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
201 int ctdb_call_recv(struct ctdb_client_call_state *state, struct ctdb_call *call);
203 /* send a ctdb message */
204 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
205 uint64_t srvid, TDB_DATA data);
209 Fetch a ctdb record from a remote node
210 . Underneath this will force the
211 dmaster for the record to be moved to the local node.
213 struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx,
214 TDB_DATA key, TDB_DATA *data);
216 int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data);
218 int ctdb_register_message_handler(struct ctdb_context *ctdb,
221 ctdb_message_fn_t handler,
224 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
227 struct ctdb_context *ctdb_cmdline_client(struct event_context *ev);
229 struct ctdb_statistics;
230 int ctdb_ctrl_statistics(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_statistics *status);
232 int ctdb_ctrl_shutdown(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
235 int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb,
236 struct timeval timeout, uint32_t destnode,
237 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map **vnnmap);
238 int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb,
239 struct timeval timeout, uint32_t destnode,
240 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *vnnmap);
242 /* table that contains a list of all dbids on a node
244 struct ctdb_dbid_map {
248 int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb,
249 struct timeval timeout, uint32_t destnode,
250 TALLOC_CTX *mem_ctx, struct ctdb_dbid_map **dbmap);
253 struct ctdb_node_map;
255 int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb,
256 struct timeval timeout, uint32_t destnode,
257 TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
259 struct ctdb_key_list {
263 struct ctdb_ltdb_header *headers;
266 int ctdb_ctrl_pulldb(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, uint32_t lmaster, TALLOC_CTX *mem_ctx, struct ctdb_key_list *keys);
267 int ctdb_ctrl_copydb(struct ctdb_context *ctdb,
268 struct timeval timeout, uint32_t sourcenode,
269 uint32_t destnode, uint32_t dbid, uint32_t lmaster,
270 TALLOC_CTX *mem_ctx);
272 int ctdb_ctrl_getdbpath(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path);
273 int ctdb_ctrl_getdbname(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **name);
274 int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, const char *name);
276 int ctdb_ctrl_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
278 int ctdb_ctrl_ping(struct ctdb_context *ctdb, uint32_t destnode);
280 int ctdb_ctrl_get_config(struct ctdb_context *ctdb);
282 int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *level);
283 int ctdb_ctrl_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t level);
286 change dmaster for all keys in the database to the new value
288 int ctdb_ctrl_setdmaster(struct ctdb_context *ctdb,
289 struct timeval timeout, uint32_t destnode,
290 TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster);
293 write a record on a specific db (this implicitely updates dmaster of the record to locally be the vnn of the node where the control is executed on)
295 int ctdb_ctrl_write_record(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, TDB_DATA key, TDB_DATA data);
297 #define CTDB_RECOVERY_NORMAL 0
298 #define CTDB_RECOVERY_ACTIVE 1
301 get the recovery mode of a remote node
303 int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *recmode);
305 set the recovery mode of a remote node
307 int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmode);
309 get the monitoring mode of a remote node
311 int ctdb_ctrl_getmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *monmode);
313 set the monitoringmode of a remote node
315 int ctdb_ctrl_setmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t monmode);
318 get the recovery master of a remote node
320 int ctdb_ctrl_getrecmaster(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *recmaster);
322 set the recovery master of a remote node
324 int ctdb_ctrl_setrecmaster(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmaster);
326 uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb,
327 struct timeval timeout,
329 uint32_t *num_nodes);
331 int ctdb_statistics_reset(struct ctdb_context *ctdb, uint32_t destnode);
333 int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile);
335 typedef int (*ctdb_traverse_func)(struct ctdb_context *, TDB_DATA, TDB_DATA, void *);
336 int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void *private_data);
338 int ctdb_dump_db(struct ctdb_db_context *ctdb_db, FILE *f);
341 get the pid of a ctdb daemon
343 int ctdb_ctrl_getpid(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *pid);
345 int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
346 int ctdb_ctrl_thaw(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
348 int ctdb_ctrl_getvnn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
350 int ctdb_ctrl_get_tunable(struct ctdb_context *ctdb,
351 struct timeval timeout,
353 const char *name, uint32_t *value);
355 int ctdb_ctrl_set_tunable(struct ctdb_context *ctdb,
356 struct timeval timeout,
358 const char *name, uint32_t value);
360 int ctdb_ctrl_list_tunables(struct ctdb_context *ctdb,
361 struct timeval timeout,
364 const char ***list, uint32_t *count);
366 int ctdb_ctrl_modflags(struct ctdb_context *ctdb,
367 struct timeval timeout,
369 uint32_t set, uint32_t clear);