From 68963d865a36ea6c717c6dfb729a932f3dcefa7c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 2 Jun 2007 13:16:11 +1000 Subject: [PATCH] first step towards fixing "make test" with the new daemon system (This used to be ctdb commit f95f7e4c93dea482e6cf0614b5415229a7c9f3fb) --- ctdb/Makefile.in | 12 +- ctdb/common/ctdb.c | 10 +- ctdb/common/ctdb_client.c | 15 +- ctdb/common/ctdb_ltdb.c | 6 + ctdb/common/ctdb_recover.c | 2 +- ctdb/tests/1node.txt | 1 - ctdb/tests/4nodes.txt | 4 - ctdb/tests/bench-ssh.sh | 43 ------ ctdb/tests/bench.sh | 10 +- ctdb/tests/ctdb_bench.c | 36 +++-- ctdb/tests/ctdb_fetch.c | 37 +++-- ctdb/tests/ctdb_fetch1.c | 291 ------------------------------------ ctdb/tests/ctdb_messaging.c | 148 ------------------ ctdb/tests/ctdb_test.c | 185 ----------------------- ctdb/tests/fetch.sh | 12 +- ctdb/tests/fetch1.sh | 7 - ctdb/tests/messaging.sh | 23 --- ctdb/tests/run_tests.sh | 1 - ctdb/tests/test.sh | 24 --- ctdb/tests/test1.sh | 9 -- 20 files changed, 80 insertions(+), 796 deletions(-) delete mode 100644 ctdb/tests/1node.txt delete mode 100644 ctdb/tests/4nodes.txt delete mode 100755 ctdb/tests/bench-ssh.sh delete mode 100644 ctdb/tests/ctdb_fetch1.c delete mode 100644 ctdb/tests/ctdb_messaging.c delete mode 100644 ctdb/tests/ctdb_test.c delete mode 100755 ctdb/tests/fetch1.sh delete mode 100755 ctdb/tests/messaging.sh delete mode 100755 ctdb/tests/test.sh delete mode 100755 ctdb/tests/test1.sh diff --git a/ctdb/Makefile.in b/ctdb/Makefile.in index 143a0c254b7..c50d4ea6e96 100644 --- a/ctdb/Makefile.in +++ b/ctdb/Makefile.in @@ -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 *~ */*~ diff --git a/ctdb/common/ctdb.c b/ctdb/common/ctdb.c index 59db0960996..4464bef9c72 100644 --- a/ctdb/common/ctdb.c +++ b/ctdb/common/ctdb.c @@ -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;inum_nodes;i++) { hdr->destnode = ctdb->nodes[i]->vnn; ctdb_queue_packet(ctdb, hdr); } diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c index 68bb15126f2..154ce86129c 100644 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@ -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) { diff --git a/ctdb/common/ctdb_ltdb.c b/ctdb/common/ctdb_ltdb.c index e98e8cfd500..a6f0879c6f0 100644 --- a/ctdb/common/ctdb_ltdb.c +++ b/ctdb/common/ctdb_ltdb.c @@ -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) { diff --git a/ctdb/common/ctdb_recover.c b/ctdb/common/ctdb_recover.c index 01f8373f175..3f1b1506ae9 100644 --- a/ctdb/common/ctdb_recover.c +++ b/ctdb/common/ctdb_recover.c @@ -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 index 7b9ad531d26..00000000000 --- a/ctdb/tests/1node.txt +++ /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 index 99b07328b38..00000000000 --- a/ctdb/tests/4nodes.txt +++ /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 index 92f81a7297d..00000000000 --- a/ctdb/tests/bench-ssh.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh - -if [ $# -lt 1 ]; then - echo "Usage: bench-ssh.sh " - 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 diff --git a/ctdb/tests/bench.sh b/ctdb/tests/bench.sh index 74d8785bcb9..778619488dd 100755 --- a/ctdb/tests/bench.sh +++ b/ctdb/tests/bench.sh @@ -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 diff --git a/ctdb/tests/ctdb_bench.c b/ctdb/tests/ctdb_bench.c index d6933f48689..4ea206f732f 100644 --- a/ctdb/tests/ctdb_bench.c +++ b/ctdb/tests/ctdb_bench.c @@ -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 - -#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 index 3a5cc15e184..00000000000 --- a/ctdb/tests/ctdb_messaging.c +++ /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;icall_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> 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 index 0338db4f9fa..00000000000 --- a/ctdb/tests/fetch1.sh +++ /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 index ab8cfcfd492..00000000000 --- a/ctdb/tests/messaging.sh +++ /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 diff --git a/ctdb/tests/run_tests.sh b/ctdb/tests/run_tests.sh index aab6cdacfa4..356a9b21a04 100755 --- a/ctdb/tests/run_tests.sh +++ b/ctdb/tests/run_tests.sh @@ -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 index 0a6e3779b4e..00000000000 --- a/ctdb/tests/test.sh +++ /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 index cca46e04c6e..00000000000 --- a/ctdb/tests/test1.sh +++ /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 -- 2.34.1