From: Ronnie sahlberg Date: Tue, 10 Apr 2007 02:18:58 +0000 (+1000) Subject: add a CONNECT_WAIT flag to replace the call ctdb_connect_wait() since X-Git-Tag: tevent-0.9.20~348^2~2953^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b84ade51db6b0277f290a41638d86c3889f2ab08;p=thirdparty%2Fsamba.git add a CONNECT_WAIT flag to replace the call ctdb_connect_wait() since 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) --- diff --git a/ctdb/common/ctdb.c b/ctdb/common/ctdb.c index ff0829ba4dc..0add6f1d82c 100644 --- a/ctdb/common/ctdb.c +++ b/ctdb/common/ctdb.c @@ -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; } diff --git a/ctdb/common/ctdb_daemon.c b/ctdb/common/ctdb_daemon.c index dc1e1477163..71fc8f47f3f 100644 --- a/ctdb/common/ctdb_daemon.c +++ b/ctdb/common/ctdb_daemon.c @@ -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); diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index b193a9997b1..e1966af6b7f 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -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; diff --git a/ctdb/tests/ctdb_test.c b/ctdb/tests/ctdb_test.c index eaeaa3665db..62c7d1c5529 100644 --- a/ctdb/tests/ctdb_test.c +++ b/ctdb/tests/ctdb_test.c @@ -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; diff --git a/ctdb/tests/test.sh b/ctdb/tests/test.sh index b1e8ae8184c..58070705399 100755 --- a/ctdb/tests/test.sh +++ b/ctdb/tests/test.sh @@ -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"