clean out some more cruft
[sahlberg/ctdb.git] / include / ctdb.h
1 /* 
2    ctdb database library
3
4    Copyright (C) Andrew Tridgell  2006
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 2 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, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #ifndef _CTDB_H
22 #define _CTDB_H
23
24 #define CTDB_IMMEDIATE_MIGRATION        0x00000001
25 struct ctdb_call {
26         int call_id;
27         TDB_DATA key;
28         TDB_DATA call_data;
29         TDB_DATA reply_data;
30         uint32_t status;
31         uint32_t flags;
32 };
33
34 /*
35   structure passed to a ctdb call backend function
36 */
37 struct ctdb_call_info {
38         TDB_DATA key;          /* record key */
39         TDB_DATA record_data;  /* current data in the record */
40         TDB_DATA *new_data;    /* optionally updated record data */
41         TDB_DATA *call_data;   /* optionally passed from caller */
42         TDB_DATA *reply_data;  /* optionally returned by function */
43         uint32_t status;       /* optional reply status - defaults to zero */
44 };
45
46 #define CTDB_ERR_INVALID 1
47 #define CTDB_ERR_NOMEM 2
48
49 /*
50   ctdb flags
51 */
52 #define CTDB_FLAG_TORTURE      (1<<1)
53
54 /* 
55    a message handler ID meaning "give me all messages"
56  */
57 #define CTDB_SRVID_ALL (~(uint64_t)0)
58
59 /*
60   srvid type : RECOVERY
61 */
62 #define CTDB_SRVTYPE_RECOVERY   0xF100000000000000LL
63
64 /* 
65    a message handler ID meaning that the cluster has been reconfigured
66  */
67 #define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
68
69 /* 
70    a message handler ID meaning that an IP address has been released
71  */
72 #define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
73
74 /* used on the domain socket, send a pdu to the local daemon */
75 #define CTDB_CURRENT_NODE     0xF0000001
76 /* send a broadcast to all nodes in the cluster, active or not */
77 #define CTDB_BROADCAST_ALL    0xF0000002
78 /* send a broadcast to all nodes in the current vnn map */
79 #define CTDB_BROADCAST_VNNMAP 0xF0000003
80
81
82 struct event_context;
83
84 /*
85   initialise ctdb subsystem
86 */
87 struct ctdb_context *ctdb_init(struct event_context *ev);
88
89 /*
90   choose the transport
91 */
92 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
93
94 /*
95   set the directory for the local databases
96 */
97 int ctdb_set_tdb_dir(struct ctdb_context *ctdb, const char *dir);
98
99 /*
100   set some flags
101 */
102 void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);
103
104 /*
105   set max acess count before a dmaster migration
106 */
107 void ctdb_set_max_lacount(struct ctdb_context *ctdb, unsigned count);
108
109 /*
110   tell ctdb what address to listen on, in transport specific format
111 */
112 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
113
114 int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname);
115
116 /*
117   tell ctdb what nodes are available. This takes a filename, which will contain
118   1 node address per line, in a transport specific format
119 */
120 int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist);
121
122 /*
123   start the ctdb protocol
124 */
125 int ctdb_start(struct ctdb_context *ctdb);
126 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork);
127
128 /*
129   attach to a ctdb database
130 */
131 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name);
132
133 /*
134   find an attached ctdb_db handle given a name
135  */
136 struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb, const char *name);
137
138 /*
139   error string for last ctdb error
140 */
141 const char *ctdb_errstr(struct ctdb_context *);
142
143 /* a ctdb call function */
144 typedef int (*ctdb_fn_t)(struct ctdb_call_info *);
145
146 /*
147   setup a ctdb call function
148 */
149 int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id);
150
151
152
153 /*
154   make a ctdb call. The associated ctdb call function will be called on the DMASTER
155   for the given record
156 */
157 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
158
159 /*
160   initiate an ordered ctdb cluster shutdown
161   this function will never return
162 */
163 void ctdb_shutdown(struct ctdb_context *ctdb);
164
165 /* return vnn of this node */
166 uint32_t ctdb_get_vnn(struct ctdb_context *ctdb);
167
168 /*
169   return the number of nodes
170 */
171 uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
172
173 /* setup a handler for ctdb messages */
174 typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint64_t srvid, 
175                                   TDB_DATA data, void *);
176 int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid, 
177                              ctdb_message_fn_t handler,
178                              void *private_data);
179
180
181 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
182 struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
183 int ctdb_call_recv(struct ctdb_client_call_state *state, struct ctdb_call *call);
184
185 /* send a ctdb message */
186 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
187                       uint64_t srvid, TDB_DATA data);
188
189
190 /* 
191    Fetch a ctdb record from a remote node
192  . Underneath this will force the
193    dmaster for the record to be moved to the local node. 
194 */
195 struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx, 
196                                            TDB_DATA key, TDB_DATA *data);
197
198 int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data);
199
200 int ctdb_register_message_handler(struct ctdb_context *ctdb, 
201                                   TALLOC_CTX *mem_ctx,
202                                   uint64_t srvid,
203                                   ctdb_message_fn_t handler,
204                                   void *private_data);
205
206 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
207
208
209 struct ctdb_context *ctdb_cmdline_client(struct event_context *ev);
210
211 struct ctdb_statistics;
212 int ctdb_ctrl_statistics(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_statistics *status);
213
214 int ctdb_ctrl_shutdown(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
215
216 struct ctdb_vnn_map;
217 int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, 
218                 struct timeval timeout, uint32_t destnode, 
219                 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map **vnnmap);
220 int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb,
221                 struct timeval timeout, uint32_t destnode, 
222                 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *vnnmap);
223
224 /* table that contains a list of all dbids on a node
225  */
226 struct ctdb_dbid_map {
227         uint32_t num;
228         uint32_t dbids[1];
229 };
230 int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, 
231         struct timeval timeout, uint32_t destnode, 
232         TALLOC_CTX *mem_ctx, struct ctdb_dbid_map **dbmap);
233
234
235 struct ctdb_node_map;
236
237 int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb, 
238                     struct timeval timeout, uint32_t destnode, 
239                     TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
240
241 struct ctdb_key_list {
242         uint32_t dbid;
243         uint32_t num;
244         TDB_DATA *keys;
245         struct ctdb_ltdb_header *headers;
246         TDB_DATA *data;
247 };
248 int ctdb_ctrl_pulldb(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, uint32_t lmaster, TALLOC_CTX *mem_ctx, struct ctdb_key_list *keys);
249 int ctdb_ctrl_copydb(struct ctdb_context *ctdb, 
250         struct timeval timeout, uint32_t sourcenode, 
251         uint32_t destnode, uint32_t dbid, uint32_t lmaster, 
252         TALLOC_CTX *mem_ctx);
253
254 int ctdb_ctrl_getdbpath(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path);
255 int ctdb_ctrl_getdbname(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **name);
256 int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, const char *name);
257
258 int ctdb_ctrl_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
259
260 int ctdb_ctrl_ping(struct ctdb_context *ctdb, uint32_t destnode);
261
262 int ctdb_ctrl_get_config(struct ctdb_context *ctdb);
263
264 int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *level);
265 int ctdb_ctrl_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t level);
266
267 /*
268   change dmaster for all keys in the database to the new value
269  */
270 int ctdb_ctrl_setdmaster(struct ctdb_context *ctdb, 
271         struct timeval timeout, uint32_t destnode, 
272         TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster);
273
274 /*
275   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)
276  */
277 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);
278
279 #define CTDB_RECOVERY_NORMAL            0
280 #define CTDB_RECOVERY_ACTIVE            1
281
282 /*
283   get the recovery mode of a remote node
284  */
285 int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *recmode);
286 /*
287   set the recovery mode of a remote node
288  */
289 int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmode);
290 /*
291   get the monitoring mode of a remote node
292  */
293 int ctdb_ctrl_getmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *monmode);
294 /*
295   set the monitoringmode of a remote node
296  */
297 int ctdb_ctrl_setmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t monmode);
298
299 /*
300   get the recovery master of a remote node
301  */
302 int ctdb_ctrl_getrecmaster(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *recmaster);
303 /*
304   set the recovery master of a remote node
305  */
306 int ctdb_ctrl_setrecmaster(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmaster);
307
308 uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb, 
309                                    struct timeval timeout, 
310                                    TALLOC_CTX *mem_ctx,
311                                    uint32_t *num_nodes);
312
313 int ctdb_statistics_reset(struct ctdb_context *ctdb, uint32_t destnode);
314
315 int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile);
316
317 typedef int (*ctdb_traverse_func)(struct ctdb_context *, TDB_DATA, TDB_DATA, void *);
318 int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void *private_data);
319
320 int ctdb_dump_db(struct ctdb_db_context *ctdb_db, FILE *f);
321
322 /*
323   get the pid of a ctdb daemon
324  */
325 int ctdb_ctrl_getpid(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *pid);
326
327 int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
328 int ctdb_ctrl_thaw(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
329
330 int ctdb_ctrl_getvnn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
331
332 int ctdb_ctrl_get_tunable(struct ctdb_context *ctdb, 
333                           struct timeval timeout, 
334                           uint32_t destnode,
335                           const char *name, uint32_t *value);
336
337 int ctdb_ctrl_set_tunable(struct ctdb_context *ctdb, 
338                           struct timeval timeout, 
339                           uint32_t destnode,
340                           const char *name, uint32_t value);
341
342 int ctdb_ctrl_list_tunables(struct ctdb_context *ctdb, 
343                             struct timeval timeout, 
344                             uint32_t destnode,
345                             TALLOC_CTX *mem_ctx,
346                             const char ***list, uint32_t *count);
347
348
349
350 #endif