add a CONNECT_WAIT flag to replace the call ctdb_connect_wait() since
authorRonnie sahlberg <ronniesahlberg@gmail.com>
Tue, 10 Apr 2007 02:18:58 +0000 (12:18 +1000)
committerRonnie sahlberg <ronniesahlberg@gmail.com>
Tue, 10 Apr 2007 02:18:58 +0000 (12:18 +1000)
we can no longer use this function from the application if we are in daemon mode.

add a horrible "sleep()" to ctdb_test.c   to prevent the daemon from dissapearing (parent process died) when the application exits which may happen before the other nodes in the test have finished talking to our daemon

(This used to be ctdb commit 74d35dafe06d71e755f3a58cc58d4b9b56fc821b)

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

index ff0829ba4dcdb3bdff5c74bf4cfb0498ab68ec24..0add6f1d82ccc9b96b3d743ecfb6cc8976d506d6 100644 (file)
@@ -340,9 +340,19 @@ struct ctdb_context *ctdb_init(struct event_context *ev)
 
 int ctdb_start(struct ctdb_context *ctdb)
 {
+       int res;
+
        if (ctdb->flags&CTDB_FLAG_DAEMON_MODE) {
                return ctdbd_start(ctdb);
        }
 
-       return ctdb->methods->start(ctdb);
+       res = ctdb->methods->start(ctdb);
+
+       if (ctdb->flags&CTDB_FLAG_CONNECT_WAIT) {
+               /* wait until all nodes are connected (should not be needed
+                  outide of test code) */
+               ctdb_connect_wait(ctdb);
+       }
+
+       return res;
 }
index dc1e1477163100be74ba143fed6aec176e7c4b11..71fc8f47f3fe23f251fc9c6fe047f61ebab38944 100644 (file)
@@ -35,6 +35,12 @@ static void ctdb_main_loop(struct ctdb_context *ctdb)
 {
        ctdb->methods->start(ctdb);
 
+       if (ctdb->flags&CTDB_FLAG_CONNECT_WAIT) {
+               /* wait until all nodes are connected (should not be needed
+                  outide of test code) */
+               ctdb_connect_wait(ctdb);
+       }
+
        /* go into a wait loop to allow other nodes to complete */
        event_loop_wait(ctdb->ev);
 
index b193a9997b168d554b6589c7434bfe38a3e81736..e1966af6b7f3c6175f0fc8ae6c1baddac6d636eb 100644 (file)
@@ -50,7 +50,10 @@ struct ctdb_call_info {
   ctdb flags
 */
 #define CTDB_FLAG_SELF_CONNECT (1<<0)
+/* fork off a separate ctdb daemon */
 #define CTDB_FLAG_DAEMON_MODE  (1<<1)
+/* for test code only: make ctdb_start() block until all nodes are connected */
+#define CTDB_FLAG_CONNECT_WAIT (1<<2)
 
 
 struct event_context;
index eaeaa3665dbe2b9e94aa1b53b138208a6fba9b50..62c7d1c5529e549d7efb12635a7efd5ed281b9b7 100644 (file)
@@ -140,6 +140,13 @@ int main(int argc, const char *argv[])
                ctdb_set_flags(ctdb, CTDB_FLAG_DAEMON_MODE);
        }
 
+       /* this flag is only used by test code and it makes ctdb_start() block until all
+          nodes have connected.
+          until we do better recovery and cluster rebuild it is probably good to use this flag
+          in applications.
+        */
+       ctdb_set_flags(ctdb, CTDB_FLAG_CONNECT_WAIT);
+
        ret = ctdb_set_transport(ctdb, transport);
        if (ret == -1) {
                printf("ctdb_set_transport failed - %s\n", ctdb_errstr(ctdb));
@@ -174,10 +181,6 @@ int main(int argc, const char *argv[])
        /* start the protocol running */
        ret = ctdb_start(ctdb);
 
-       /* wait until all nodes are connected (should not be needed
-          outide of test code) */
-       ctdb_connect_wait(ctdb);
-       
        ZERO_STRUCT(call);
        call.key.dptr = discard_const("test");
        call.key.dsize = strlen("test")+1;
@@ -218,6 +221,9 @@ int main(int argc, const char *argv[])
 
        /*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 b1e8ae8184c38e5bd757f27957f57c0f84069ec3..58070705399f92267e1b15725568158008fd44c2 100755 (executable)
@@ -2,6 +2,15 @@
 
 killall -q ctdb_test
 
+echo "Trying 2 nodes in daemon mode"
+bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.1:9001 --daemon &
+bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.2:9001 --daemon &
+
+sleep 30000
+killall ctdb_test
+exit
+
+
 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 &
@@ -15,13 +24,7 @@ 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 &
 sleep 3
-killall ctdb_test
-
-echo "Trying 2 nodes in daemon mode"
-bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.1:9001 --daemon &
-bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.2:9001 --daemon &
 
-sleep 30
 killall ctdb_test
 
 echo "Trying 4 nodes in daemon mode"