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)
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;
}
{
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);
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;
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));
/* 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;
/*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;
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 &
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"