4 Copyright (C) Andrew Tridgell 2006
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.
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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define CTDB_IMMEDIATE_MIGRATION 0x00000001
35 structure passed to a ctdb call backend function
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 */
46 #define CTDB_ERR_INVALID 1
47 #define CTDB_ERR_NOMEM 2
52 #define CTDB_FLAG_TORTURE (1<<1)
55 a message handler ID meaning "give me all messages"
57 #define CTDB_SRVID_ALL (~(uint64_t)0)
62 #define CTDB_SRVTYPE_RECOVERY 0xF100000000000000LL
65 a message handler ID meaning that the cluster has been reconfigured
67 #define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
70 a message handler ID meaning that an IP address has been released
72 #define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
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
85 initialise ctdb subsystem
87 struct ctdb_context *ctdb_init(struct event_context *ev);
92 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
95 set the directory for the local databases
97 int ctdb_set_tdb_dir(struct ctdb_context *ctdb, const char *dir);
102 void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);
105 set max acess count before a dmaster migration
107 void ctdb_set_max_lacount(struct ctdb_context *ctdb, unsigned count);
110 tell ctdb what address to listen on, in transport specific format
112 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
114 int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname);
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
120 int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist);
123 start the ctdb protocol
125 int ctdb_start(struct ctdb_context *ctdb);
126 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork);
129 attach to a ctdb database
131 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name);
134 find an attached ctdb_db handle given a name
136 struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb, const char *name);
139 error string for last ctdb error
141 const char *ctdb_errstr(struct ctdb_context *);
143 /* a ctdb call function */
144 typedef int (*ctdb_fn_t)(struct ctdb_call_info *);
147 setup a ctdb call function
149 int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id);
154 make a ctdb call. The associated ctdb call function will be called on the DMASTER
157 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
160 initiate an ordered ctdb cluster shutdown
161 this function will never return
163 void ctdb_shutdown(struct ctdb_context *ctdb);
165 /* return vnn of this node */
166 uint32_t ctdb_get_vnn(struct ctdb_context *ctdb);
169 return the number of nodes
171 uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
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,
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);
185 /* send a ctdb message */
186 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
187 uint64_t srvid, TDB_DATA data);
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.
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);
198 int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data);
200 int ctdb_register_message_handler(struct ctdb_context *ctdb,
203 ctdb_message_fn_t handler,
206 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
209 struct ctdb_context *ctdb_cmdline_client(struct event_context *ev);
211 struct ctdb_statistics;
212 int ctdb_ctrl_statistics(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_statistics *status);
214 int ctdb_ctrl_shutdown(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
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);
224 /* table that contains a list of all dbids on a node
226 struct ctdb_dbid_map {
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);
235 struct ctdb_node_map;
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);
241 struct ctdb_key_list {
245 struct ctdb_ltdb_header *headers;
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);
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);
258 int ctdb_ctrl_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
260 int ctdb_ctrl_ping(struct ctdb_context *ctdb, uint32_t destnode);
262 int ctdb_ctrl_get_config(struct ctdb_context *ctdb);
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);
268 change dmaster for all keys in the database to the new value
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);
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)
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);
279 #define CTDB_RECOVERY_NORMAL 0
280 #define CTDB_RECOVERY_ACTIVE 1
283 get the recovery mode of a remote node
285 int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *recmode);
287 set the recovery mode of a remote node
289 int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmode);
291 get the monitoring mode of a remote node
293 int ctdb_ctrl_getmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *monmode);
295 set the monitoringmode of a remote node
297 int ctdb_ctrl_setmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t monmode);
300 get the recovery master of a remote node
302 int ctdb_ctrl_getrecmaster(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *recmaster);
304 set the recovery master of a remote node
306 int ctdb_ctrl_setrecmaster(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmaster);
308 uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb,
309 struct timeval timeout,
311 uint32_t *num_nodes);
313 int ctdb_statistics_reset(struct ctdb_context *ctdb, uint32_t destnode);
315 int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile);
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);
320 int ctdb_dump_db(struct ctdb_db_context *ctdb_db, FILE *f);
323 get the pid of a ctdb daemon
325 int ctdb_ctrl_getpid(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *pid);
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);
330 int ctdb_ctrl_getvnn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
332 int ctdb_ctrl_get_tunable(struct ctdb_context *ctdb,
333 struct timeval timeout,
335 const char *name, uint32_t *value);
337 int ctdb_ctrl_set_tunable(struct ctdb_context *ctdb,
338 struct timeval timeout,
340 const char *name, uint32_t value);
342 int ctdb_ctrl_list_tunables(struct ctdb_context *ctdb,
343 struct timeval timeout,
346 const char ***list, uint32_t *count);