1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

dispatcher daemon first try.

does not yet work

(This used to be ctdb commit ff428808c6546d6f2804a1ac1cf414d1bb9cdcb4)
This commit is contained in:
Ronnie sahlberg 2007-04-09 11:51:27 +10:00
parent b3ca4826f4
commit b384019536
7 changed files with 82 additions and 42 deletions

View File

@ -20,7 +20,7 @@ LIB_FLAGS=@LDFLAGS@ -Llib @LIBS@ -lpopt @INFINIBAND_LIBS@
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

View File

@ -179,14 +179,6 @@ uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb)
}
/*
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
*/
@ -338,3 +330,7 @@ struct ctdb_context *ctdb_init(struct event_context *ev)
return ctdb;
}
int ctdb_start(struct ctdb_context *ctdb)
{
return ctdb->methods->start(ctdb);
}

View File

@ -380,24 +380,6 @@ void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
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
@ -575,6 +557,7 @@ struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct c
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
@ -634,13 +617,6 @@ struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct c
}
struct ctdb_record_handle {
struct ctdb_db_context *ctdb_db;
TDB_DATA key;
TDB_DATA *data;
};
/*
make a remote ctdb call - async recv.
@ -696,9 +672,6 @@ int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call)
struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx,
TDB_DATA key, TDB_DATA *data)
{

View File

@ -89,6 +89,10 @@ int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist);
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
@ -146,6 +150,15 @@ typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint32_t srvid,
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);
@ -167,4 +180,12 @@ struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALL
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

View File

@ -54,6 +54,12 @@ struct ctdb_node {
uint32_t vnn;
};
struct ctdb_record_handle {
struct ctdb_db_context *ctdb_db;
TDB_DATA key;
TDB_DATA *data;
};
/*
transport specific methods
*/
@ -98,6 +104,12 @@ struct ctdb_context {
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 {
@ -109,6 +121,7 @@ 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)
@ -141,6 +154,23 @@ struct ctdb_ltdb_header {
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
@ -246,5 +276,9 @@ int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
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

View File

@ -81,6 +81,7 @@ int main(int argc, const char *argv[])
const char *transport = "tcp";
const char *myaddress = NULL;
int self_connect=0;
int daemon_mode=0;
struct poptOption popt_options[] = {
POPT_AUTOHELP
@ -88,6 +89,7 @@ int main(int argc, const char *argv[])
{ "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;
@ -166,7 +168,11 @@ int main(int argc, const char *argv[])
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) */
@ -184,7 +190,11 @@ int main(int argc, const char *argv[])
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);
@ -196,7 +206,11 @@ int main(int argc, const char *argv[])
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);
@ -210,6 +224,8 @@ int main(int argc, const char *argv[])
/* 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;

View File

@ -1,6 +1,6 @@
#!/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