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
105 a message ID to get the recovery daemon to reload the nodes file
107 #define CTDB_SRVID_RELOAD_NODES 0xFA00000000000000LL
111 /* used on the domain socket, send a pdu to the local daemon */
112 #define CTDB_CURRENT_NODE 0xF0000001
113 /* send a broadcast to all nodes in the cluster, active or not */
114 #define CTDB_BROADCAST_ALL 0xF0000002
115 /* send a broadcast to all nodes in the current vnn map */
116 #define CTDB_BROADCAST_VNNMAP 0xF0000003
117 /* send a broadcast to all connected nodes */
118 #define CTDB_BROADCAST_CONNECTED 0xF0000004
120 /* the key used for transaction locking on persistent databases */
121 #define CTDB_TRANSACTION_LOCK_KEY "__transaction_lock__"
123 enum control_state {CTDB_CONTROL_WAIT, CTDB_CONTROL_DONE, CTDB_CONTROL_ERROR, CTDB_CONTROL_TIMEOUT};
125 struct ctdb_client_control_state {
126 struct ctdb_context *ctdb;
130 enum control_state state;
132 struct ctdb_req_control *c;
134 /* if we have a callback registered for the completion (or failure) of
136 if a callback is used, it MUST talloc_free the cb_data passed to it
139 void (*fn)(struct ctdb_client_control_state *);
145 struct event_context;
148 initialise ctdb subsystem
150 struct ctdb_context *ctdb_init(struct event_context *ev);
155 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
158 set the directory for the local databases
160 int ctdb_set_tdb_dir(struct ctdb_context *ctdb, const char *dir);
161 int ctdb_set_tdb_dir_persistent(struct ctdb_context *ctdb, const char *dir);
166 void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);
169 set max acess count before a dmaster migration
171 void ctdb_set_max_lacount(struct ctdb_context *ctdb, unsigned count);
174 tell ctdb what address to listen on, in transport specific format
176 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
178 int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname);
181 tell ctdb what nodes are available. This takes a filename, which will contain
182 1 node address per line, in a transport specific format
184 int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist);
187 Check that a specific ip address exists in the node list and returns
188 the id for the node or -1
190 int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const char *nodeip);
193 start the ctdb protocol
195 int ctdb_start(struct ctdb_context *ctdb);
196 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork);
199 attach to a ctdb database
201 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent, uint32_t tdb_flags);
204 find an attached ctdb_db handle given a name
206 struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb, const char *name);
209 error string for last ctdb error
211 const char *ctdb_errstr(struct ctdb_context *);
213 /* a ctdb call function */
214 typedef int (*ctdb_fn_t)(struct ctdb_call_info *);
217 setup a ctdb call function
219 int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id);
224 make a ctdb call. The associated ctdb call function will be called on the DMASTER
227 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
230 initiate an ordered ctdb cluster shutdown
231 this function will never return
233 void ctdb_shutdown(struct ctdb_context *ctdb);
235 /* return pnn of this node */
236 uint32_t ctdb_get_pnn(struct ctdb_context *ctdb);
239 return the number of nodes
241 uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
243 /* setup a handler for ctdb messages */
244 typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint64_t srvid,
245 TDB_DATA data, void *);
246 int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
247 ctdb_message_fn_t handler,
251 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
252 struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
253 int ctdb_call_recv(struct ctdb_client_call_state *state, struct ctdb_call *call);
255 /* send a ctdb message */
256 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn,
257 uint64_t srvid, TDB_DATA data);
261 Fetch a ctdb record from a remote node
262 . Underneath this will force the
263 dmaster for the record to be moved to the local node.
265 struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx,
266 TDB_DATA key, TDB_DATA *data);
268 int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data);
270 int ctdb_fetch(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx,
271 TDB_DATA key, TDB_DATA *data);
273 int ctdb_register_message_handler(struct ctdb_context *ctdb,
276 ctdb_message_fn_t handler,
279 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
282 struct ctdb_context *ctdb_cmdline_client(struct event_context *ev);
284 struct ctdb_statistics;
285 int ctdb_ctrl_statistics(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_statistics *status);
287 int ctdb_ctrl_shutdown(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
290 int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb,
291 struct timeval timeout, uint32_t destnode,
292 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map **vnnmap);
293 int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb,
294 struct timeval timeout, uint32_t destnode,
295 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *vnnmap);
297 /* table that contains a list of all dbids on a node
299 struct ctdb_dbid_map {
306 int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb,
307 struct timeval timeout, uint32_t destnode,
308 TALLOC_CTX *mem_ctx, struct ctdb_dbid_map **dbmap);
311 struct ctdb_node_map;
313 int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb,
314 struct timeval timeout, uint32_t destnode,
315 TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
317 int ctdb_ctrl_getnodemapv4(struct ctdb_context *ctdb,
318 struct timeval timeout, uint32_t destnode,
319 TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
321 int ctdb_ctrl_reload_nodes_file(struct ctdb_context *ctdb,
322 struct timeval timeout, uint32_t destnode);
324 struct ctdb_key_list {
328 struct ctdb_ltdb_header *headers;
332 int ctdb_ctrl_pulldb(
333 struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
334 uint32_t lmaster, TALLOC_CTX *mem_ctx,
335 struct timeval timeout, TDB_DATA *outdata);
337 struct ctdb_client_control_state *ctdb_ctrl_pulldb_send(
338 struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
339 uint32_t lmaster, TALLOC_CTX *mem_ctx, struct timeval timeout);
341 int ctdb_ctrl_pulldb_recv(
342 struct ctdb_context *ctdb,
343 TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state,
346 int ctdb_ctrl_pushdb(
347 struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
349 struct timeval timeout, TDB_DATA indata);
351 struct ctdb_client_control_state *ctdb_ctrl_pushdb_send(
352 struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
353 TALLOC_CTX *mem_ctx, struct timeval timeout,
356 int ctdb_ctrl_pushdb_recv(
357 struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
358 struct ctdb_client_control_state *state);
361 int ctdb_ctrl_copydb(struct ctdb_context *ctdb,
362 struct timeval timeout, uint32_t sourcenode,
363 uint32_t destnode, uint32_t dbid, uint32_t lmaster,
364 TALLOC_CTX *mem_ctx);
366 int ctdb_ctrl_getdbpath(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path);
367 int ctdb_ctrl_getdbname(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **name);
368 int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, const char *name, bool persistent);
370 int ctdb_ctrl_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
372 int ctdb_ctrl_ping(struct ctdb_context *ctdb, uint32_t destnode);
374 int ctdb_ctrl_get_config(struct ctdb_context *ctdb);
376 int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, int32_t *level);
377 int ctdb_ctrl_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, int32_t level);
380 change dmaster for all keys in the database to the new value
382 int ctdb_ctrl_setdmaster(struct ctdb_context *ctdb,
383 struct timeval timeout, uint32_t destnode,
384 TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster);
387 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)
389 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);
391 #define CTDB_RECOVERY_NORMAL 0
392 #define CTDB_RECOVERY_ACTIVE 1
395 get the recovery mode of a remote node
397 int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, uint32_t *recmode);
399 struct ctdb_client_control_state *ctdb_ctrl_getrecmode_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
401 int ctdb_ctrl_getrecmode_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *recmode);
405 set the recovery mode of a remote node
407 int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmode);
409 get the monitoring mode of a remote node
411 int ctdb_ctrl_getmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *monmode);
414 set the monitoring mode of a remote node to active
416 int ctdb_ctrl_enable_monmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
419 set the monitoring mode of a remote node to disabled
421 int ctdb_ctrl_disable_monmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
425 get the recovery master of a remote node
427 int ctdb_ctrl_getrecmaster(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, uint32_t *recmaster);
429 struct ctdb_client_control_state *ctdb_ctrl_getrecmaster_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
431 int ctdb_ctrl_getrecmaster_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *recmaster);
436 set the recovery master of a remote node
438 int ctdb_ctrl_setrecmaster(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmaster);
440 uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb,
441 struct timeval timeout,
443 uint32_t *num_nodes);
445 int ctdb_statistics_reset(struct ctdb_context *ctdb, uint32_t destnode);
447 int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_syslog);
449 typedef int (*ctdb_traverse_func)(struct ctdb_context *, TDB_DATA, TDB_DATA, void *);
450 int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void *private_data);
452 int ctdb_dump_db(struct ctdb_db_context *ctdb_db, FILE *f);
455 get the pid of a ctdb daemon
457 int ctdb_ctrl_getpid(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *pid);
459 int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout,
462 struct ctdb_client_control_state *
463 ctdb_ctrl_freeze_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
464 struct timeval timeout, uint32_t destnode);
466 int ctdb_ctrl_freeze_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
467 struct ctdb_client_control_state *state);
469 int ctdb_ctrl_thaw(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
471 int ctdb_ctrl_getpnn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
473 int ctdb_ctrl_get_tunable(struct ctdb_context *ctdb,
474 struct timeval timeout,
476 const char *name, uint32_t *value);
478 int ctdb_ctrl_set_tunable(struct ctdb_context *ctdb,
479 struct timeval timeout,
481 const char *name, uint32_t value);
483 int ctdb_ctrl_list_tunables(struct ctdb_context *ctdb,
484 struct timeval timeout,
487 const char ***list, uint32_t *count);
489 int ctdb_ctrl_modflags(struct ctdb_context *ctdb,
490 struct timeval timeout,
492 uint32_t set, uint32_t clear);
494 enum ctdb_server_id_type { SERVER_TYPE_SAMBA=1 };
496 struct ctdb_server_id {
497 enum ctdb_server_id_type type;
502 struct ctdb_server_id_list {
504 struct ctdb_server_id server_ids[1];
508 int ctdb_ctrl_register_server_id(struct ctdb_context *ctdb,
509 struct timeval timeout,
510 struct ctdb_server_id *id);
511 int ctdb_ctrl_unregister_server_id(struct ctdb_context *ctdb,
512 struct timeval timeout,
513 struct ctdb_server_id *id);
514 int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb,
515 struct timeval timeout, uint32_t destnode,
516 struct ctdb_server_id *id, uint32_t *status);
517 int ctdb_ctrl_get_server_id_list(struct ctdb_context *ctdb,
519 struct timeval timeout, uint32_t destnode,
520 struct ctdb_server_id_list **svid_list);
523 struct timeval current_time;
524 struct timeval ctdbd_start_time;
525 struct timeval last_recovery_started;
526 struct timeval last_recovery_finished;
530 definitions for different socket structures
532 typedef struct sockaddr_in ctdb_addr_in;
533 typedef struct sockaddr_in6 ctdb_addr_in6;
541 struct for tcp_client control
542 this is an ipv4 only version of this structure used by samba
543 samba will later be migrated over to use the
544 ctdb_control_tcp_addr structure instead
546 struct ctdb_control_tcp {
547 struct sockaddr_in src; // samba uses this
548 struct sockaddr_in dest;// samba uses this
550 /* new style structure */
551 struct ctdb_control_tcp_addr {
556 int ctdb_socket_connect(struct ctdb_context *ctdb);
559 get the uptime of a remote node
561 int ctdb_ctrl_uptime(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, struct ctdb_uptime **uptime);
563 struct ctdb_client_control_state *ctdb_ctrl_uptime_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
565 int ctdb_ctrl_uptime_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, struct ctdb_uptime **uptime);
567 int ctdb_ctrl_end_recovery(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
569 int ctdb_ctrl_getreclock(struct ctdb_context *ctdb,
570 struct timeval timeout, uint32_t destnode,
571 TALLOC_CTX *mem_ctx, const char **reclock);
572 int ctdb_ctrl_setreclock(struct ctdb_context *ctdb,
573 struct timeval timeout, uint32_t destnode,
574 const char *reclock);
577 uint32_t *list_of_connected_nodes(struct ctdb_context *ctdb,
578 struct ctdb_node_map *node_map,
581 uint32_t *list_of_active_nodes(struct ctdb_context *ctdb,
582 struct ctdb_node_map *node_map,
585 uint32_t *list_of_vnnmap_nodes(struct ctdb_context *ctdb,
586 struct ctdb_vnn_map *vnn_map,
590 int ctdb_read_pnn_lock(int fd, int32_t pnn);
593 get capabilities of a remote node
595 int ctdb_ctrl_getcapabilities(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *capabilities);
597 struct ctdb_client_control_state *ctdb_ctrl_getcapabilities_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
599 int ctdb_ctrl_getcapabilities_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *capabilities);
601 struct ctdb_marshall_buffer *ctdb_marshall_add(TALLOC_CTX *mem_ctx,
602 struct ctdb_marshall_buffer *m,
606 struct ctdb_ltdb_header *header,
608 TDB_DATA ctdb_marshall_finish(struct ctdb_marshall_buffer *m);
610 struct ctdb_transaction_handle *ctdb_transaction_start(struct ctdb_db_context *ctdb_db,
611 TALLOC_CTX *mem_ctx);
612 int ctdb_transaction_fetch(struct ctdb_transaction_handle *h,
614 TDB_DATA key, TDB_DATA *data);
615 int ctdb_transaction_store(struct ctdb_transaction_handle *h,
616 TDB_DATA key, TDB_DATA data);
617 int ctdb_transaction_commit(struct ctdb_transaction_handle *h);
619 int ctdb_ctrl_recd_ping(struct ctdb_context *ctdb);
621 int switch_from_server_to_client(struct ctdb_context *ctdb);
623 #define MONITOR_SCRIPT_OK 0
624 #define MONITOR_SCRIPT_TIMEOUT 1
626 #define MAX_SCRIPT_NAME 31
627 #define MAX_SCRIPT_OUTPUT 511
628 struct ctdb_monitoring_script_wire {
629 char name[MAX_SCRIPT_NAME+1];
630 struct timeval start;
631 struct timeval finished;
634 char output[MAX_SCRIPT_OUTPUT+1];
637 struct ctdb_monitoring_wire {
638 uint32_t num_scripts;
639 struct ctdb_monitoring_script_wire scripts[1];
642 int ctdb_ctrl_getscriptstatus(struct ctdb_context *ctdb,
643 struct timeval timeout, uint32_t destnode,
644 TALLOC_CTX *mem_ctx, struct ctdb_monitoring_wire **script_status);
647 struct debug_levels {
649 const char *description;
651 extern struct debug_levels debug_levels[];
653 const char *get_debug_by_level(int32_t level);
654 int32_t get_debug_by_desc(const char *desc);