first step towards fixing "make test" with the new daemon system
authorAndrew Tridgell <tridge@samba.org>
Sat, 2 Jun 2007 03:16:11 +0000 (13:16 +1000)
committerAndrew Tridgell <tridge@samba.org>
Sat, 2 Jun 2007 03:16:11 +0000 (13:16 +1000)
(This used to be ctdb commit f95f7e4c93dea482e6cf0614b5415229a7c9f3fb)

20 files changed:
ctdb/Makefile.in
ctdb/common/ctdb.c
ctdb/common/ctdb_client.c
ctdb/common/ctdb_ltdb.c
ctdb/common/ctdb_recover.c
ctdb/tests/1node.txt [deleted file]
ctdb/tests/4nodes.txt [deleted file]
ctdb/tests/bench-ssh.sh [deleted file]
ctdb/tests/bench.sh
ctdb/tests/ctdb_bench.c
ctdb/tests/ctdb_fetch.c
ctdb/tests/ctdb_fetch1.c [deleted file]
ctdb/tests/ctdb_messaging.c [deleted file]
ctdb/tests/ctdb_test.c [deleted file]
ctdb/tests/fetch.sh
ctdb/tests/fetch1.sh [deleted file]
ctdb/tests/messaging.sh [deleted file]
ctdb/tests/run_tests.sh
ctdb/tests/test.sh [deleted file]
ctdb/tests/test1.sh [deleted file]

index 143a0c254b7ded51c1ea8b63af3be633413cad42..c50d4ea6e966404eff4fd12e3f00db907d9411b8 100644 (file)
@@ -43,7 +43,7 @@ CTDB_OBJ = $(CTDB_COMMON_OBJ) $(CTDB_TAKEOVER_OBJ) $(CTDB_TCP_OBJ) $(POPT_OBJ)
 
 OBJS = @TDB_OBJ@ @TALLOC_OBJ@ @LIBREPLACEOBJ@ @INFINIBAND_WRAPPER_OBJ@ $(EXTRA_OBJ) @EVENTS_OBJ@ $(CTDB_OBJ) $(UTIL_OBJ)
 
-TEST_BINS=bin/ctdbd_test bin/ctdb_test bin/ctdb_bench bin/ctdb_messaging bin/ctdb_fetch bin/ctdb_fetch1 bin/lockwait @INFINIBAND_BINS@
+TEST_BINS=bin/ctdbd_test bin/ctdb_test bin/ctdb_bench bin/ctdb_fetch bin/lockwait @INFINIBAND_BINS@
 BINS = bin/ctdb
 SBINS = bin/ctdbd
 
@@ -88,14 +88,6 @@ bin/ctdb_fetch: $(OBJS) tests/ctdb_fetch.o
        @echo Linking $@
        @$(CC) $(CFLAGS) -o $@ tests/ctdb_fetch.o $(OBJS) $(LIB_FLAGS)
 
-bin/ctdb_fetch1: $(OBJS) tests/ctdb_fetch1.o 
-       @echo Linking $@
-       @$(CC) $(CFLAGS) -o $@ tests/ctdb_fetch1.o $(OBJS) $(LIB_FLAGS)
-
-bin/ctdb_messaging: $(OBJS) tests/ctdb_messaging.o 
-       @echo Linking $@
-       @$(CC) $(CFLAGS) -o $@ tests/ctdb_messaging.o $(OBJS) $(LIB_FLAGS)
-
 bin/ibwrapper_test: $(OBJS) ib/ibwrapper_test.o
        @echo Linking $@
        @$(CC) $(CFLAGS) -o $@ ib/ibwrapper_test.o $(OBJS) $(LIB_FLAGS)
@@ -106,7 +98,7 @@ bin/lockwait: $(OBJS) tests/lockwait.o
 
 clean:
        rm -f *.o */*.o */*/*.o
-       rm -f $(BINS)
+       rm -f $(BINS) $(SBINS) $(TEST_BINS)
 
 distclean: clean
        rm -f *~ */*~
index 59db09609964bbc457a07c4f94f06bffddcccfbc..4464bef9c72013b52d34c8d8e68b178a0a2bcf1e 100644 (file)
@@ -228,14 +228,6 @@ uint32_t ctdb_get_vnn(struct ctdb_context *ctdb)
        return ctdb->vnn;
 }
 
-/*
-  return the number of nodes
-*/
-uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb)
-{
-       return ctdb->num_nodes;
-}
-
 /*
   return the number of connected nodes
 */
