From: Ronnie sahlberg Date: Wed, 18 Apr 2007 04:08:45 +0000 (+1000) Subject: add/finish the ctdb_shutdown() function. X-Git-Tag: tevent-0.9.20~348^2~2883^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=adb4becfb7f5af51828d4f09d676c42da02d6635;p=thirdparty%2Fsamba.git add/finish the ctdb_shutdown() function. this function can be used in test applications to perform an orderly shutdown of the ctdb cluster once the test has completed. the ctdb nodes will remain operational until all of them have received a shutdown from their client(s) after which the ctdb daemons will all terminate. this eliminates the need to using sleep() in some of the test applications (This used to be ctdb commit f35db69dc190b11659aad85495bb66308fdb5599) --- diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c index 29afbae82f2..fb2018510d1 100644 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@ -100,7 +100,6 @@ void ctdb_reply_fetch_lock(struct ctdb_context *ctdb, struct ctdb_req_header *hd */ void ctdb_reply_shutdown(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) { - printf("daemon:%d has completed shutdown. client will now terminate\n",ctdb_get_vnn(ctdb)); talloc_free(ctdb); exit(10); @@ -689,7 +688,7 @@ void ctdb_shutdown(struct ctdb_context *ctdb) r.hdr.operation = CTDB_REQ_SHUTDOWN; r.hdr.reqid = 0; - ctdb_client_queue_pkt(ctdb, &(req.hdr)); + ctdb_client_queue_pkt(ctdb, &(r.hdr)); /* this event loop will terminate once we receive the reply */ while (1) { diff --git a/ctdb/common/ctdb_daemon.c b/ctdb/common/ctdb_daemon.c index 9825786d16a..cb05c4176b4 100644 --- a/ctdb/common/ctdb_daemon.c +++ b/ctdb/common/ctdb_daemon.c @@ -197,27 +197,62 @@ static void daemon_fetch_lock_complete(struct ctdb_call_state *state) static void daemon_request_shutdown(struct ctdb_client *client, struct ctdb_req_shutdown *f) { - struct ctdb_req_finished r; + struct ctdb_reply_shutdown rs; + struct ctdb_context *ctdb = talloc_get_type(client->ctdb, struct ctdb_context); int len; uint32_t node; - len = sizeof(struct ctdb_req_finished); - ZERO_STRUCT(r); - r.hdr.length = len; - r.hdr.ctdb_magic = CTDB_MAGIC; - r.hdr.ctdb_version = CTDB_VERSION; - r.hdr.operation = CTDB_REQ_FINISHED; - r.hdr.srcnode = ctdb->vnn; - r.hdr.reqid = 0; + /* we dont send to ourself so we can already count one daemon as + exiting */ + ctdb->num_finished++; + /* loop over all nodes of the cluster */ - for (node=0; nodehdr); + for (node=0; nodenum_nodes;node++) { + struct ctdb_req_finished *rf; + + /* dont send a message to ourself */ + if (ctdb->vnn == node) { + continue; + } + + len = sizeof(struct ctdb_req_finished); + rf = ctdb->methods->allocate_pkt(ctdb, len); + CTDB_NO_MEMORY_FATAL(ctdb, rf); + talloc_set_name_const(rf, "ctdb_req_finished packet"); + + ZERO_STRUCT(*rf); + rf->hdr.length = len; + rf->hdr.ctdb_magic = CTDB_MAGIC; + rf->hdr.ctdb_version = CTDB_VERSION; + rf->hdr.operation = CTDB_REQ_FINISHED; + rf->hdr.destnode = node; + rf->hdr.srcnode = ctdb->vnn; + rf->hdr.reqid = 0; + + ctdb_queue_packet(ctdb, &(rf->hdr)); + + talloc_free(rf); } - /* send a shutdown reply back to the client */ + /* wait until all nodes have are prepared to shutdown */ + while (ctdb->num_finished != ctdb->num_nodes) { + event_loop_once(ctdb->ev); + } + /* send a shutdown reply back to the client */ + len = sizeof(struct ctdb_reply_shutdown); + ZERO_STRUCT(rs); + rs.hdr.length = len; + rs.hdr.ctdb_magic = CTDB_MAGIC; + rs.hdr.ctdb_version = CTDB_VERSION; + rs.hdr.operation = CTDB_REPLY_SHUTDOWN; + ctdb_queue_send(client->queue, (uint8_t *)&(rs.hdr), rs.hdr.length); + /* XXX we should wait here until the packet has been sent to the client */ + + /* all daemons have requested to finish - we now exit */ + DEBUG(1,("All daemons finished - exiting\n")); + _exit(0); } /* @@ -649,9 +684,4 @@ void *ctdbd_allocate_pkt(struct ctdb_context *ctdb, size_t len) 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/tests/test.sh b/ctdb/tests/test.sh index b1ed1d20d78..d913d751a68 100755 --- a/ctdb/tests/test.sh +++ b/ctdb/tests/test.sh @@ -6,9 +6,7 @@ killall -q ctdb_test echo "Trying 2 nodes" $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" $VALGRIND bin/ctdb_test --nlist tests/4nodes.txt --listen 127.0.0.1:9001 & @@ -16,5 +14,3 @@ $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 diff --git a/ctdb/tests/test1.sh b/ctdb/tests/test1.sh index f13799b45c7..0581458c4ed 100755 --- a/ctdb/tests/test1.sh +++ b/ctdb/tests/test1.sh @@ -2,5 +2,7 @@ echo "Testing daemon mode" bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001 +sleep 3 + echo "Testing self connect" bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001 --self-connect