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 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/>.
23 #define CTDB_IMMEDIATE_MIGRATION 0x00000001
34 structure passed to a ctdb call backend function
36 struct ctdb_call_info {
37 TDB_DATA key; /* record key */
38 TDB_DATA record_data; /* current data in the record */
39 TDB_DATA *new_data; /* optionally updated record data */
40 TDB_DATA *call_data; /* optionally passed from caller */
41 TDB_DATA *reply_data; /* optionally returned by function */
42 uint32_t status; /* optional reply status - defaults to zero */
45 #define CTDB_ERR_INVALID 1
46 #define CTDB_ERR_NOMEM 2
51 #define CTDB_FLAG_TORTURE (1<<1)
54 a message handler ID meaning "give me all messages"
56 #define CTDB_SRVID_ALL (~(uint64_t)0)
61 #define CTDB_SRVID_RECOVERY 0xF100000000000000LL
64 a message handler ID meaning that the cluster has been reconfigured
66 #define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
69 a message handler ID meaning that an IP address has been released
71 #define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
74 a message ID to set the node flags in the recovery daemon
76 #define CTDB_SRVID_SET_NODE_FLAGS 0xF400000000000000LL
79 a message ID meaning that a node should be banned
81 #define CTDB_SRVID_BAN_NODE 0xF500000000000000LL
84 a message ID meaning that a node should be unbanned
86 #define CTDB_SRVID_UNBAN_NODE 0xF600000000000000LL
89 a message to tell the recovery daemon to fetch a set of records
91 #define CTDB_SRVID_VACUUM_FETCH 0xF700000000000000LL
94 a message to tell the recovery daemon to write a talloc memdump
97 #define CTDB_SRVID_MEM_DUMP 0xF800000000000000LL
100 a message ID to get the recovery daemon to push the node flags out
102 #define CTDB_SRVID_PUSH_NODE_FLAGS 0xF900000000000000LL
106 /* used on the domain socket, send a pdu to the local daemon */
107 #define CTDB_CURRENT_NODE 0xF0000001
108 /* send a broadcast to all nodes in the cluster, active or not */
109 #define CTDB_BROADCAST_ALL 0xF0000002
110 /* send a broadcast to all nodes in the current vnn map */
111 #define CTDB_BROADCAST_VNNMAP 0xF0000003
112 /* send a broadcast to all connected nodes */
113 #define CTDB_BROADCAST_CONNECTED 0xF0000004
115 /* the key used for transaction locking on persistent databases */
116 #define CTDB_TRANSACTION_LOCK_KEY "__transaction_lock__"
118 enum control_state {CTDB_CONTROL_WAIT, CTDB_CONTROL_DONE, CTDB_CONTROL_ERROR, CTDB_CONTROL_TIMEOUT};
120 struct ctdb_client_control_state {
121 struct ctdb_context *ctdb;
125 enum control_state state;
127 struct ctdb_req_control *c;
129 /* if we have a callback registered for the completion (or failure) of
131 if a callback is used, it MUST talloc_free the cb_data passed to it
134 void (*fn)(struct ctdb_client_control_state *);
140 struct event_context;
143 initialise ctdb subsystem
145 struct ctdb_context *ctdb_init(struct event_context *ev);
150 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
153 set the directory for the local databases
155 int ctdb_set_tdb_dir(struct ctdb_context *ctdb, const char *dir);
156 int ctdb_set_tdb_dir_persistent(struct ctdb_context *ctdb, const char *dir);
161 void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);
164 set max acess count before a dmaster migration
166 void ctdb_set_max_lacount(struct ctdb_context *ctdb, unsigned count);
169 tell ctdb what address to listen on, in transport specific format
171 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
173 int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname);
176 tell ctdb what nodes are available. This takes a filename, which will contain
177 1 node address per line, in a transport specific format
179 int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist);
182 Check that a specific ip address exists in the node list and returns
183 the id for the node or -1
185 int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const char *nodeip);
188 start the ctdb protocol
190 int ctdb_start(struct ctdb_context *ctdb);
191 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork);
194 attach to a ctdb database
196 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent, uint32_t tdb_flags);
199 find an attached ctdb_db handle given a name
201 struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb, const char *name);
204 error string for last ctdb error
206 const char *ctdb_errstr(struct ctdb_context *);
208 /* a ctdb call function */
209 typedef int (*ctdb_fn_t)(struct ctdb_call_info *);
212 setup a ctdb call function
214 int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id);
219 make a ctdb call. The associated ctdb call function will be called on the DMASTER
222 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
225 initiate an ordered ctdb cluster shutdown
226 this function will never return
228 void ctdb_shutdown(struct ctdb_context *ctdb);
230 /* return pnn of this node */
231 uint32_t ctdb_get_pnn(struct ctdb_context *ctdb);
234 return the number of nodes
236 uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
238 /* setup a handler for ctdb messages */
239 typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint64_t srvid,
240 TDB_DATA data, void *);
241 int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
242 ctdb_message_fn_t handler,
246 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
247 struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
248 int ctdb_call_recv(struct ctdb_client_call_state *state, struct ctdb_call *call);
250 /* send a ctdb message */
251 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn,
252 uint64_t srvid, TDB_DATA data);
256 Fetch a ctdb record from a remote node
257 . Underneath this will force the
258 dmaster for the record to be moved to the local node.
260 struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx,
261 TDB_DATA key, TDB_DATA *data);
263 int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data);
265 int ctdb_fetch(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx,
266 TDB_DATA key, TDB_DATA *data);
268 int ctdb_register_message_handler(struct ctdb_context *ctdb,
271 ctdb_message_fn_t handler,
274 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
277 struct ctdb_context *ctdb_cmdline_client(struct event_context *ev);
279 struct ctdb_statistics;
280 int ctdb_ctrl_statistics(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_statistics *status);
282 int ctdb_ctrl_shutdown(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
285 int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb,
286 struct timeval timeout, uint32_t destnode,
287 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map **vnnmap);
288 int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb,
289 struct timeval timeout, uint32_t destnode,
290 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *vnnmap);
292 /* table that contains a list of all dbids on a node
294 struct ctdb_dbid_map {
301 int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb,
302 struct timeval timeout, uint32_t destnode,
303 TALLOC_CTX *mem_ctx, struct ctdb_dbid_map **dbmap);
306 struct ctdb_node_map;
308 int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb,
309 struct timeval timeout, uint32_t destnode,
310 TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
312 int ctdb_ctrl_getnodemapv4(struct ctdb_context *ctdb,
313 struct timeval timeout, uint32_t destnode,
314 TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
316 int ctdb_ctrl_reload_nodes_file(struct ctdb_context *ctdb,
317 struct timeval timeout, uint32_t destnode);
319 struct ctdb_key_list {
323 struct ctdb_ltdb_header *headers;
327 int ctdb_ctrl_pulldb(
328 struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
329 uint32_t lmaster, TALLOC_CTX *mem_ctx,
330 struct timeval timeout, TDB_DATA *outdata);
332 struct ctdb_client_control_state *ctdb_ctrl_pulldb_send(
333 struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
334 uint32_t lmaster, TALLOC_CTX *mem_ctx, struct timeval timeout);
336 int ctdb_ctrl_pulldb_recv(
337 struct ctdb_context *ctdb,
338 TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state,
341 int ctdb_ctrl_pushdb(
342 struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
344 struct timeval timeout, TDB_DATA indata);
346 struct ctdb_client_control_state *ctdb_ctrl_pushdb_send(
347 struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
348 TALLOC_CTX *mem_ctx, struct timeval timeout,
351 int ctdb_ctrl_pushdb_recv(
352 struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
353 struct ctdb_client_control_state *state);
356 int ctdb_ctrl_copydb(struct ctdb_context *ctdb,
357 struct timeval timeout, uint32_t sourcenode,
358 uint32_t destnode, uint32_t dbid, uint32_t lmaster,
359 TALLOC_CTX *mem_ctx);
361 int ctdb_ctrl_getdbpath(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path);
362 int ctdb_ctrl_getdbname(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **name);
363 int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, const char *name, bool persistent);
365 int ctdb_ctrl_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
367 int ctdb_ctrl_ping(struct ctdb_context *ctdb, uint32_t destnode);
369 int ctdb_ctrl_get_config(struct ctdb_context *ctdb);
371 int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, int32_t *level);
372 int ctdb_ctrl_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, int32_t level);
375 change dmaster for all keys in the database to the new value
377 int ctdb_ctrl_setdmaster(struct ctdb_context *ctdb,
378 struct timeval timeout, uint32_t destnode,
379 TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster);
382 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)
384 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);
386 #define CTDB_RECOVERY_NORMAL 0
387 #define CTDB_RECOVERY_ACTIVE 1
390 get the recovery mode of a remote node
392 int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, uint32_t *recmode);
394 struct ctdb_client_control_state *ctdb_ctrl_getrecmode_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
396 int ctdb_ctrl_getrecmode_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *recmode);
400 set the recovery mode of a remote node
402 int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmode);
404 get the monitoring mode of a remote node
406 int ctdb_ctrl_getmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *monmode);
409 set the monitoring mode of a remote node to active
411 int ctdb_ctrl_enable_monmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
414 set the monitoring mode of a remote node to disabled
416 int ctdb_ctrl_disable_monmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
420 get the recovery master of a remote node
422 int ctdb_ctrl_getrecmaster(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, uint32_t *recmaster);
424 struct ctdb_client_control_state *ctdb_ctrl_getrecmaster_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
426 int ctdb_ctrl_getrecmaster_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *recmaster);
431 set the recovery master of a remote node
433 int ctdb_ctrl_setrecmaster(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmaster);
435 uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb,
436 struct timeval timeout,
438 uint32_t *num_nodes);
440 int ctdb_statistics_reset(struct ctdb_context *ctdb, uint32_t destnode);
442 int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_syslog);
444 typedef int (*ctdb_traverse_func)(struct ctdb_context *, TDB_DATA, TDB_DATA, void *);
445 int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void *private_data);
447 int ctdb_dump_db(struct ctdb_db_context *ctdb_db, FILE *f);
450 get the pid of a ctdb daemon
452 int ctdb_ctrl_getpid(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *pid);
454 int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout,
457 struct ctdb_client_control_state *
458 ctdb_ctrl_freeze_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
459 struct timeval timeout, uint32_t destnode);
461 int ctdb_ctrl_freeze_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
462 struct ctdb_client_control_state *state);
464 int ctdb_ctrl_thaw(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
466 int ctdb_ctrl_getpnn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
468 int ctdb_ctrl_get_tunable(struct ctdb_context *ctdb,
469 struct timeval timeout,
471 const char *name, uint32_t *value);
473 int ctdb_ctrl_set_tunable(struct ctdb_context *ctdb,
474 struct timeval timeout,
476 const char *name, uint32_t value);
478 int ctdb_ctrl_list_tunables(struct ctdb_context *ctdb,
479 struct timeval timeout,
482 const char ***list, uint32_t *count);
484 int ctdb_ctrl_modflags(struct ctdb_context *ctdb,
485 struct timeval timeout,
487 uint32_t set, uint32_t clear);
489 enum ctdb_server_id_type { SERVER_TYPE_SAMBA=1 };
491 struct ctdb_server_id {
492 enum ctdb_server_id_type type;
497 struct ctdb_server_id_list {
499 struct ctdb_server_id server_ids[1];
503 int ctdb_ctrl_register_server_id(struct ctdb_context *ctdb,
504 struct timeval timeout,
505 struct ctdb_server_id *id);
506 int ctdb_ctrl_unregister_server_id(struct ctdb_context *ctdb,
507 struct timeval timeout,
508 struct ctdb_server_id *id);
509 int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb,
510 struct timeval timeout, uint32_t destnode,
511 struct ctdb_server_id *id, uint32_t *status);
512 int ctdb_ctrl_get_server_id_list(struct ctdb_context *ctdb,
514 struct timeval timeout, uint32_t destnode,
515 struct ctdb_server_id_list **svid_list);
518 struct timeval current_time;
519 struct timeval ctdbd_start_time;
520 struct timeval last_recovery_started;
521 struct timeval last_recovery_finished;
525 definitions for different socket structures
527 typedef struct sockaddr_in ctdb_addr_in;
528 typedef struct sockaddr_in6 ctdb_addr_in6;
536 struct for tcp_client control
537 this is an ipv4 only version of this structure used by samba
538 samba will later be migrated over to use the
539 ctdb_control_tcp_addr structure instead
541 struct ctdb_control_tcp {
542 struct sockaddr_in src; // samba uses this
543 struct sockaddr_in dest;// samba uses this
545 /* new style structure */
546 struct ctdb_control_tcp_addr {
551 int ctdb_socket_connect(struct ctdb_context *ctdb);
554 get the uptime of a remote node
556 int ctdb_ctrl_uptime(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, struct ctdb_uptime **uptime);
558 struct ctdb_client_control_state *ctdb_ctrl_uptime_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
560 int ctdb_ctrl_uptime_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, struct ctdb_uptime **uptime);
562 int ctdb_ctrl_end_recovery(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
564 int ctdb_ctrl_getreclock(struct ctdb_context *ctdb,
565 struct timeval timeout, uint32_t destnode,
566 TALLOC_CTX *mem_ctx, const char **reclock);
569 uint32_t *list_of_connected_nodes(struct ctdb_context *ctdb,
570 struct ctdb_node_map *node_map,
573 uint32_t *list_of_active_nodes(struct ctdb_context *ctdb,
574 struct ctdb_node_map *node_map,
577 uint32_t *list_of_vnnmap_nodes(struct ctdb_context *ctdb,
578 struct ctdb_vnn_map *vnn_map,
582 int ctdb_read_pnn_lock(int fd, int32_t pnn);
585 get capabilities of a remote node
587 int ctdb_ctrl_getcapabilities(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *capabilities);
589 struct ctdb_client_control_state *ctdb_ctrl_getcapabilities_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
591 int ctdb_ctrl_getcapabilities_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *capabilities);
593 struct ctdb_marshall_buffer *ctdb_marshall_add(TALLOC_CTX *mem_ctx,
594 struct ctdb_marshall_buffer *m,
598 struct ctdb_ltdb_header *header,
600 TDB_DATA ctdb_marshall_finish(struct ctdb_marshall_buffer *m);
602 struct ctdb_transaction_handle *ctdb_transaction_start(struct ctdb_db_context *ctdb_db,
603 TALLOC_CTX *mem_ctx);
604 int ctdb_transaction_fetch(struct ctdb_transaction_handle *h,
606 TDB_DATA key, TDB_DATA *data);
607 int ctdb_transaction_store(struct ctdb_transaction_handle *h,
608 TDB_DATA key, TDB_DATA data);
609 int ctdb_transaction_commit(struct ctdb_transaction_handle *h);
611 int ctdb_ctrl_recd_ping(struct ctdb_context *ctdb);
613 int switch_from_server_to_client(struct ctdb_context *ctdb);
615 #define MONITOR_SCRIPT_OK 0
616 #define MONITOR_SCRIPT_TIMEOUT 1
618 #define MAX_SCRIPT_NAME 31
619 #define MAX_SCRIPT_OUTPUT 511
620 struct ctdb_monitoring_script_wire {
621 char name[MAX_SCRIPT_NAME+1];
622 struct timeval start;
623 struct timeval finished;
626 char output[MAX_SCRIPT_OUTPUT+1];
629 struct ctdb_monitoring_wire {
630 uint32_t num_scripts;
631 struct ctdb_monitoring_script_wire scripts[1];
634 int ctdb_ctrl_getscriptstatus(struct ctdb_context *ctdb,
635 struct timeval timeout, uint32_t destnode,
636 TALLOC_CTX *mem_ctx, struct ctdb_monitoring_wire **script_status);