fc910ce5c288c4ba680907d020614bfd045d0a14
[sahlberg/ctdb.git] / include / ctdb.h
1 /* 
2    ctdb database library
3
4    Copyright (C) Ronnie sahlberg 2010
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
20 #ifndef _CTDB_H
21 #define _CTDB_H
22
23 /* Functions are not thread safe so all function calls must be wrapped
24  * inside a pthread_mutex for threaded applications.
25  *
26  * All _send() functions are guaranteed to be non-blocking and fully
27  * asynchronous.
28  *
29  * Avoid using the synchronous calls
30  */
31
32 /*
33  * Connect to ctdb using the specified domain socket.
34  * Returns a ctdb context if successful or NULL.
35  */
36 struct ctdb_context *ctdb_connect(const char *addr);
37
38 int ctdb_get_fd(struct ctdb_context *ctdb);
39
40 int ctdb_which_events(struct ctdb_context *ctdb);
41
42 int ctdb_service(struct ctdb_context *ctdb);
43
44
45 /*
46  * Special node addresses :
47  */
48 /* used on the domain socket, send a pdu to the local daemon */
49 #define CTDB_CURRENT_NODE     0xF0000001
50 /* send a broadcast to all nodes in the cluster, active or not */
51 #define CTDB_BROADCAST_ALL    0xF0000002
52 /* send a broadcast to all nodes in the current vnn map */
53 #define CTDB_BROADCAST_VNNMAP 0xF0000003
54 /* send a broadcast to all connected nodes */
55 #define CTDB_BROADCAST_CONNECTED 0xF0000004
56
57
58
59
60
61 typedef void ctdb_handle;
62
63
64 /*
65  * messaging functions
66  * these functions provide a messaging layer for applications to communicate
67  * with eachother across
68  */
69 typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint64_t srvid, TDB_DATA data, void *);
70
71 /*
72  * register a message handler and start listening on a service port
73  */
74 typedef void (*ctdb_set_message_handler_cb)(int32_t status, void *private_data);
75
76 ctdb_handle *
77 ctdb_set_message_handler_send(struct ctdb_context *ctdb, uint64_t srvid,
78                               ctdb_set_message_handler_cb callback,
79                               ctdb_message_fn_t handler, void *private_data);
80
81 int ctdb_set_message_handler_recv(struct ctdb_context *ctdb,
82                                   ctdb_handle *handle);
83
84 int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
85                              ctdb_message_fn_t handler, void *private_data);
86
87
88
89 /*
90  * unregister a message handler and stop listening on teh specified port
91  */
92 typedef void (*ctdb_remove_message_handler_cb)(int32_t status, void *private_data);
93
94 ctdb_handle *
95 ctdb_remove_message_handler_send(struct ctdb_context *ctdb, uint64_t srvid,
96                                  ctdb_remove_message_handler_cb callback,
97                                  void *private_data);
98
99 int ctdb_remove_message_handler_recv(struct ctdb_context *ctdb,
100                                   ctdb_handle *handle);
101
102 int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid);
103
104
105
106 /*
107  * send a message to a specific node/port
108  * this function is non-blocking
109  */
110 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn, uint64_t srvid, TDB_DATA data);
111
112
113
114
115 /*
116  * functions to read the pnn number of the local node
117  */
118 typedef void (*ctdb_getpnn_cb)(int32_t status, int32_t pnn, void *private_data);
119
120 ctdb_handle *
121 ctdb_getpnn_send(struct ctdb_context *ctdb,
122                  uint32_t destnode,
123                  ctdb_getpnn_cb callback,
124                  void *private_data);
125 int ctdb_getpnn_recv(struct ctdb_context *ctdb,
126                      ctdb_handle *handle,
127                      uint32_t *pnn);
128 int ctdb_getpnn(struct ctdb_context *ctdb,
129                 uint32_t destnode,
130                 uint32_t *pnn);
131
132
133
134
135 /*
136  * functions to read the recovery master of a node
137  */
138 typedef void (*ctdb_getrecmaster_cb)(int32_t status, int32_t recmaster, void *private_data);
139
140 ctdb_handle *
141 ctdb_getrecmaster_send(struct ctdb_context *ctdb,
142                         uint32_t destnode,
143                         ctdb_getrecmaster_cb callback,
144                         void *private_data);
145 int ctdb_getrecmaster_recv(struct ctdb_context *ctdb,
146                         ctdb_handle *handle,
147                         uint32_t *recmaster);
148 int ctdb_getrecmaster(struct ctdb_context *ctdb,
149                         uint32_t destnode,
150                         uint32_t *recmaster);
151
152
153
154
155 /*
156  * functions to create a database
157  * if the database already exists this function is a NOP
158  */
159 typedef void (*ctdb_createdb_cb)(int32_t status, uint32_t db_id, void *private_data);
160
161 ctdb_handle *
162 ctdb_createdb_send(struct ctdb_context *ctdb, uint32_t destnode,
163                    const char *name, int persistent,
164                    ctdb_createdb_cb callback,
165                    void *private_data);
166 int ctdb_createdb_recv(struct ctdb_context *ctdb,
167                        ctdb_handle *handle, uint32_t *db_id);
168 int ctdb_createdb(struct ctdb_context *ctdb, uint32_t destnode,
169                   const char *name, int persistent, uint32_t *db_id);
170
171
172
173 /*
174  * cancel a request/call
175  */
176 int ctdb_cancel(ctdb_handle *);
177
178
179
180 #endif