From: Andrew Tridgell Date: Wed, 18 Apr 2007 01:55:54 +0000 (+1000) Subject: started adding a cleaner daemon finish method X-Git-Tag: tevent-0.9.20~348^2~2885 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7a02b09b01363fdf7e12f10eb46f18492823a2a9;p=thirdparty%2Fsamba.git started adding a cleaner daemon finish method (This used to be ctdb commit 5ef0cd83d7f24616dad85cece485b770376ecd45) --- diff --git a/ctdb/common/ctdb.c b/ctdb/common/ctdb.c index 60e1e6b90b4..a086fc4cfdf 100644 --- a/ctdb/common/ctdb.c +++ b/ctdb/common/ctdb.c @@ -255,6 +255,10 @@ void ctdb_recv_pkt(struct ctdb_context *ctdb, uint8_t *data, uint32_t length) ctdb_request_message(ctdb, hdr); break; + case CTDB_REQ_FINISHED: + ctdb_request_finished(ctdb, hdr); + break; + default: DEBUG(0,("%s: Packet with unknown operation %d\n", __location__, hdr->operation)); diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c index aca243eda12..4e5e7701ccc 100644 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@ -434,6 +434,11 @@ void ctdb_connect_wait(struct ctdb_context *ctdb) r.hdr.operation = CTDB_REQ_CONNECT_WAIT; DEBUG(3,("ctdb_connect_wait: sending to ctdbd\n")); + + /* if the domain socket is not yet open, open it */ + if (ctdb->daemon.sd==-1) { + ux_socket_connect(ctdb); + } res = ctdb_queue_send(ctdb->daemon.queue, (uint8_t *)&r.hdr, r.hdr.length); if (res != 0) { diff --git a/ctdb/common/ctdb_daemon.c b/ctdb/common/ctdb_daemon.c index a4bb36d482e..1e85440efd2 100644 --- a/ctdb/common/ctdb_daemon.c +++ b/ctdb/common/ctdb_daemon.c @@ -611,3 +611,15 @@ void *ctdbd_allocate_pkt(struct ctdb_context *ctdb, size_t len) return talloc_size(ctdb, size); } +/* + called when a CTDB_REQ_FINISHED packet comes in +*/ +void ctdb_request_finished(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) +{ + ctdb->num_finished++; + if (ctdb->num_finished == ctdb->num_nodes) { + /* all daemons have requested to finish - we now exit */ + DEBUG(1,("All daemons finished - exiting\n")); + _exit(0); + } +} diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 6736ee4ab7c..bf6b96e6357 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -117,6 +117,7 @@ struct ctdb_context { uint32_t vnn; /* our own vnn */ uint32_t num_nodes; uint32_t num_connected; + uint32_t num_finished; unsigned flags; struct idr_context *idr; struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */ @@ -213,6 +214,7 @@ enum ctdb_operation { CTDB_REPLY_DMASTER = 4, CTDB_REPLY_ERROR = 5, CTDB_REQ_MESSAGE = 6, + CTDB_REQ_FINISHED = 7, /* only used on the domain socket */ CTDB_REQ_REGISTER = 1000, @@ -294,6 +296,10 @@ struct ctdb_req_message { uint8_t data[1]; }; +struct ctdb_req_finished { + struct ctdb_req_header hdr; +}; + struct ctdb_req_connect_wait { struct ctdb_req_header hdr; }; diff --git a/ctdb/tests/ctdb_test.c b/ctdb/tests/ctdb_test.c index dea9066eb20..e051305725f 100644 --- a/ctdb/tests/ctdb_test.c +++ b/ctdb/tests/ctdb_test.c @@ -133,6 +133,8 @@ int main(int argc, const char *argv[]) /* start the protocol running */ ret = ctdb_start(ctdb); + ctdb_connect_wait(ctdb); + ZERO_STRUCT(call); call.key.dptr = discard_const("test"); call.key.dsize = strlen("test")+1; @@ -171,11 +173,6 @@ 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);*/ - -/* sleep for a while so that our daemon will remaining alive for the other nodes in the cluster */ -sleep(10); - /* shut it down */ talloc_free(ctdb); return 0; diff --git a/ctdb/tests/test.sh b/ctdb/tests/test.sh index f119ad5b1bc..b1ed1d20d78 100755 --- a/ctdb/tests/test.sh +++ b/ctdb/tests/test.sh @@ -4,17 +4,17 @@ killall -q ctdb_test echo "Trying 2 nodes" -bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.1:9001 & -bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.2:9001 +$VALGRIND bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.1:9001 & +$VALGRIND bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.2:9001 sleep 3 killall ctdb_test echo "Trying 4 nodes" -bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.1:9001 & -bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.2:9001 & -bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.3:9001 & -bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.4:9001 +$VALGRIND bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.1:9001 & +$VALGRIND bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.2:9001 & +$VALGRIND bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.3:9001 & +$VALGRIND bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.4:9001 sleep 3 killall ctdb_test