1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-24 21:49:29 +03:00

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)
This commit is contained in:
Ronnie sahlberg
2007-04-18 14:08:45 +10:00
parent e390c925c1
commit adb4becfb7
4 changed files with 50 additions and 23 deletions

View File

@ -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) {

View File

@ -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; node<ctdb_num_nodes;node++) {
r.hdr.destnode = node;
ctdb_queue_packet(ctdb, &r->hdr);
for (node=0; node<ctdb->num_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);
}
/* 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);
}
}

View File

@ -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

View File

@ -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