]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
started adding a cleaner daemon finish method
authorAndrew Tridgell <tridge@samba.org>
Wed, 18 Apr 2007 01:55:54 +0000 (11:55 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 18 Apr 2007 01:55:54 +0000 (11:55 +1000)
(This used to be ctdb commit 5ef0cd83d7f24616dad85cece485b770376ecd45)

ctdb/common/ctdb.c
ctdb/common/ctdb_client.c
ctdb/common/ctdb_daemon.c
ctdb/include/ctdb_private.h
ctdb/tests/ctdb_test.c
ctdb/tests/test.sh

index 60e1e6b90b4d20cd75733b8b2e6724d8dcd8e3af..a086fc4cfdf91100caf82e1ff59346bba867552b 100644 (file)
@@ -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));
index aca243eda12ec22be02f2cc718fb184476a9f790..4e5e7701cccd29627082005448d4e56a33ad4bb6 100644 (file)
@@ -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) {
index a4bb36d482e74ec741f01d754a626f82b67c3202..1e85440efd2b0635ff5e5720b86fc7d1c66d6d71 100644 (file)
@@ -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);
+       }
+}
index 6736ee4ab7ca44535e3bf0bd933ceda61fa87ce4..bf6b96e63578b535829be96d54da095a40b1ce47 100644 (file)
@@ -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;
 };
index dea9066eb2083bc0f4e94cf1c18520e187c6e1df..e051305725ff5875cebf062ddb45dae3877af069 100644 (file)
@@ -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;
index f119ad5b1bc04dde201d406ad00772a420972b0b..b1ed1d20d788b939da8d7c4c83eebf11948f1404 100755 (executable)
@@ -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