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
@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)
clean:
rm -f *.o */*.o */*/*.o
- rm -f $(BINS)
+ rm -f $(BINS) $(SBINS) $(TEST_BINS)
distclean: clean
rm -f *~ */*~
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
*/
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);
}
}
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);
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) &&
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) {
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) {
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);
+++ /dev/null
-127.0.0.1
-127.0.0.2
-127.0.0.3
-127.0.0.4
+++ /dev/null
-#!/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
#!/bin/sh
-killall -q ctdb_bench
+killall -q ctdb_bench ctdbd
NUMNODES=2
if [ $# -gt 0 ]; then
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
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};
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++;
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);
}
}
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
int ret;
poptContext pc;
struct event_context *ev;
+ int cluster_ready=0;
pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
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");
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;
}
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"
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);
}
{
int vnn=ctdb_get_vnn(ctdb);
- if (vnn == ctdb_get_num_nodes(ctdb)-1) {
+ if (vnn == num_nodes - 1) {
bench_fetch_1node(ctdb);
}
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
*/
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);
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");
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);
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;
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;
}
+++ /dev/null
-/*
- 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;
-}
+++ /dev/null
-/*
- 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;
-}
+++ /dev/null
-/*
- 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;
-}
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
+++ /dev/null
-#!/bin/sh
-
-killall -q ctdb_fetch1
-
-echo "Trying node"
-bin/ctdb_fetch1 --nlist tests/1node.txt $*
-wait
+++ /dev/null
-#!/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
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"
+++ /dev/null
-#!/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
+++ /dev/null
-#!/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