72efc3affcb4dbe9bec2fb65530d87b3b8bae559
[vlendec/samba-autobuild/.git] / ctdb / 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_SRVID_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 /* 
75    a message ID meaning that a nodes flags have changed
76  */
77 #define CTDB_SRVID_NODE_FLAGS_CHANGED 0xF400000000000000LL
78
79 /* 
80    a message ID meaning that a node should be banned
81  */
82 #define CTDB_SRVID_BAN_NODE 0xF500000000000000LL
83
84 /* 
85    a message ID meaning that a node should be unbanned
86  */
87 #define CTDB_SRVID_UNBAN_NODE 0xF600000000000000LL
88
89
90 /* used on the domain socket, send a pdu to the local daemon */
91 #define CTDB_CURRENT_NODE     0xF0000001
92 /* send a broadcast to all nodes in the cluster, active or not */
93 #define CTDB_BROADCAST_ALL    0xF0000002
94 /* send a broadcast to all nodes in the current vnn map */
95 #define CTDB_BROADCAST_VNNMAP 0xF0000003
96 /* send a broadcast to all connected nodes */
97 #define CTDB_BROADCAST_CONNECTED 0xF0000004
98
99
100 struct event_context;
101
102 /*
103   initialise ctdb subsystem
104 */
105 struct ctdb_context *ctdb_init(struct event_context *ev);
106
107 /*
108   choose the transport
109 */
110 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
111
112 /*
113   set the directory for the local databases
114 */
115 int ctdb_set_tdb_dir(struct ctdb_context *ctdb, const char *dir);
116
117 /*
118   set some flags
119 */
120 void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);
121
122 /*
123   set max acess count before a dmaster migration
124 */
125 void ctdb_set_max_lacount(struct ctdb_context *ctdb, unsigned count);
126
127 /*
128   tell ctdb what address to listen on, in transport specific format
129 */
130 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
131
132 int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname);
133
134 /*
135   tell ctdb what nodes are available. This takes a filename, which will contain
136   1 node address per line, in a transport specific format
137 */
138 int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist);
139
140 /*
141   start the ctdb protocol
142 */
143 int ctdb_start(struct ctdb_context *ctdb);
144 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork);
145
146 /*
147   attach to a ctdb database
148 */
149 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name);
150
151 /*
152   find an attached ctdb_db handle given a name
153  */
154 struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb, const char *name);
155
156 /*
157   error string for last ctdb error
158 */
159 const char *ctdb_errstr(struct ctdb_context *);
160
161 /* a ctdb call function */
162 typedef int (*ctdb_fn_t)(struct ctdb_call_info *);
163
164 /*
165   setup a ctdb call function
166 */
167 int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id);
168
169
170
171 /*
172   make a ctdb call. The associated ctdb call function will be called on the DMASTER
173   for the given record
174 */
175 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
176
177 /*
178   initiate an ordered ctdb cluster shutdown
179   this function will never return
180 */
181 void ctdb_shutdown(struct ctdb_context *ctdb);
182
183 /* return vnn of this node */
184 uint32_t ctdb_get_vnn(struct ctdb_context *ctdb);
185
186 /*
187   return the number of nodes
188 */
189 uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
190
191 /* setup a handler for ctdb messages */
192 typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint64_t srvid, 
193                                   TDB_DATA data, void *);
194 int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid, 
195                              ctdb_message_fn_t handler,
196                              void *private_data);
197
198
199 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
200 struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
201 int ctdb_call_recv(struct ctdb_client_call_state *state, struct ctdb_call *call);
202
203 /* send a ctdb message */
204 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
205                       uint64_t srvid, TDB_DATA data);
206
207
208 /* 
209    Fetch a ctdb record from a remote node
210  . Underneath this will force the
211    dmaster for the record to be moved to the local node. 
212 */
213 struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx, 
214                                            TDB_DATA key, TDB_DATA *data);
215
216 int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data);
217
218 int ctdb_register_message_handler(struct ctdb_context *ctdb, 
219                                   TALLOC_CTX *mem_ctx,
220                                   uint64_t srvid,
221                                   ctdb_message_fn_t handler,
222                                   void *private_data);
223
224 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
225
226
227 struct ctdb_context *ctdb_cmdline_client(struct event_context *ev);
228
229 struct ctdb_statistics;
230 int ctdb_ctrl_statistics(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_statistics *status);
231
232 int ctdb_ctrl_shutdown(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
233
234 struct ctdb_vnn_map;
235 int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, 
236                 struct timeval timeout, uint32_t destnode, 
237                 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map **vnnmap);
238 int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb,
239                 struct timeval timeout, uint32_t destnode, 
240                 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *vnnmap);
241
242 /* table that contains a list of all dbids on a node
243  */
244 struct ctdb_dbid_map {
245         uint32_t num;
246         uint32_t dbids[1];
247 };
248 int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, 
249         struct timeval timeout, uint32_t destnode, 
250         TALLOC_CTX *mem_ctx, struct ctdb_dbid_map **dbmap);
251
252
253 struct ctdb_node_map;
254
255 int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb, 
256                     struct timeval timeout, uint32_t destnode, 
257                     TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
258
259 struct ctdb_key_list {
260         uint32_t dbid;
261         uint32_t num;
262         TDB_DATA *keys;
263         struct ctdb_ltdb_header *headers;
264         TDB_DATA *data;
265 };
266 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);
267 int ctdb_ctrl_copydb(struct ctdb_context *ctdb, 
268         struct timeval timeout, uint32_t sourcenode, 
269         uint32_t destnode, uint32_t dbid, uint32_t lmaster, 
270         TALLOC_CTX *mem_ctx);
271
272 int ctdb_ctrl_getdbpath(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path);
273 int ctdb_ctrl_getdbname(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **name);
274 int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, const char *name);
275
276 int ctdb_ctrl_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
277
278 int ctdb_ctrl_ping(struct ctdb_context *ctdb, uint32_t destnode);
279
280 int ctdb_ctrl_get_config(struct ctdb_context *ctdb);
281
282 int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *level);
283 int ctdb_ctrl_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t level);
284
285 /*
286   change dmaster for all keys in the database to the new value
287  */
288 int ctdb_ctrl_setdmaster(struct ctdb_context *ctdb, 
289         struct timeval timeout, uint32_t destnode, 
290         TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster);
291
292 /*
293   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)
294  */
295 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);
296
297 #define CTDB_RECOVERY_NORMAL            0
298 #define CTDB_RECOVERY_ACTIVE            1
299
300 /*
301   get the recovery mode of a remote node
302  */
303 int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *recmode);
304 /*
305   set the recovery mode of a remote node
306  */
307 int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmode);
308 /*
309   get the monitoring mode of a remote node
310  */
311 int ctdb_ctrl_getmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *monmode);
312 /*
313   set the monitoringmode of a remote node
314  */
315 int ctdb_ctrl_setmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t monmode);
316
317 /*
318   get the recovery master of a remote node
319  */
320 int ctdb_ctrl_getrecmaster(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *recmaster);
321 /*
322   set the recovery master of a remote node
323  */
324 int ctdb_ctrl_setrecmaster(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmaster);
325
326 uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb, 
327                                    struct timeval timeout, 
328                                    TALLOC_CTX *mem_ctx,
329                                    uint32_t *num_nodes);
330
331 int ctdb_statistics_reset(struct ctdb_context *ctdb, uint32_t destnode);
332
333 int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile);
334
335 typedef int (*ctdb_traverse_func)(struct ctdb_context *, TDB_DATA, TDB_DATA, void *);
336 int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void *private_data);
337
338 int ctdb_dump_db(struct ctdb_db_context *ctdb_db, FILE *f);
339
340 /*
341   get the pid of a ctdb daemon
342  */
343 int ctdb_ctrl_getpid(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *pid);
344
345 int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
346 int ctdb_ctrl_thaw(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
347
348 int ctdb_ctrl_getvnn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
349
350 int ctdb_ctrl_get_tunable(struct ctdb_context *ctdb, 
351                           struct timeval timeout, 
352                           uint32_t destnode,
353                           const char *name, uint32_t *value);
354
355 int ctdb_ctrl_set_tunable(struct ctdb_context *ctdb, 
356                           struct timeval timeout, 
357                           uint32_t destnode,
358                           const char *name, uint32_t value);
359
360 int ctdb_ctrl_list_tunables(struct ctdb_context *ctdb, 
361                             struct timeval timeout, 
362                             uint32_t destnode,
363                             TALLOC_CTX *mem_ctx,
364                             const char ***list, uint32_t *count);
365
366 int ctdb_ctrl_modflags(struct ctdb_context *ctdb, 
367                        struct timeval timeout, 
368                        uint32_t destnode, 
369                        uint32_t set, uint32_t clear);
370
371 #endif