EVENTS_OBJ = lib/events/events.o lib/events/events_standard.o
-CTDB_COMMON_OBJ = common/ctdb.o common/util.o common/ctdb_util.o \
+CTDB_COMMON_OBJ = common/ctdb.o common/ctdb_daemon.o common/ctdb_io.o common/util.o common/ctdb_util.o \
common/ctdb_call.o common/ctdb_ltdb.o common/ctdb_message.o \
lib/util/idtree.o lib/util/db_wrap.o
}
-/*
- start the protocol going
-*/
-int ctdb_start(struct ctdb_context *ctdb)
-{
- return ctdb->methods->start(ctdb);
-}
-
/*
called by the transport layer when a packet comes in
*/
return ctdb;
}
+int ctdb_start(struct ctdb_context *ctdb)
+{
+ return ctdb->methods->start(ctdb);
+}
talloc_free(r);
}
-enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
-
-/*
- state of a in-progress ctdb call
-*/
-struct ctdb_call_state {
- enum call_state state;
- struct ctdb_req_call *c;
- struct ctdb_db_context *ctdb_db;
- struct ctdb_node *node;
- const char *errmsg;
- struct ctdb_call call;
- int redirect_count;
- struct ctdb_ltdb_header header;
- void *fetch_private;
-};
-
-
/*
called when a CTDB_REPLY_CALL packet comes in
TDB_DATA data;
struct ctdb_context *ctdb = ctdb_db->ctdb;
+
/*
if we are the dmaster for this key then we don't need to
send it off at all, we can bypass the network and handle it
}
-
-struct ctdb_record_handle {
- struct ctdb_db_context *ctdb_db;
- TDB_DATA key;
- TDB_DATA *data;
-};
-
/*
make a remote ctdb call - async recv.
-
-
-
struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx,
TDB_DATA key, TDB_DATA *data)
{
start the ctdb protocol
*/
int ctdb_start(struct ctdb_context *ctdb);
+/*
+ start the ctdb protocol in daemon mode, spawning a ctdb daemon
+*/
+int ctdbd_start(struct ctdb_context *ctdb);
/*
attach to a ctdb database
int ctdb_set_message_handler(struct ctdb_context *ctdb, ctdb_message_fn_t handler,
void *private);
+
+int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
+struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
+int ctdb_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
+
+int ctdbd_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
+struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
+int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
+
/* send a ctdb message */
int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
uint32_t srvid, TDB_DATA data);
int ctdb_record_store(struct ctdb_record_handle *rec, TDB_DATA data);
+struct ctdb_partial {
+ uint8_t *data;
+ uint32_t length;
+};
+/* callback is called with data==NULL for fauilures. the callback must test for this and do cleanup appropriately */
+typedef void (*partial_cb_fn_t)(uint8_t *data, int cnt, void *args);
+void ctdb_read_pdu(int fd, TALLOC_CTX *ctx, struct ctdb_partial *partial, partial_cb_fn_t func, void *args);
+
#endif
uint32_t vnn;
};
+struct ctdb_record_handle {
+ struct ctdb_db_context *ctdb_db;
+ TDB_DATA key;
+ TDB_DATA *data;
+};
+
/*
transport specific methods
*/
ctdb_message_fn_t message_handler;
void *message_private;
struct ctdb_db_context *db_list;
+ /* add all these client stuff to sub contexts */
+ int daemon_sd;
+ char *sd_name;
+ struct ctdbd_queue_packet *sd_queue;
+ struct fd_event *daemon_fde;
+ struct ctdb_partial daemon_partial;
};
struct ctdb_db_context {
struct ctdb_registered_call *calls; /* list of registered calls */
};
+
#define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
return -1; }} while (0)
uint32_t lacount;
};
+enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
+
+/*
+ state of a in-progress ctdb call
+*/
+struct ctdb_call_state {
+ enum call_state state;
+ struct ctdb_req_call *c;
+ struct ctdb_db_context *ctdb_db;
+ struct ctdb_node *node;
+ const char *errmsg;
+ struct ctdb_call call;
+ int redirect_count;
+ struct ctdb_ltdb_header header;
+ void *fetch_private;
+};
+
/*
operation IDs
struct ctdb_ltdb_header *header, TDB_DATA data);
void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
+struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
+ struct ctdb_call *call,
+ struct ctdb_ltdb_header *header,
+ TDB_DATA *data);
#endif
const char *transport = "tcp";
const char *myaddress = NULL;
int self_connect=0;
+ int daemon_mode=0;
struct poptOption popt_options[] = {
POPT_AUTOHELP
{ "listen", 0, POPT_ARG_STRING, &myaddress, 0, "address to listen on", "address" },
{ "transport", 0, POPT_ARG_STRING, &transport, 0, "protocol transport", NULL },
{ "self-connect", 0, POPT_ARG_NONE, &self_connect, 0, "enable self connect", "boolean" },
+ { "daemon", 0, POPT_ARG_NONE, &daemon_mode, 0, "spawn a ctdb daemon", "boolean" },
POPT_TABLEEND
};
int opt;
ret = ctdb_set_call(ctdb_db, fetch_func, FUNC_FETCH);
/* start the protocol running */
- ret = ctdb_start(ctdb);
+ if (daemon_mode) {
+ ret = ctdbd_start(ctdb);
+ } else {
+ ret = ctdb_start(ctdb);
+ }
/* wait until all nodes are connected (should not be needed
outide of test code) */
call.call_data.dptr = (uint8_t *)&v;
call.call_data.dsize = sizeof(v);
- ret = ctdb_call(ctdb_db, &call);
+ if (daemon_mode) {
+ ret = ctdbd_call(ctdb_db, &call);
+ } else {
+ ret = ctdb_call(ctdb_db, &call);
+ }
if (ret == -1) {
printf("ctdb_call FUNC_SORT failed - %s\n", ctdb_errstr(ctdb));
exit(1);
call.call_data.dptr = NULL;
call.call_data.dsize = 0;
- ret = ctdb_call(ctdb_db, &call);
+ if (daemon_mode) {
+ ret = ctdbd_call(ctdb_db, &call);
+ } else {
+ ret = ctdb_call(ctdb_db, &call);
+ }
if (ret == -1) {
printf("ctdb_call FUNC_FETCH failed - %s\n", ctdb_errstr(ctdb));
exit(1);
/* go into a wait loop to allow other nodes to complete */
ctdb_wait_loop(ctdb);
+ /*talloc_report_full(ctdb, stdout);*/
+
/* shut it down */
talloc_free(ctdb);
return 0;
#!/bin/sh
echo "Testing local send"
-bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001
+bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001 --daemon
echo "Testing self connect"
-bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001 --self-connect
+bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001 --daemon --self-connect