@@ -480,7 +472,7 @@ static void ctdb_defer_packet(struct ctdb_context *ctdb, struct ctdb_req_header
 static void ctdb_broadcast_packet_all(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
 {
        int i;
-       for (i=0;i<ctdb_get_num_nodes(ctdb);i++) {
+       for (i=0;i<ctdb->num_nodes;i++) {
                hdr->destnode = ctdb->nodes[i]->vnn;
                ctdb_queue_packet(ctdb, hdr);
        }
index 68bb15126f2e7d082797c2ee78874504e53a28fa..154ce86129c23265ad2f3792c05ddb8b8d72861e 100644 (file)
@@ -301,13 +301,9 @@ struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db,
        }
 
        ret = ctdb_ltdb_fetch(ctdb_db, call->key, &header, ctdb_db, &data);
-       if (ret != 0) {
-               ctdb_ltdb_unlock(ctdb_db, call->key);
-               DEBUG(0,(__location__ " Failed to fetch record\n"));
-               return NULL;
-       }
 
-       if (header.dmaster == ctdb->vnn && !(ctdb->flags & CTDB_FLAG_SELF_CONNECT)) {
+       if (ret == 0 &&
+           header.dmaster == ctdb->vnn && !(ctdb->flags & CTDB_FLAG_SELF_CONNECT)) {
                state = ctdb_client_call_local_send(ctdb_db, call, &header, &data);
                talloc_free(data.dptr);
                ctdb_ltdb_unlock(ctdb_db, call->key);
@@ -547,11 +543,6 @@ again:
        talloc_set_destructor(h, fetch_lock_destructor);
 
        ret = ctdb_ltdb_fetch(ctdb_db, key, &h->header, h, data);
-       if (ret != 0) {
-               ctdb_ltdb_unlock(ctdb_db, key);
-               talloc_free(h);
-               return NULL;
-       }
 
        /* when torturing, ensure we test the remote path */
        if ((ctdb_db->ctdb->flags & CTDB_FLAG_TORTURE) &&
@@ -562,7 +553,7 @@ again:
 
        DEBUG(4,("ctdb_fetch_lock: done local fetch\n"));
 
-       if (h->header.dmaster != ctdb_db->ctdb->vnn) {
+       if (ret != 0 || h->header.dmaster != ctdb_db->ctdb->vnn) {
                ctdb_ltdb_unlock(ctdb_db, key);
                ret = ctdb_client_force_migration(ctdb_db, key);
                if (ret != 0) {
index e98e8cfd500cbe90c74f9b5553cbb6a0db8bb028..a6f0879c6f0e8d72433ef0e5e863cf8d7461b686 100644 (file)
@@ -106,6 +106,12 @@ int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
                TDB_DATA d2;
                /* return an initial header */
                if (rec.dptr) free(rec.dptr);
+               if (ctdb->vnn_map == NULL) {
+                       /* called from the client */
+                       ZERO_STRUCTP(data);
+                       header->dmaster = (uint32_t)-1;
+                       return -1;
+               }
                ltdb_initial_header(ctdb_db, key, header);
                ZERO_STRUCT(d2);
                if (data) {
index 01f8373f175367a430726bc2dd249bd2914043a7..3f1b1506ae98d218a892a715d1fc2c06a4c4e2db 100644 (file)
@@ -150,7 +150,7 @@ ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA ind
 
        CHECK_CONTROL_DATA_SIZE(0);
 
-       num_nodes = ctdb_get_num_nodes(ctdb);
+       num_nodes = ctdb->num_nodes;
 
        outdata->dsize = offsetof(struct ctdb_node_map, nodes) + num_nodes*sizeof(struct ctdb_node_and_flags);
        outdata->dptr  = (unsigned char *)talloc_zero_size(outdata, outdata->dsize);
diff --git a/ctdb/tests/1node.txt b/ctdb/tests/1node.txt
deleted file mode 100644 (file)
index 7b9ad53..0000000
+++ /dev/null
@@ -1 +0,0 @@
-127.0.0.1
diff --git a/ctdb/tests/4nodes.txt b/ctdb/tests/4nodes.txt
deleted file mode 100644 (file)
index 99b0732..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-127.0.0.1
-127.0.0.2
-127.0.0.3
-127.0.0.4
diff --git a/ctdb/tests/bench-ssh.sh b/ctdb/tests/bench-ssh.sh
deleted file mode 100755 (executable)
index 92f81a7..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/sh
-
-if [ $# -lt 1 ]; then
-    echo "Usage: bench-ssh.sh <NODES> <OPTIONS>"
-    exit 1
-fi
-
-while :; do
-    if [ "`echo $1 | cut -c1`" = "-" -o $# -eq 0 ]; then break; fi
-    nodes="$nodes $1";
-    shift;
-done
-
-options=$*
-dir=`pwd`
-
-echo "Creating nodes-ssh.txt"
-rm -f nodes-ssh.txt
-count=0
-for h in $nodes; do
-    echo "$h" >> nodes-ssh.txt
-    count=`expr $count + 1`
-done
-
-
-echo "Killing old processes"
-for h in $nodes; do
-    scp -q nodes-ssh.txt $h:$dir
-    ssh $h killall -q ctdb_bench
-done
-
-echo "Starting nodes"
-i=0
-for h in $nodes; do
-    if [ $i -eq `expr $count - 1` ]; then
-       ssh $h $dir/bin/ctdb_bench --nlist $dir/nodes-ssh.txt --socket $h$options
-    else
-       ssh -f $h $dir/bin/ctdb_bench --nlist $dir/nodes-ssh.txt --socket $h $options
-    fi
-    i=`expr $i + 1`
-done
-
-wait
index 74d8785bcb97ba22e3c5a9c4dec97a8eb2f8d084..778619488dd0fa4b97c466e9a6b158dd41f8aba6 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-killall -q ctdb_bench
+killall -q ctdb_bench ctdbd
 
 NUMNODES=2
 if [ $# -gt 0 ]; then
@@ -12,10 +12,16 @@ for i in `seq 1 $NUMNODES`; do
   echo 127.0.0.$i >> nodes.txt
 done
 
+echo "Trying $NUMNODES nodes"
+for i in `seq 1 $NUMNODES`; do
+    $VALGRIND bin/ctdbd --reclock=rec.lock --nlist nodes.txt --event-script=tests/events --logfile=- --socket=sock.$i
+done
+
 killall -9 ctdb_bench
 echo "Trying $NUMNODES nodes"
 for i in `seq 1 $NUMNODES`; do
-  $VALGRIND bin/ctdb_bench --nlist nodes.txt --socket /tmp/ctdb.127.0.0.$i $* &
+  $VALGRIND bin/ctdb_bench --nlist nodes.txt --socket sock.$i $* &
 done
 
 wait
+ctdb shutdown --socket sock.1 -n all
index d6933f48689f9f2d28f82a0db3e51f7b56d6bb48..4ea206f732f3a96587f44cfac5d29cdb69d9f067 100644 (file)
@@ -45,6 +45,7 @@ static double end_timer(void)
 static int timelimit = 10;
 static int num_records = 10;
 static int num_msgs = 1;
+static uint32_t num_nodes;
 
 enum my_functions {FUNC_INCR=1, FUNC_FETCH=2};
 
@@ -91,7 +92,7 @@ static void ring_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
        int *count = (int *)private_data;
        int dest;
        (*count)++;
-       dest = (ctdb_get_vnn(ctdb) + incr) % ctdb_get_num_nodes(ctdb);
+       dest = (ctdb_get_vnn(ctdb) + incr) % num_nodes;
        ctdb_send_message(ctdb, dest, srvid, data);
        if (incr == 1) {
                msg_plus++;
@@ -119,11 +120,11 @@ static void bench_ring(struct ctdb_context *ctdb, struct event_context *ev)
 
                for (i=0;i<num_msgs;i++) {
                        incr = 1;
-                       dest = (ctdb_get_vnn(ctdb) + incr) % ctdb_get_num_nodes(ctdb);
+                       dest = (ctdb_get_vnn(ctdb) + incr) % num_nodes;
                        ctdb_send_message(ctdb, dest, 0, data);
 
                        incr = -1;
-                       dest = (ctdb_get_vnn(ctdb) + incr) % ctdb_get_num_nodes(ctdb);
+                       dest = (ctdb_get_vnn(ctdb) + incr) % num_nodes;
                        ctdb_send_message(ctdb, dest, 0, data);
                }
        }
@@ -143,6 +144,16 @@ static void bench_ring(struct ctdb_context *ctdb, struct event_context *ev)
               msg_count/end_timer(), msg_plus, msg_minus);
 }
 
+/*
+  handler for reconfigure message
+*/
+static void reconfigure_handler(struct ctdb_context *ctdb, uint64_t srvid, 
+                               TDB_DATA data, void *private_data)
+{
+       int *ready = (int *)private_data;
+       *ready = 1;
+}
+
 
 /*
   main program
@@ -166,6 +177,7 @@ int main(int argc, const char *argv[])
        int ret;
        poptContext pc;
        struct event_context *ev;
+       int cluster_ready=0;
 
        pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
 
@@ -188,10 +200,10 @@ int main(int argc, const char *argv[])
        ev = event_context_init(NULL);
 
        /* initialise ctdb */
-       ctdb = ctdb_cmdline_init(ev);
+       ctdb = ctdb_cmdline_client(ev);
 
-       /* start the protocol running */
-       ret = ctdb_start(ctdb);
+       ctdb_set_message_handler(ctdb, CTDB_SRVID_RECONFIGURE, reconfigure_handler, 
+                                &cluster_ready);
 
        /* attach to a specific database */
        ctdb_db = ctdb_attach(ctdb, "test.tdb");
@@ -207,15 +219,15 @@ int main(int argc, const char *argv[])
        if (ctdb_set_message_handler(ctdb, 0, ring_message_handler,&msg_count))
                goto error;
 
-       /* wait until all nodes are connected (should not be needed
-          outside of test code) */
-       ctdb_connect_wait(ctdb);
+       printf("Waiting for cluster\n");
+       while (!cluster_ready) {
+               event_loop_once(ev);
+       }
+
+       ctdb_get_connected_nodes(ctdb, timeval_zero(), ctdb, &num_nodes);
 
        bench_ring(ctdb, ev);
        
 error:
-       /* shut it down */
-       ctdb_shutdown(ctdb);
-
        return 0;
 }
index 4e11a0405d52598393d5ed3b15e288e1a90181d7..4d761679d28cc66cacb8f1141206871a1c063dcb 100644 (file)
@@ -45,7 +45,7 @@ static double end_timer(void)
 static int timelimit = 10;
 static int num_records = 10;
 static int num_msgs = 1;
-
+static uint32_t num_nodes;
 static int msg_count;
 
 #define TESTKEY "testkey"
@@ -100,7 +100,7 @@ static void bench_fetch_1node(struct ctdb_context *ctdb)
        nulldata.dptr = NULL;
        nulldata.dsize = 0;
 
-       dest = (ctdb_get_vnn(ctdb) + 1) % ctdb_get_num_nodes(ctdb);
+       dest = (ctdb_get_vnn(ctdb) + 1) % num_nodes;
        ctdb_send_message(ctdb, dest, 0, nulldata);
 }
 
@@ -127,7 +127,7 @@ static void bench_fetch(struct ctdb_context *ctdb, struct event_context *ev)
 {
        int vnn=ctdb_get_vnn(ctdb);
 
-       if (vnn == ctdb_get_num_nodes(ctdb)-1) {
+       if (vnn == num_nodes - 1) {
                bench_fetch_1node(ctdb);
        }
        
@@ -158,6 +158,16 @@ static int fetch_func(struct ctdb_call_info *call)
        return 0;
 }
 
+/*
+  handler for reconfigure message
+*/
+static void reconfigure_handler(struct ctdb_context *ctdb, uint64_t srvid, 
+                               TDB_DATA data, void *private_data)
+{
+       int *ready = (int *)private_data;
+       *ready = 1;
+}
+
 /*
   main program
 */
@@ -181,6 +191,7 @@ int main(int argc, const char *argv[])
        poptContext pc;
        struct event_context *ev;
        struct ctdb_call call;
+       int cluster_ready=0;
 
        pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
 
@@ -204,10 +215,10 @@ int main(int argc, const char *argv[])
 
        ev = event_context_init(NULL);
 
-       ctdb = ctdb_cmdline_init(ev);
+       ctdb = ctdb_cmdline_client(ev);
 
-       /* start the protocol running */
-       ret = ctdb_start(ctdb);
+       ctdb_set_message_handler(ctdb, CTDB_SRVID_RECONFIGURE, reconfigure_handler, 
+                                &cluster_ready);
 
        /* attach to a specific database */
        ctdb_db = ctdb_attach(ctdb, "test.tdb");
@@ -220,9 +231,12 @@ int main(int argc, const char *argv[])
 
        ctdb_set_message_handler(ctdb, 0, message_handler, &msg_count);
 
-       /* wait until all nodes are connected (should not be needed
-          outside of test code) */
-       ctdb_connect_wait(ctdb);
+       printf("Waiting for cluster\n");
+       while (!cluster_ready) {
+               event_loop_once(ev);
+       }
+
+       ctdb_get_connected_nodes(ctdb, timeval_zero(), ctdb, &num_nodes);
 
        bench_fetch(ctdb, ev);
 
@@ -230,6 +244,8 @@ int main(int argc, const char *argv[])
        call.key.dptr = discard_const(TESTKEY);
        call.key.dsize = strlen(TESTKEY);
 
+       printf("Fetching final record\n");
+
        /* fetch the record */
        call.call_id = FUNC_FETCH;
        call.call_data.dptr = NULL;
@@ -243,8 +259,5 @@ int main(int argc, const char *argv[])
 
        printf("DATA:\n%s\n", (char *)call.reply_data.dptr);
 
-       /* go into a wait loop to allow other nodes to complete */
-       ctdb_shutdown(ctdb);
-
        return 0;
 }
diff --git a/ctdb/tests/ctdb_fetch1.c b/ctdb/tests/ctdb_fetch1.c
deleted file mode 100644 (file)
index c80d553..0000000
+++ /dev/null
@@ -1,291 +0,0 @@
-/* 
-   simple ctdb fetch test
-
-   Copyright (C) Andrew Tridgell  2006
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-#include "lib/events/events.h"
-#include "system/filesys.h"
-#include "popt.h"
-#include "ctdb.h"
-#include "ctdb_private.h"
-#include "cmdline.h"
-#include <sys/time.h>
-
-#define PARENT_SRVID   0
-#define CHILD1_SRVID   1
-#define CHILD2_SRVID   2
-
-int num_msg=0;
-
-static struct timeval tp1,tp2;
-
-static void start_timer(void)
-{
-       gettimeofday(&tp1,NULL);
-}
-
-static double end_timer(void)
-{
-       gettimeofday(&tp2,NULL);
-       return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) - 
-               (tp1.tv_sec + (tp1.tv_usec*1.0e-6));
-}
-
-static void message_handler(struct ctdb_context *ctdb, uint64_t srvid, 
-                           TDB_DATA data, void *private_data)
-{
-       num_msg++;
-}
-static void child_handler(struct ctdb_context *ctdb, uint64_t srvid, 
-                           TDB_DATA data, void *private_data)
-{
-       num_msg++;
-}
-
-void test1(struct ctdb_db_context *ctdb_db)
-{
-       TDB_DATA key, data, data2, store_data;
-       int ret;
-       struct ctdb_record_handle *h;
-       /* 
-          test 1 : write data and read it back.   should all be the same
-        */
-       printf("Test1: write and verify we can read it back: ");
-       key.dptr  = discard_const("Record");
-       key.dsize = strlen((const char *)key.dptr)+1;
-       h = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data);
-       if (h == NULL) {
-               printf("test1: ctdb_fetch_lock() failed\n");
-               exit(1);
-       }
-
-       store_data.dptr  = discard_const("data to store");
-       store_data.dsize = strlen((const char *)store_data.dptr)+1;
-       ret = ctdb_record_store(h, store_data);
-       talloc_free(h);
-       if (ret!=0) {
-               printf("test1: ctdb_record_store() failed\n");
-               exit(1);
-       }
-
-       h = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data2);
-       if (h == NULL) {
-               printf("test1: ctdb_fetch_lock() failed\n");
-               exit(1);
-       }
-
-       /* hopefully   data2 will now contain the record written above */
-       if (!strcmp("data to store", (const char *)data2.dptr)) {
-               printf("SUCCESS\n");
-       } else {
-               printf("FAILURE\n");
-               exit(10);
-       }
-       
-       /* just write it back to unlock it */
-       ret = ctdb_record_store(h, store_data);
-       talloc_free(h);
-       if (ret!=0) {
-               printf("test1: ctdb_record_store() failed\n");
-               exit(1);
-       }
-}
-
-void child(int srvid, struct event_context *ev, struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db)
-{
-       TDB_DATA data;
-       TDB_DATA key, data2;
-       struct ctdb_record_handle *h;
-
-       data.dptr=discard_const("dummy message");
-       data.dsize=strlen((const char *)data.dptr)+1;
-
-       ctdb_set_message_handler(ctdb, srvid, child_handler, NULL);
-
-       ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), PARENT_SRVID, data);
-       while (num_msg==0) {
-               event_loop_once(ev);
-       }
-
-
-       /* fetch and lock the record */
-       key.dptr  = discard_const("Record");
-       key.dsize = strlen((const char *)key.dptr)+1;
-       printf("client:%d fetching the record\n",srvid);
-       h = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data2);
-       printf("client:%d the record is fetched and locked\n",srvid);
-       if (h == NULL) {
-               printf("client: ctdb_fetch_lock() failed\n");
-               exit(1);
-       }
-       ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), PARENT_SRVID, data);
-
-       /* wait until parent tells us to release the lock */
-       while (num_msg==1) {
-               event_loop_once(ev);
-       }
-
-       printf("child %d terminating\n",srvid);
-       exit(10);
-          
-}
-
-/*
-  main program
-*/
-int main(int argc, const char *argv[])
-{
-       struct ctdb_context *ctdb;
-       struct ctdb_db_context *ctdb_db;
-       TDB_DATA data;
-
-       struct poptOption popt_options[] = {
-               POPT_AUTOHELP
-               POPT_CTDB_CMDLINE
-               POPT_TABLEEND
-       };
-       int opt;
-       const char **extra_argv;
-       int extra_argc = 0;
-       int ret;
-       poptContext pc;
-       struct event_context *ev;
-
-       pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
-
-       while ((opt = poptGetNextOpt(pc)) != -1) {
-               switch (opt) {
-               default:
-                       fprintf(stderr, "Invalid option %s: %s\n", 
-                               poptBadOption(pc, 0), poptStrerror(opt));
-                       exit(1);
-               }
-       }
-
-       /* setup the remaining options for the main program to use */
-       extra_argv = poptGetArgs(pc);
-       if (extra_argv) {
-               extra_argv++;
-               while (extra_argv[extra_argc]) extra_argc++;
-       }
-
-       ev = event_context_init(NULL);
-
-       /* initialise ctdb */
-       ctdb = ctdb_cmdline_init(ev);
-       if (ctdb == NULL) {
-               printf("Failed to init ctdb\n");
-               exit(1);
-       }
-
-       /* start the protocol running */
-       ret = ctdb_start(ctdb);
-
-       /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "test.tdb");
-       if (!ctdb_db) {
-               printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
-               exit(1);
-       }
-
-       /*
-          start two child processes
-        */
-       if(fork()){
-               /* 
-                  set up a message handler so our child processes can talk to us
-                */
-               ctdb_set_message_handler(ctdb, PARENT_SRVID, message_handler, NULL);
-       } else {
-               sleep(3);
-               if(!fork()){
-                       child(CHILD1_SRVID, ev, ctdb, ctdb_db);
-               } else {
-                       child(CHILD2_SRVID, ev, ctdb, ctdb_db);
-               }
-       }
-
-       /* 
-          test 1 : write data and read it back.
-        */
-       test1(ctdb_db); 
-
-       /* 
-          wait until both children have sent us a message they have started
-        */
-       printf("Wait for both child processes to start: ");
-       while (num_msg!=2) {
-               event_loop_once(ev);
-       }
-       printf("STARTED\n");
-
-
-       /*
-          send message to child 1 to make it to fetch and lock the record 
-        */
-       data.dptr=discard_const("dummy message");
-       data.dsize=strlen((const char *)data.dptr)+1;
-       ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD1_SRVID, data);
-
-       /* wait for child 1 to complete fetching and locking the record */
-       while (num_msg!=3) {
-               event_loop_once(ev);
-       }
-
-       /* now tell child 2 to fetch and lock the same record */
-       ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD2_SRVID, data);
-
-       /* wait a while for child 2 to complete fetching and locking the 
-          record, this should fail since the record is already locked
-          by the first child */
-       start_timer();
-       while ( (end_timer() < 1.0) && (num_msg!=4) ) {
-               event_loop_once(ev);
-       }
-       if (num_msg!=4) {
-               printf("Child 2 did not get the lock since it is held by client 1:SUCCESS\n");
-       } else {
-               printf("Child 2 did get the lock:FAILURE\n");
-               exit(10);
-       }
-
-       /* send message to child 1 to terminate, which should let child 2
-          get the lock.
-        */
-       ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD1_SRVID, data);
-
-
-       /* wait for a final message from child 2 it has received the lock
-          which indicates success */
-       while (num_msg!=4) {
-               event_loop_once(ev);
-       }
-       printf("child 2 aquired the lock after child 1 terminated:SUCCESS\n");
-
-       /* send a message to child 2 to tell it to terminate too */
-       ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD2_SRVID, data);
-
-
-       printf("Test was SUCCESSFUL\n");
-
-       /* shut it down */
-       talloc_free(ctdb);
-       return 0;
-}
diff --git a/ctdb/tests/ctdb_messaging.c b/ctdb/tests/ctdb_messaging.c
deleted file mode 100644 (file)
index 3a5cc15..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/* 
-   test of messaging
-
-   Copyright (C) Andrew Tridgell  2006
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-#include "lib/events/events.h"
-#include "system/filesys.h"
-#include "popt.h"
-#include "cmdline.h"
-
-static int timelimit = 10;
-static int num_records = 10;
-static int num_msgs = 1;
-static int num_clients = 2;
-
-
-/*
-  handler for messages in bench_ring()
-*/
-static void message_handler(struct ctdb_context *ctdb, uint64_t srvid, 
-                                TDB_DATA data, void *private_data)
-{
-       printf("client vnn:%d received a message to srvid:%llu [%s]\n",
-              ctdb_get_vnn(ctdb), (unsigned long long)srvid, data.dptr);
-       fflush(stdout);
-}
-
-/*
-  main program
-*/
-int main(int argc, const char *argv[])
-{
-       struct ctdb_context *ctdb;
-       struct ctdb_db_context *ctdb_db;
-       char buf[256];
-
-       struct poptOption popt_options[] = {
-               POPT_AUTOHELP
-               POPT_CTDB_CMDLINE
-               { "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" },
-               { "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" },
-               { "num-msgs", 'n', POPT_ARG_INT, &num_msgs, 0, "num_msgs", "integer" },
-               { "num-clients", 0, POPT_ARG_INT, &num_clients, 0, "num_clients", "integer" },
-               POPT_TABLEEND
-       };
-       int opt;
-       const char **extra_argv;
-       int extra_argc = 0;
-       int ret, i, j;
-       poptContext pc;
-       struct event_context *ev;
-       pid_t pid;
-       int srvid;
-       TDB_DATA data;
-
-       pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
-
-       while ((opt = poptGetNextOpt(pc)) != -1) {
-               switch (opt) {
-               default:
-                       fprintf(stderr, "Invalid option %s: %s\n", 
-                               poptBadOption(pc, 0), poptStrerror(opt));
-                       exit(1);
-               }
-       }
-
-       /* setup the remaining options for the main program to use */
-       extra_argv = poptGetArgs(pc);
-       if (extra_argv) {
-               extra_argv++;
-               while (extra_argv[extra_argc]) extra_argc++;
-       }
-
-       ev = event_context_init(NULL);
-
-       /* initialise ctdb */
-       ctdb = ctdb_cmdline_init(ev);
-       if (ctdb == NULL) {
-               printf("Failed to init ctdb\n");
-               exit(1);
-       }
-
-       /* start the protocol running */
-       ret = ctdb_start(ctdb);
-
-       /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "test.tdb");
-       if (!ctdb_db) {
-               printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
-               exit(1);
-       }
-
-       srvid = -1;
-       for (i=0;i<num_clients-1;i++) {
-               pid=fork();
-               if (pid) {
-                       srvid = i;
-                       break;
-               }
-       }
-       if (srvid == -1) {
-               srvid = num_clients-1;
-       }
-
-       ctdb_set_message_handler(ctdb, srvid, message_handler, NULL);
-
-       /* wait until all nodes are connected (should not be needed
-          outside of test code) */
-       ctdb_connect_wait(ctdb);
-
-       sleep(3);
-
-       printf("sending message from vnn:%d to vnn:%d/srvid:%d\n",ctdb_get_vnn(ctdb),ctdb_get_vnn(ctdb), 1-srvid);
-       for (i=0;i<ctdb_get_num_nodes(ctdb);i++) {
-               for (j=0;j<num_clients;j++) {
-                       printf("sending message to %d:%d\n", i, j);
-                       sprintf(buf,"Message from %d to vnn:%d srvid:%d",ctdb_get_vnn(ctdb),i,j);
-                       data.dptr = (unsigned char *)buf;
-                       data.dsize=strlen(buf)+1;
-                       ctdb_send_message(ctdb, i, j, data);
-               }
-       }
-
-       while (1) {
-               event_loop_once(ev);
-       }
-       
-       /* shut it down */
-       ctdb_shutdown(ctdb);
-
-       return 0;
-}
diff --git a/ctdb/tests/ctdb_test.c b/ctdb/tests/ctdb_test.c
deleted file mode 100644 (file)
index 2e93a60..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-/* 
-   ctdb test harness
-
-   Copyright (C) Andrew Tridgell  2006
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-#include "lib/events/events.h"
-#include "system/filesys.h"
-#include "popt.h"
-#include "cmdline.h"
-#include "ctdb_private.h"
-
-enum my_functions {FUNC_SORT=1, FUNC_FETCH=2};
-
-static int int_compare(int *i1, int *i2)
-{
-       return *i1 - *i2;
-}
-
-/*
-  add an integer into a record in sorted order
-*/
-static int sort_func(struct ctdb_call_info *call)
-{
-       if (call->call_data == NULL ||
-           call->call_data->dsize != sizeof(int)) {
-               return CTDB_ERR_INVALID;
-       }
-       call->new_data = talloc(call, TDB_DATA);
-       if (call->new_data == NULL) {
-               return CTDB_ERR_NOMEM;
-       }
-       call->new_data->dptr = talloc_size(call, 
-                                          call->record_data.dsize + 
-                                          call->call_data->dsize);
-       if (call->new_data->dptr == NULL) {
-               return CTDB_ERR_NOMEM;
-       }
-       call->new_data->dsize = call->record_data.dsize + call->call_data->dsize;
-       memcpy(call->new_data->dptr,
-              call->record_data.dptr, call->record_data.dsize);
-       memcpy(call->new_data->dptr+call->record_data.dsize,
-              call->call_data->dptr, call->call_data->dsize);
-
-       qsort(call->new_data->dptr, call->new_data->dsize / sizeof(int),
-             sizeof(int), (comparison_fn_t)int_compare);
-
-       return 0;
-}
-
-/*
-  ctdb call function to fetch a record
-*/
-static int fetch_func(struct ctdb_call_info *call)
-{
-       call->reply_data = &call->record_data;
-       return 0;
-}
-
-/*
-  main program
-*/
-int main(int argc, const char *argv[])
-{
-       struct ctdb_context *ctdb;
-       struct ctdb_db_context *ctdb_db;
-
-       struct poptOption popt_options[] = {
-               POPT_AUTOHELP
-               POPT_CTDB_CMDLINE
-               POPT_TABLEEND
-       };
-       int opt;
-       const char **extra_argv;
-       int extra_argc = 0;
-       int i, ret;
-       poptContext pc;
-       struct event_context *ev;
-       struct ctdb_call call;
-       const char *path;
-
-       pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
-
-       while ((opt = poptGetNextOpt(pc)) != -1) {
-               switch (opt) {
-               default:
-                       fprintf(stderr, "Invalid option %s: %s\n", 
-                               poptBadOption(pc, 0), poptStrerror(opt));
-                       exit(1);
-               }
-       }
-
-       /* setup the remaining options for the main program to use */
-       extra_argv = poptGetArgs(pc);
-       if (extra_argv) {
-               extra_argv++;
-               while (extra_argv[extra_argc]) extra_argc++;
-       }
-
-       ev = event_context_init(NULL);
-
-       /* initialise ctdb */
-       ctdb = ctdb_cmdline_init(ev);
-       if (ctdb == NULL) {
-               printf("Failed to init ctdb\n");
-               exit(1);
-       }
-
-       /* start the protocol running */
-       ret = ctdb_start(ctdb);
-
-       /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "test.tdb");
-       if (!ctdb_db) {
-               printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
-               exit(1);
-       }
-
-       /* setup a ctdb call function */
-       ret = ctdb_set_call(ctdb_db, sort_func,  FUNC_SORT);
-       ret = ctdb_set_call(ctdb_db, fetch_func, FUNC_FETCH);
-
-       ctdb_connect_wait(ctdb);
-
-       /* find the full path to the database file */
-       ctdb_ctrl_getdbpath(ctdb, timeval_current_ofs(1, 0), CTDB_CURRENT_NODE, ctdb_db->db_id, ctdb_db, &path);
-       printf("path to database:[%s]\n",path);
-
-       ZERO_STRUCT(call);
-       call.key.dptr = discard_const("test");
-       call.key.dsize = strlen("test")+1;
-
-       /* add some random data */
-       for (i=0;i<10;i++) {
-               int v = random() % 1000;
-
-               call.call_id = FUNC_SORT;
-               call.call_data.dptr = (uint8_t *)&v;
-               call.call_data.dsize = sizeof(v);
-
-               ret = ctdb_call(ctdb_db, &call);
-               if (ret == -1) {
-                       printf("ctdb_call FUNC_SORT failed - %s\n", ctdb_errstr(ctdb));
-                       exit(1);
-               }
-       }
-
-       /* fetch the record */
-       call.call_id = FUNC_FETCH;
-       call.call_data.dptr = NULL;
-       call.call_data.dsize = 0;
-
-       ret = ctdb_call(ctdb_db, &call);
-       if (ret == -1) {
-               printf("ctdb_call FUNC_FETCH failed - %s\n", ctdb_errstr(ctdb));
-               exit(1);
-       }
-
-       for (i=0;i<call.reply_data.dsize/sizeof(int);i++) {
-               printf("%3d\n", ((int *)call.reply_data.dptr)[i]);
-       }
-       talloc_free(call.reply_data.dptr);
-
-       ctdb_dump_db(ctdb_db, stdout);
-
-       /* go into a wait loop to allow other nodes to complete */
-       ctdb_shutdown(ctdb);
-
-       return 0;
-}
index a17dc76e05d7a449d39825e3a15b2a952c4f2054..b5fdd1b08fefcd7c358e7d6b17d26a904306a5fe 100755 (executable)
@@ -10,9 +10,17 @@ for i in `seq 1 $NUMNODES`; do
   echo 127.0.0.$i >> nodes.txt
 done
 
