4 Copyright (C) Ronnie sahlberg 2010
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 /* Functions are not thread safe so all function calls must be wrapped
24 * inside a pthread_mutex for threaded applications.
26 * All _send() functions are guaranteed to be non-blocking and fully
29 * Avoid using the synchronous calls
33 * Connect to ctdb using the specified domain socket.
34 * Returns a ctdb context if successful or NULL.
36 * Use ctdb_free() to release the returned ctdb_context when finished.
38 struct ctdb_context *ctdb_connect(const char *addr);
40 int ctdb_get_fd(struct ctdb_context *ctdb);
42 int ctdb_which_events(struct ctdb_context *ctdb);
44 int ctdb_service(struct ctdb_context *ctdb);
48 * Special node addresses :
50 /* used on the domain socket, send a pdu to the local daemon */
51 #define CTDB_CURRENT_NODE 0xF0000001
52 /* send a broadcast to all nodes in the cluster, active or not */
53 #define CTDB_BROADCAST_ALL 0xF0000002
54 /* send a broadcast to all nodes in the current vnn map */
55 #define CTDB_BROADCAST_VNNMAP 0xF0000003
56 /* send a broadcast to all connected nodes */
57 #define CTDB_BROADCAST_CONNECTED 0xF0000004
64 typedef void ctdb_handle;
68 * functions to attach to a database
69 * if the database does not exist it will be created.
71 * Use ctdb_free() to release the returned ctdb_db_context when finished.
73 struct ctdb_db_context;
75 typedef void (*ctdb_attachdb_cb)(int32_t status, struct ctdb_db_context *ctdb_db, void *private_data);
78 ctdb_attachdb_send(struct ctdb_context *ctdb,
79 const char *name, int persistent, uint32_t tdb_flags,
80 ctdb_attachdb_cb callback,
82 int ctdb_attachdb_recv(struct ctdb_context *ctdb,
83 ctdb_handle *handle, struct ctdb_db_context **);
84 int ctdb_attachdb(struct ctdb_context *ctdb,
85 const char *name, int persistent, uint32_t tdb_flags,
86 struct ctdb_db_context **);
92 * these functions provide a messaging layer for applications to communicate
93 * with eachother across
95 typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint64_t srvid, TDB_DATA data, void *);
98 * register a message handler and start listening on a service port
100 typedef void (*ctdb_set_message_handler_cb)(int32_t status, void *private_data);
103 ctdb_set_message_handler_send(struct ctdb_context *ctdb, uint64_t srvid,
104 ctdb_set_message_handler_cb callback,
105 ctdb_message_fn_t handler, void *private_data);
107 int ctdb_set_message_handler_recv(struct ctdb_context *ctdb,
108 ctdb_handle *handle);
110 int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
111 ctdb_message_fn_t handler, void *private_data);
116 * unregister a message handler and stop listening on teh specified port
118 typedef void (*ctdb_remove_message_handler_cb)(int32_t status, void *private_data);
121 ctdb_remove_message_handler_send(struct ctdb_context *ctdb, uint64_t srvid,
122 ctdb_remove_message_handler_cb callback,
125 int ctdb_remove_message_handler_recv(struct ctdb_context *ctdb,
126 ctdb_handle *handle);
128 int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid);
133 * send a message to a specific node/port
134 * this function is non-blocking
136 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn, uint64_t srvid, TDB_DATA data);
142 * functions to read the pnn number of the local node
144 typedef void (*ctdb_getpnn_cb)(int32_t status, int32_t pnn, void *private_data);
147 ctdb_getpnn_send(struct ctdb_context *ctdb,
149 ctdb_getpnn_cb callback,
151 int ctdb_getpnn_recv(struct ctdb_context *ctdb,
154 int ctdb_getpnn(struct ctdb_context *ctdb,
162 * functions to read the recovery master of a node
164 typedef void (*ctdb_getrecmaster_cb)(int32_t status, int32_t recmaster, void *private_data);
167 ctdb_getrecmaster_send(struct ctdb_context *ctdb,
169 ctdb_getrecmaster_cb callback,
171 int ctdb_getrecmaster_recv(struct ctdb_context *ctdb,
173 uint32_t *recmaster);
174 int ctdb_getrecmaster(struct ctdb_context *ctdb,
176 uint32_t *recmaster);
182 * cancel a request/call
184 int ctdb_free(ctdb_handle *);