2006-11-18 02:41:20 +03:00
/*
ctdb database library
Copyright ( C ) Andrew Tridgell 2006
This library is free software ; you can redistribute it and / or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation ; either
version 2 of the License , or ( at your option ) any later version .
This library is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public
License along with this library ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
2007-01-23 03:38:45 +03:00
# ifndef _CTDB_H
# define _CTDB_H
2006-11-18 02:41:20 +03:00
2007-04-04 15:15:56 +04:00
# define CTDB_IMMEDIATE_MIGRATION 0x00000001
2007-01-25 08:13:17 +03:00
struct ctdb_call {
int call_id ;
TDB_DATA key ;
TDB_DATA call_data ;
TDB_DATA reply_data ;
2007-01-29 14:30:06 +03:00
uint32_t status ;
2007-04-04 15:15:56 +04:00
uint32_t flags ;
2007-01-25 08:13:17 +03:00
} ;
2006-11-18 02:41:20 +03:00
/*
2007-01-25 08:13:17 +03:00
structure passed to a ctdb call backend function
2006-11-18 02:41:20 +03:00
*/
2007-01-25 07:19:16 +03:00
struct ctdb_call_info {
2006-11-18 02:41:20 +03:00
TDB_DATA key ; /* record key */
TDB_DATA record_data ; /* current data in the record */
TDB_DATA * new_data ; /* optionally updated record data */
TDB_DATA * call_data ; /* optionally passed from caller */
TDB_DATA * reply_data ; /* optionally returned by function */
2007-01-29 14:30:06 +03:00
uint32_t status ; /* optional reply status - defaults to zero */
2006-11-18 02:41:20 +03:00
} ;
# define CTDB_ERR_INVALID 1
# define CTDB_ERR_NOMEM 2
2006-12-01 07:45:24 +03:00
/*
ctdb flags
*/
# define CTDB_FLAG_SELF_CONNECT (1<<0)
2007-04-19 10:27:56 +04:00
# define CTDB_FLAG_TORTURE (1<<1)
2006-12-01 07:45:24 +03:00
2007-04-16 04:31:39 +04:00
/*
a message handler ID meaning " give me all messages "
*/
2007-04-27 18:53:52 +04:00
# define CTDB_SRVID_ALL (~(uint64_t)0)
2007-04-16 04:31:39 +04:00
2006-11-18 06:33:05 +03:00
struct event_context ;
2006-11-18 02:41:20 +03:00
/*
initialise ctdb subsystem
*/
2006-11-18 06:33:05 +03:00
struct ctdb_context * ctdb_init ( struct event_context * ev ) ;
2006-11-18 02:41:20 +03:00
2006-11-27 13:38:13 +03:00
/*
choose the transport
*/
int ctdb_set_transport ( struct ctdb_context * ctdb , const char * transport ) ;
2007-04-18 18:36:22 +04:00
/*
set the directory for the local databases
*/
2007-04-19 03:14:25 +04:00
int ctdb_set_tdb_dir ( struct ctdb_context * ctdb , const char * dir ) ;
2007-04-18 18:36:22 +04:00
2006-12-01 07:45:24 +03:00
/*
set some flags
*/
void ctdb_set_flags ( struct ctdb_context * ctdb , unsigned flags ) ;
2007-04-10 00:03:39 +04:00
/*
clear some flags
*/
void ctdb_clear_flags ( struct ctdb_context * ctdb , unsigned flags ) ;
2007-01-23 03:38:45 +03:00
/*
set max acess count before a dmaster migration
*/
void ctdb_set_max_lacount ( struct ctdb_context * ctdb , unsigned count ) ;
2006-11-18 03:21:40 +03:00
/*
tell ctdb what address to listen on , in transport specific format
*/
int ctdb_set_address ( struct ctdb_context * ctdb , const char * address ) ;
2007-04-26 16:27:49 +04:00
int ctdb_set_socketname ( struct ctdb_context * ctdb , const char * socketname ) ;
2006-11-18 02:41:20 +03:00
/*
tell ctdb what nodes are available . This takes a filename , which will contain
1 node address per line , in a transport specific format
*/
int ctdb_set_nlist ( struct ctdb_context * ctdb , const char * nlist ) ;
2006-11-18 03:21:40 +03:00
/*
start the ctdb protocol
*/
int ctdb_start ( struct ctdb_context * ctdb ) ;
2007-04-29 18:19:40 +04:00
int ctdb_start_daemon ( struct ctdb_context * ctdb ) ;
2006-11-18 02:41:20 +03:00
2007-04-03 13:41:00 +04:00
/*
attach to a ctdb database
*/
2007-04-30 17:31:40 +04:00
struct ctdb_db_context * ctdb_attach ( struct ctdb_context * ctdb , const char * name ) ;
2007-04-03 13:41:00 +04:00
2007-04-04 09:02:49 +04:00
/*
find an attached ctdb_db handle given a name
*/
struct ctdb_db_context * ctdb_db_handle ( struct ctdb_context * ctdb , const char * name ) ;
2006-11-18 02:41:20 +03:00
/*
error string for last ctdb error
*/
const char * ctdb_errstr ( struct ctdb_context * ) ;
/* a ctdb call function */
2007-01-25 07:19:16 +03:00
typedef int ( * ctdb_fn_t ) ( struct ctdb_call_info * ) ;
2006-11-18 02:41:20 +03:00
/*
setup a ctdb call function
*/
2007-04-30 17:31:40 +04:00
int ctdb_set_call ( struct ctdb_db_context * ctdb_db , ctdb_fn_t fn , uint32_t id ) ;
2006-11-18 02:41:20 +03:00
/*
make a ctdb call . The associated ctdb call function will be called on the DMASTER
for the given record
*/
2007-04-03 13:41:00 +04:00
int ctdb_call ( struct ctdb_db_context * ctdb_db , struct ctdb_call * call ) ;
2006-11-27 13:38:13 +03:00
2006-12-01 01:01:11 +03:00
/*
wait for all nodes to be connected - useful for test code
*/
void ctdb_connect_wait ( struct ctdb_context * ctdb ) ;
2006-12-01 07:45:24 +03:00
/*
2007-04-18 06:39:03 +04:00
initiate an ordered ctdb cluster shutdown
this function will never return
2006-12-01 07:45:24 +03:00
*/
2007-04-18 06:39:03 +04:00
void ctdb_shutdown ( struct ctdb_context * ctdb ) ;
2006-12-01 07:45:24 +03:00
2007-01-23 03:38:45 +03:00
/* return vnn of this node */
uint32_t ctdb_get_vnn ( struct ctdb_context * ctdb ) ;
2007-02-09 04:45:58 +03:00
/*
return the number of nodes
*/
uint32_t ctdb_get_num_nodes ( struct ctdb_context * ctdb ) ;
2007-02-09 01:42:04 +03:00
/* setup a handler for ctdb messages */
2007-04-27 18:31:45 +04:00
typedef void ( * ctdb_message_fn_t ) ( struct ctdb_context * , uint64_t srvid ,
2007-02-09 01:42:04 +03:00
TDB_DATA data , void * ) ;
2007-04-27 18:31:45 +04:00
int ctdb_set_message_handler ( struct ctdb_context * ctdb , uint64_t srvid ,
2007-04-11 07:43:15 +04:00
ctdb_message_fn_t handler ,
2007-04-11 22:12:15 +04:00
void * private_data ) ;
2007-02-09 01:42:04 +03:00
2007-04-09 05:51:27 +04:00
int ctdb_call ( struct ctdb_db_context * ctdb_db , struct ctdb_call * call ) ;
2007-04-19 05:28:01 +04:00
struct ctdb_client_call_state * ctdb_call_send ( struct ctdb_db_context * ctdb_db , struct ctdb_call * call ) ;
int ctdb_call_recv ( struct ctdb_client_call_state * state , struct ctdb_call * call ) ;
2007-04-09 05:51:27 +04:00
2007-02-09 01:42:04 +03:00
/* send a ctdb message */
int ctdb_send_message ( struct ctdb_context * ctdb , uint32_t vnn ,
2007-04-27 18:31:45 +04:00
uint64_t srvid , TDB_DATA data ) ;
2007-02-09 01:42:04 +03:00
2007-04-04 15:15:56 +04:00
/*
2007-04-17 05:34:45 +04:00
Fetch a ctdb record from a remote node
. Underneath this will force the
2007-04-04 15:15:56 +04:00
dmaster for the record to be moved to the local node .
*/
2007-04-17 08:52:51 +04:00
struct ctdb_record_handle * ctdb_fetch_lock ( struct ctdb_db_context * ctdb_db , TALLOC_CTX * mem_ctx ,
TDB_DATA key , TDB_DATA * data ) ;
int ctdb_record_store ( struct ctdb_record_handle * h , TDB_DATA data ) ;
2007-04-04 15:15:56 +04:00
2007-04-11 07:43:15 +04:00
int ctdb_register_message_handler ( struct ctdb_context * ctdb ,
TALLOC_CTX * mem_ctx ,
2007-04-27 18:31:45 +04:00
uint64_t srvid ,
2007-04-11 07:43:15 +04:00
ctdb_message_fn_t handler ,
2007-04-11 22:12:15 +04:00
void * private_data ) ;
2007-04-04 15:15:56 +04:00
2007-04-12 09:46:50 +04:00
struct ctdb_db_context * find_ctdb_db ( struct ctdb_context * ctdb , uint32_t id ) ;
2007-04-17 05:34:45 +04:00
2007-04-26 16:27:49 +04:00
struct ctdb_context * ctdb_cmdline_client ( struct event_context * ev ) ;
2007-04-20 14:07:47 +04:00
struct ctdb_status ;
2007-04-29 18:58:27 +04:00
int ctdb_ctrl_status ( struct ctdb_context * ctdb , uint32_t destnode , struct ctdb_status * status ) ;
2007-04-20 14:07:47 +04:00
2007-04-27 14:56:10 +04:00
struct ctdb_vnn_map ;
2007-05-04 03:45:53 +04:00
int ctdb_ctrl_getvnnmap ( struct ctdb_context * ctdb ,
struct timeval timeout , uint32_t destnode ,
TALLOC_CTX * mem_ctx , struct ctdb_vnn_map * * vnnmap ) ;
2007-05-02 04:20:34 +04:00
int ctdb_ctrl_setvnnmap ( struct ctdb_context * ctdb , uint32_t destnode , TALLOC_CTX * mem_ctx , struct ctdb_vnn_map * vnnmap ) ;
2007-04-28 14:40:26 +04:00
/* table that contains a list of all dbids on a node
*/
struct ctdb_dbid_map {
uint32_t num ;
2007-05-03 07:07:34 +04:00
uint32_t dbids [ 1 ] ;
2007-04-28 14:40:26 +04:00
} ;
2007-05-03 07:07:34 +04:00
int ctdb_ctrl_getdbmap ( struct ctdb_context * ctdb , uint32_t destnode , TALLOC_CTX * mem_ctx , struct ctdb_dbid_map * * dbmap ) ;
2007-04-27 14:56:10 +04:00
2007-04-28 14:40:26 +04:00
/* table that contains a list of all nodes a ctdb knows about and their
status
*/
struct ctdb_node_and_flags {
uint32_t vnn ;
uint32_t flags ;
} ;
struct ctdb_node_map {
uint32_t num ;
2007-05-03 07:30:38 +04:00
struct ctdb_node_and_flags nodes [ 1 ] ;
2007-04-28 14:40:26 +04:00
} ;
2007-05-04 03:01:01 +04:00
int ctdb_ctrl_getnodemap ( struct ctdb_context * ctdb ,
struct timeval timeout , uint32_t destnode ,
2007-05-03 07:30:38 +04:00
TALLOC_CTX * mem_ctx , struct ctdb_node_map * * nodemap ) ;
2007-04-28 14:40:26 +04:00
2007-04-28 23:47:13 +04:00
struct ctdb_key_list {
2007-04-29 18:58:27 +04:00
uint32_t dbid ;
2007-04-28 23:47:13 +04:00
uint32_t num ;
TDB_DATA * keys ;
struct ctdb_ltdb_header * headers ;
uint32_t * lmasters ;
TDB_DATA * data ;
} ;
2007-05-02 04:20:34 +04:00
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 ) ;
int ctdb_ctrl_copydb ( struct ctdb_context * ctdb , uint32_t sourcenode , uint32_t destnode , uint32_t dbid , uint32_t lmaster , TALLOC_CTX * mem_ctx ) ;
2007-04-28 23:47:13 +04:00
2007-04-29 18:58:27 +04:00
int ctdb_ctrl_getdbpath ( struct ctdb_context * ctdb , uint32_t dbid , TALLOC_CTX * mem_ctx , const char * * path ) ;
2007-04-23 18:06:48 +04:00
2007-04-29 18:58:27 +04:00
int ctdb_ctrl_process_exists ( struct ctdb_context * ctdb , uint32_t destnode , pid_t pid ) ;
2007-04-26 16:27:49 +04:00
2007-04-29 18:58:27 +04:00
int ctdb_ctrl_ping ( struct ctdb_context * ctdb , uint32_t destnode ) ;
2007-04-26 21:27:07 +04:00
2007-04-29 18:58:27 +04:00
int ctdb_ctrl_get_config ( struct ctdb_context * ctdb ) ;
2007-04-26 21:27:07 +04:00
2007-04-29 18:58:27 +04:00
int ctdb_ctrl_get_debuglevel ( struct ctdb_context * ctdb , uint32_t destnode , uint32_t * level ) ;
int ctdb_ctrl_set_debuglevel ( struct ctdb_context * ctdb , uint32_t destnode , uint32_t level ) ;
2007-04-27 17:14:36 +04:00
2007-04-29 12:34:11 +04:00
/*
change dmaster for all keys in the database to the new value
*/
2007-04-29 18:58:27 +04:00
int ctdb_ctrl_setdmaster ( struct ctdb_context * ctdb , uint32_t destnode , TALLOC_CTX * mem_ctx , uint32_t dbid , uint32_t dmaster ) ;
2007-04-29 12:34:11 +04:00
2007-04-29 12:48:46 +04:00
/*
delete all records from a tdb
*/
2007-04-29 18:58:27 +04:00
int ctdb_ctrl_cleardb ( struct ctdb_context * ctdb , uint32_t destnode , TALLOC_CTX * mem_ctx , uint32_t dbid ) ;
2007-04-29 16:14:51 +04:00
2007-05-02 15:00:02 +04:00
/*
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 )
*/
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 ) ;
2007-04-29 16:51:56 +04:00
# define CTDB_RECOVERY_NORMAL 0
# define CTDB_RECOVERY_ACTIVE 1
/*
get the recovery mode of a remote node
*/
2007-04-29 18:58:27 +04:00
int ctdb_ctrl_getrecmode ( struct ctdb_context * ctdb , uint32_t destnode , uint32_t * recmode ) ;
2007-04-29 16:51:56 +04:00
/*
set the recovery mode of a remote node
*/
2007-04-29 18:58:27 +04:00
int ctdb_ctrl_setrecmode ( struct ctdb_context * ctdb , uint32_t destnode , uint32_t recmode ) ;
2007-04-29 16:51:56 +04:00
2007-05-04 03:01:01 +04:00
uint32_t * ctdb_get_connected_nodes ( struct ctdb_context * ctdb ,
struct timeval timeout ,
TALLOC_CTX * mem_ctx ,
2007-04-28 19:42:40 +04:00
uint32_t * num_nodes ) ;
2007-04-28 21:13:36 +04:00
int ctdb_status_reset ( struct ctdb_context * ctdb , uint32_t destnode ) ;
2007-04-30 00:42:23 +04:00
int ctdb_set_logfile ( struct ctdb_context * ctdb , const char * logfile ) ;
2007-05-03 11:12:23 +04:00
int ctdb_list_keys ( struct ctdb_db_context * ctdb_db , FILE * f ) ;
2007-01-23 03:38:45 +03:00
# endif