-killall -9 ctdb_fetch
+killall -q ctdbd
 echo "Trying $NUMNODES nodes"
 for i in `seq 1 $NUMNODES`; do
-  $VALGRIND bin/ctdb_fetch --nlist nodes.txt --socket /tmp/ctdb.127.0.0.$i $* &
+    $VALGRIND bin/ctdbd --reclock=rec.lock --nlist nodes.txt --event-script=tests/events --logfile=- --socket=sock.$i
+done
+
+killall -9 -q ctdb_fetch
+for i in `seq 1 $NUMNODES`; do
+  $VALGRIND bin/ctdb_fetch --socket sock.$i $* &
 done
 wait
+
+echo "Shutting down"
+bin/ctdb shutdown -n all --socket=sock.1
diff --git a/ctdb/tests/fetch1.sh b/ctdb/tests/fetch1.sh
deleted file mode 100755 (executable)
index 0338db4..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-
-killall -q ctdb_fetch1
-
-echo "Trying node"
-bin/ctdb_fetch1 --nlist tests/1node.txt $* 
-wait
diff --git a/ctdb/tests/messaging.sh b/ctdb/tests/messaging.sh
deleted file mode 100755 (executable)
index ab8cfcf..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/sh
-
-#!/bin/sh
-
-killall -q ctdb_messaging
-
-NUMNODES=2
-if [ $# -gt 0 ]; then
-    NUMNODES=$1
-fi
-
-rm -f nodes.txt
-for i in `seq 1 $NUMNODES`; do
-  echo 127.0.0.$i >> nodes.txt
-done
-
-killall -9 ctdb_messaging
-echo "Trying $NUMNODES nodes"
-for i in `seq 1 $NUMNODES`; do
-  $VALGRIND bin/ctdb_messaging --nlist nodes.txt --socket /tmp/ctdb.127.0.0.$i $* &
-done
-
-wait
index aab6cdacfa4daa51547c05bd847d5e629509f38e..356a9b21a045e3126dae93bc78f05d9cc3033aa8 100755 (executable)
@@ -2,7 +2,6 @@
 
 tests/fetch.sh 4 || exit 1
 tests/bench.sh 4 || exit 1
-tests/test.sh || exit 1
 tests/ctdbd.sh || exit 1
 
 echo "All OK"
diff --git a/ctdb/tests/test.sh b/ctdb/tests/test.sh
deleted file mode 100755 (executable)
index 0a6e377..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-
-#!/bin/sh
-
-killall -q ctdb_test
-
-NUMNODES=2
-if [ $# -gt 0 ]; then
-    NUMNODES=$1
-    shift
-fi
-
-rm -f nodes.txt
-for i in `seq 1 $NUMNODES`; do
-  echo 127.0.0.$i >> nodes.txt
-done
-
-killall -9 ctdb_test
-echo "Trying $NUMNODES nodes"
-for i in `seq 1 $NUMNODES`; do
-  $VALGRIND bin/ctdb_test --nlist nodes.txt --socket /tmp/ctdb.127.0.0.$i $* &
-done
-
-wait
diff --git a/ctdb/tests/test1.sh b/ctdb/tests/test1.sh
deleted file mode 100755 (executable)
index cca46e0..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-
-echo "Testing daemon mode"
-bin/ctdb_test --nlist tests/1node.txt
-wait
-
-echo "Testing self connect"
-bin/ctdb_test --nlist tests/1node.txt --self-connect
-wait