createdb and getdbpath does not need to be in the public api
[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  * Use ctdb_free() to release the returned ctdb_context when finished.
37  */
38 struct ctdb_context *ctdb_connect(const char *addr);
39
40 int ctdb_get_fd(struct ctdb_context *ctdb);
41
42 int ctdb_which_events(struct ctdb_context *ctdb);
43
44 int ctdb_service(struct ctdb_context *ctdb);
45
46
47 /*
48  * Special node addresses :
49  */
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
58
59
60
61
62
63
64 typedef void ctdb_handle;
65
66
67 /*
68  * functions to attach to a database
69  * if the database does not exist it will be created.
70  *
71  * Use ctdb_free() to release the returned ctdb_db_context when finished.
72  */
73 struct ctdb_db_context;
74
75 typedef void (*ctdb_attachdb_cb)(int32_t status, struct ctdb_db_context *ctdb_db, void *private_data);
76
77 ctdb_handle *
78 ctdb_attachdb_send(struct ctdb_context *ctdb,
79                    const char *name, int persistent, uint32_t tdb_flags,
80                    ctdb_attachdb_cb callback,
81                    void *private_data);
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 **);
87
88
89
90 /*
91  * messaging functions
92  * these functions provide a messaging layer for applications to communicate
93  * with eachother across
94  */
95 typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint64_t srvid, TDB_DATA data, void *);
96
97 /*
98  * register a message handler and start listening on a service port
99  */
100 typedef void (*ctdb_set_message_handler_cb)(int32_t status, void *private_data);
101
102 ctdb_handle *
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);
106
107 int ctdb_set_message_handler_recv(struct ctdb_context *ctdb,
108                                   ctdb_handle *handle);
109
110 int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
111                              ctdb_message_fn_t handler, void *private_data);
112
113
114
115 /*
116  * unregister a message handler and stop listening on teh specified port
117  */
118 typedef void (*ctdb_remove_message_handler_cb)(int32_t status, void *private_data);
119
120 ctdb_handle *
121 ctdb_remove_message_handler_send(struct ctdb_context *ctdb, uint64_t srvid,
122                                  ctdb_remove_message_handler_cb callback,
123                                  void *private_data);
124
125 int ctdb_remove_message_handler_recv(struct ctdb_context *ctdb,
126                                   ctdb_handle *handle);
127
128 int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid);
129
130
131
132 /*
133  * send a message to a specific node/port
134  * this function is non-blocking
135  */
136 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn, uint64_t srvid, TDB_DATA data);
137
138
139
140
141 /*
142  * functions to read the pnn number of the local node
143  */
144 typedef void (*ctdb_getpnn_cb)(int32_t status, int32_t pnn, void *private_data);
145
146 ctdb_handle *
147 ctdb_getpnn_send(struct ctdb_context *ctdb,
148                  uint32_t destnode,
149                  ctdb_getpnn_cb callback,
150                  void *private_data);
151 int ctdb_getpnn_recv(struct ctdb_context *ctdb,
152                      ctdb_handle *handle,
153                      uint32_t *pnn);
154 int ctdb_getpnn(struct ctdb_context *ctdb,
155                 uint32_t destnode,
156                 uint32_t *pnn);
157
158
159
160
161 /*
162  * functions to read the recovery master of a node
163  */
164 typedef void (*ctdb_getrecmaster_cb)(int32_t status, int32_t recmaster, void *private_data);
165
166 ctdb_handle *
167 ctdb_getrecmaster_send(struct ctdb_context *ctdb,
168                         uint32_t destnode,
169                         ctdb_getrecmaster_cb callback,
170                         void *private_data);
171 int ctdb_getrecmaster_recv(struct ctdb_context *ctdb,
172                         ctdb_handle *handle,
173                         uint32_t *recmaster);
174 int ctdb_getrecmaster(struct ctdb_context *ctdb,
175                         uint32_t destnode,
176                         uint32_t *recmaster);
177
178
179
180
181 /*
182  * cancel a request/call
183  */
184 int ctdb_free(ctdb_handle *);
185
186
187
188 #endif