diff options
Diffstat (limited to 'source4/cluster/ctdb/tests')
-rwxr-xr-x | source4/cluster/ctdb/tests/bench.sh | 24 | ||||
-rw-r--r-- | source4/cluster/ctdb/tests/ctdb_bench.c | 229 | ||||
-rw-r--r-- | source4/cluster/ctdb/tests/ctdb_fetch.c | 262 | ||||
-rw-r--r-- | source4/cluster/ctdb/tests/ctdb_store.c | 156 | ||||
-rwxr-xr-x | source4/cluster/ctdb/tests/ctdbd.sh | 50 | ||||
-rwxr-xr-x | source4/cluster/ctdb/tests/events | 68 | ||||
-rwxr-xr-x | source4/cluster/ctdb/tests/fetch.sh | 24 | ||||
-rw-r--r-- | source4/cluster/ctdb/tests/nodes.txt | 4 | ||||
-rw-r--r-- | source4/cluster/ctdb/tests/public_addresses | 4 | ||||
-rwxr-xr-x | source4/cluster/ctdb/tests/recover.sh | 107 | ||||
-rwxr-xr-x | source4/cluster/ctdb/tests/run_tests.sh | 8 | ||||
-rwxr-xr-x | source4/cluster/ctdb/tests/start_daemons.sh | 28 |
12 files changed, 964 insertions, 0 deletions
diff --git a/source4/cluster/ctdb/tests/bench.sh b/source4/cluster/ctdb/tests/bench.sh new file mode 100755 index 0000000000..48a4277591 --- /dev/null +++ b/source4/cluster/ctdb/tests/bench.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +killall -q ctdb_bench ctdbd + +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 + +tests/start_daemons.sh $NUMNODES nodes.txt || exit 1 + +killall -9 ctdb_bench +echo "Trying $NUMNODES nodes" +for i in `seq 1 $NUMNODES`; do + valgrind -q $VALGRIND bin/ctdb_bench --socket sock.$i -n $NUMNODES $* & +done + +wait +bin/ctdb shutdown --socket sock.1 -n all diff --git a/source4/cluster/ctdb/tests/ctdb_bench.c b/source4/cluster/ctdb/tests/ctdb_bench.c new file mode 100644 index 0000000000..77b7f15d35 --- /dev/null +++ b/source4/cluster/ctdb/tests/ctdb_bench.c @@ -0,0 +1,229 @@ +/* + simple ctdb benchmark + + 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 3 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, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "system/filesys.h" +#include "popt.h" +#include "cmdline.h" + +#include <sys/time.h> +#include <time.h> + +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 int timelimit = 10; +static int num_records = 10; +static int num_nodes; + +enum my_functions {FUNC_INCR=1, FUNC_FETCH=2}; + +/* + ctdb call function to increment an integer +*/ +static int incr_func(struct ctdb_call_info *call) +{ + if (call->record_data.dsize == 0) { + call->new_data = talloc(call, TDB_DATA); + if (call->new_data == NULL) { + return CTDB_ERR_NOMEM; + } + call->new_data->dptr = talloc_size(call, 4); + call->new_data->dsize = 4; + *(uint32_t *)call->new_data->dptr = 0; + } else { + call->new_data = &call->record_data; + } + (*(uint32_t *)call->new_data->dptr)++; + 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; +} + + +static int msg_count; +static int msg_plus, msg_minus; + +/* + handler for messages in bench_ring() +*/ +static void ring_message_handler(struct ctdb_context *ctdb, uint64_t srvid, + TDB_DATA data, void *private_data) +{ + int incr = *(int *)data.dptr; + int *count = (int *)private_data; + int dest; + (*count)++; + dest = (ctdb_get_vnn(ctdb) + incr) % num_nodes; + ctdb_send_message(ctdb, dest, srvid, data); + if (incr == 1) { + msg_plus++; + } else { + msg_minus++; + } +} + +/* + benchmark sending messages in a ring around the nodes +*/ +static void bench_ring(struct ctdb_context *ctdb, struct event_context *ev) +{ + int vnn=ctdb_get_vnn(ctdb); + + if (vnn == 0) { + /* two messages are injected into the ring, moving + in opposite directions */ + int dest, incr; + TDB_DATA data; + + data.dptr = (uint8_t *)&incr; + data.dsize = sizeof(incr); + + incr = 1; + dest = (ctdb_get_vnn(ctdb) + incr) % num_nodes; + ctdb_send_message(ctdb, dest, 0, data); + + incr = -1; + dest = (ctdb_get_vnn(ctdb) + incr) % num_nodes; + ctdb_send_message(ctdb, dest, 0, data); + } + + start_timer(); + + while (end_timer() < timelimit) { + if (vnn == 0 && msg_count % 10000 == 0) { + printf("Ring: %.2f msgs/sec (+ve=%d -ve=%d)\r", + msg_count/end_timer(), msg_plus, msg_minus); + fflush(stdout); + } + event_loop_once(ev); + } + + printf("Ring: %.2f msgs/sec (+ve=%d -ve=%d)\n", + 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 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 + { "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" }, + { "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" }, + { NULL, 'n', POPT_ARG_INT, &num_nodes, 0, "num_nodes", "integer" }, + POPT_TABLEEND + }; + int opt; + const char **extra_argv; + int extra_argc = 0; + int ret; + poptContext pc; + struct event_context *ev; + int cluster_ready=0; + + 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 = s4_event_context_init(NULL); + + /* initialise ctdb */ + ctdb = ctdb_cmdline_client(ev); + + 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_db) { + printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb)); + exit(1); + } + + /* setup a ctdb call function */ + ret = ctdb_set_call(ctdb_db, incr_func, FUNC_INCR); + ret = ctdb_set_call(ctdb_db, fetch_func, FUNC_FETCH); + + if (ctdb_set_message_handler(ctdb, 0, ring_message_handler,&msg_count)) + goto error; + + printf("Waiting for cluster\n"); + while (1) { + uint32_t recmode=1; + ctdb_ctrl_getrecmode(ctdb, timeval_zero(), CTDB_CURRENT_NODE, &recmode); + if (recmode == 0) break; + event_loop_once(ev); + } + + bench_ring(ctdb, ev); + +error: + return 0; +} diff --git a/source4/cluster/ctdb/tests/ctdb_fetch.c b/source4/cluster/ctdb/tests/ctdb_fetch.c new file mode 100644 index 0000000000..d5ec645757 --- /dev/null +++ b/source4/cluster/ctdb/tests/ctdb_fetch.c @@ -0,0 +1,262 @@ +/* + simple ctdb benchmark + + 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 3 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, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "system/filesys.h" +#include "popt.h" +#include "cmdline.h" + +#include <sys/time.h> +#include <time.h> + +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 int timelimit = 10; +static int num_records = 10; +static int num_nodes; +static int msg_count; + +#define TESTKEY "testkey" + +/* + fetch a record + store a expanded record + send a message to next node to tell it to do the same +*/ +static void bench_fetch_1node(struct ctdb_context *ctdb) +{ + TDB_DATA key, data, nulldata; + struct ctdb_db_context *ctdb_db; + TALLOC_CTX *tmp_ctx = talloc_new(ctdb); + int dest, ret; + struct ctdb_record_handle *h; + + key.dptr = discard_const(TESTKEY); + key.dsize = strlen(TESTKEY); + + ctdb_db = ctdb_db_handle(ctdb, "test.tdb"); + + h = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data); + if (h == NULL) { + printf("Failed to fetch record '%s' on node %d\n", + (const char *)key.dptr, ctdb_get_vnn(ctdb)); + talloc_free(tmp_ctx); + return; + } + + if (data.dsize > 1000) { + data.dsize = 0; + } + + if (data.dsize == 0) { + data.dptr = (uint8_t *)talloc_asprintf(tmp_ctx, "Test data\n"); + } + data.dptr = (uint8_t *)talloc_asprintf_append((char *)data.dptr, + "msg_count=%d on node %d\n", + msg_count, ctdb_get_vnn(ctdb)); + data.dsize = strlen((const char *)data.dptr)+1; + + ret = ctdb_record_store(h, data); + talloc_free(h); + if (ret != 0) { + printf("Failed to store record\n"); + } + + talloc_free(tmp_ctx); + + /* tell the next node to do the same */ + nulldata.dptr = NULL; + nulldata.dsize = 0; + + dest = (ctdb_get_vnn(ctdb) + 1) % num_nodes; + ctdb_send_message(ctdb, dest, 0, nulldata); +} + +/* + handler for messages in bench_ring() +*/ +static void message_handler(struct ctdb_context *ctdb, uint64_t srvid, + TDB_DATA data, void *private_data) +{ + msg_count++; + bench_fetch_1node(ctdb); +} + + +/* + benchmark the following: + + fetch a record + store a expanded record + send a message to next node to tell it to do the same + +*/ +static void bench_fetch(struct ctdb_context *ctdb, struct event_context *ev) +{ + int vnn=ctdb_get_vnn(ctdb); + + if (vnn == num_nodes - 1) { + bench_fetch_1node(ctdb); + } + + start_timer(); + + while (end_timer() < timelimit) { + if (vnn == 0 && msg_count % 100 == 0) { + printf("Fetch: %.2f msgs/sec\r", msg_count/end_timer()); + fflush(stdout); + } + if (event_loop_once(ev) != 0) { + printf("Event loop failed!\n"); + break; + } + } + + printf("Fetch: %.2f msgs/sec\n", msg_count/end_timer()); +} + +enum my_functions {FUNC_FETCH=1}; + +/* + ctdb call function to fetch a record +*/ +static int fetch_func(struct ctdb_call_info *call) +{ + call->reply_data = &call->record_data; + 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 +*/ +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 + { "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" }, + { "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" }, + { NULL, 'n', POPT_ARG_INT, &num_nodes, 0, "num_nodes", "integer" }, + POPT_TABLEEND + }; + int opt; + const char **extra_argv; + int extra_argc = 0; + int ret; + 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); + + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + default: + fprintf(stderr, "Invalid option %s: %s\n", + poptBadOption(pc, 0), poptStrerror(opt)); + exit(1); + } + } + + /* talloc_enable_leak_report_full(); */ + + /* 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 = s4_event_context_init(NULL); + + ctdb = ctdb_cmdline_client(ev); + + 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_db) { + printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb)); + exit(1); + } + + ret = ctdb_set_call(ctdb_db, fetch_func, FUNC_FETCH); + + ctdb_set_message_handler(ctdb, 0, message_handler, &msg_count); + + printf("Waiting for cluster\n"); + while (1) { + uint32_t recmode=1; + ctdb_ctrl_getrecmode(ctdb, timeval_zero(), CTDB_CURRENT_NODE, &recmode); + if (recmode == 0) break; + event_loop_once(ev); + } + + bench_fetch(ctdb, ev); + + ZERO_STRUCT(call); + 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; + 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); + } + + printf("DATA:\n%s\n", (char *)call.reply_data.dptr); + + return 0; +} diff --git a/source4/cluster/ctdb/tests/ctdb_store.c b/source4/cluster/ctdb/tests/ctdb_store.c new file mode 100644 index 0000000000..8b44276d21 --- /dev/null +++ b/source4/cluster/ctdb/tests/ctdb_store.c @@ -0,0 +1,156 @@ +/* + simple tool to create a lot of records on a tdb and to read them out + + Copyright (C) Andrew Tridgell 2006 + Ronnie sahlberg 2007 + + 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 3 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, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "system/filesys.h" +#include "popt.h" +#include "cmdline.h" + +#include <sys/time.h> +#include <time.h> + +static int num_records = 10; + + +static void store_records(struct ctdb_context *ctdb, struct event_context *ev) +{ + TDB_DATA key, data; + struct ctdb_db_context *ctdb_db; + TALLOC_CTX *tmp_ctx = talloc_new(ctdb); + int ret; + struct ctdb_record_handle *h; + uint32_t i; + + ctdb_db = ctdb_db_handle(ctdb, "test.tdb"); + + printf("creating %d records\n", num_records); + for (i=0;i<num_records;i++) { + key.dptr = (uint8_t *)&i; + key.dsize = sizeof(uint32_t); + + h = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data); + if (h == NULL) { + printf("Failed to fetch record '%s' on node %d\n", + (const char *)key.dptr, ctdb_get_vnn(ctdb)); + talloc_free(tmp_ctx); + return; + } + + data.dptr = (uint8_t *)&i; + data.dsize = sizeof(uint32_t); + + ret = ctdb_record_store(h, data); + talloc_free(h); + if (ret != 0) { + printf("Failed to store record\n"); + } + if (i % 1000 == 0) { + printf("%u\r", i); + fflush(stdout); + } + } + + printf("fetching all %d records\n", num_records); + while (1) { + for (i=0;i<num_records;i++) { + key.dptr = (uint8_t *)&i; + key.dsize = sizeof(uint32_t); + + h = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data); + if (h == NULL) { + printf("Failed to fetch record '%s' on node %d\n", + (const char *)key.dptr, ctdb_get_vnn(ctdb)); + talloc_free(tmp_ctx); + return; + } + talloc_free(h); + } + sleep(1); + printf("."); + fflush(stdout); + } + + talloc_free(tmp_ctx); +} + +/* + 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 + { "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" }, + POPT_TABLEEND + }; + int opt; + const char **extra_argv; + int extra_argc = 0; + 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); + } + } + + /* talloc_enable_leak_report_full(); */ + + /* 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 = s4_event_context_init(NULL); + + ctdb = ctdb_cmdline_client(ev); + + /* 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); + } + + printf("Waiting for cluster\n"); + while (1) { + uint32_t recmode=1; + ctdb_ctrl_getrecmode(ctdb, timeval_zero(), CTDB_CURRENT_NODE, &recmode); + if (recmode == 0) break; + event_loop_once(ev); + } + + store_records(ctdb, ev); + + return 0; +} diff --git a/source4/cluster/ctdb/tests/ctdbd.sh b/source4/cluster/ctdb/tests/ctdbd.sh new file mode 100755 index 0000000000..4a1e9976b2 --- /dev/null +++ b/source4/cluster/ctdb/tests/ctdbd.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +killall -q ctdbd + +tests/start_daemons.sh 2 tests/nodes.txt || exit 1 + +echo "Testing ping" +$VALGRIND bin/ctdb ping || exit 1 + +echo "Testing status" +$VALGRIND bin/ctdb status || exit 1 + +echo "Testing statistics" +$VALGRIND bin/ctdb -n all statistics || exit 1 + +echo "Testing statisticsreset" +$VALGRIND bin/ctdb -n all statisticsreset || exit 1 + +echo "Testing debug" +$VALGRIND bin/ctdb -n all setdebug 3 || exit 1 +$VALGRIND bin/ctdb -n all getdebug || exit 1 +$VALGRIND bin/ctdb -n all setdebug 0 || exit 1 +$VALGRIND bin/ctdb -n all getdebug || exit 1 + +echo "Attaching to some databases" +$VALGRIND bin/ctdb attach test1.tdb || exit 1 +$VALGRIND bin/ctdb attach test2.tdb || exit 1 + +echo "Testing getdbmap" +$VALGRIND bin/ctdb getdbmap || exit 1 + +echo "Testing status" +$VALGRIND bin/ctdb status || exit 1 + +echo "Testing variables" +$VALGRIND bin/ctdb listvars || exit 1 +$VALGRIND bin/ctdb getvar TraverseTimeout || exit 1 +$VALGRIND bin/ctdb setvar TraverseTimeout 10 || exit 1 +$VALGRIND bin/ctdb getvar TraverseTimeout || exit 1 + +sleep 1 + +echo "Testing shutdown" +$VALGRIND bin/ctdb shutdown -n all || exit 1 + +sleep 1 + +echo "All done" +killall -q ctdbd +exit 0 diff --git a/source4/cluster/ctdb/tests/events b/source4/cluster/ctdb/tests/events new file mode 100755 index 0000000000..fb319bc426 --- /dev/null +++ b/source4/cluster/ctdb/tests/events @@ -0,0 +1,68 @@ +#!/bin/sh +# event script for 'make test' + +cmd="$1" +shift + +case $cmd in + monitor) + echo "`date` monitor event" + exit 0 + ;; + startup) + echo "`date` ctdb startup event" + exit 0; + ;; + + takeip) + if [ $# != 3 ]; then + echo "must supply interface, IP and maskbits" + exit 1 + fi + iface=$1 + ip=$2 + maskbits=$3 + + [ `id -u` = 0 ] && { + /sbin/ip addr add $ip/$maskbits dev $iface || { + echo "`/bin/date` Failed to add $ip/$maskbits on dev $iface" + exit 1 + } + } + exit 0; + ;; + + + ################################################## + # called when ctdbd wants to release an IP address + releaseip) + if [ $# != 3 ]; then + echo "`/bin/date` must supply interface, IP and maskbits" + exit 1 + fi + iface=$1 + ip=$2 + maskbits=$3 + [ `id -u` = 0 ] && { + /sbin/ip addr del $ip/$maskbits dev $iface || { + echo "`/bin/date` Failed to del $ip on dev $iface" + exit 1 + } + } + echo "`date` ctdb takeip event for $1 $2 $3" + exit 0 + ;; + + recovered) + echo "`date` ctdb recovered event" + exit 0 + ;; + + shutdown) + echo "`date` ctdb shutdown event" + exit 0 + ;; +esac + +echo "`/bin/date` Invalid command $cmd" +exit 1 diff --git a/source4/cluster/ctdb/tests/fetch.sh b/source4/cluster/ctdb/tests/fetch.sh new file mode 100755 index 0000000000..325957e63f --- /dev/null +++ b/source4/cluster/ctdb/tests/fetch.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +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 + +tests/start_daemons.sh $NUMNODES nodes.txt || exit 1 + + +killall -9 -q ctdb_fetch +for i in `seq 1 $NUMNODES`; do + $VALGRIND bin/ctdb_fetch --socket sock.$i -n $NUMNODES $* & +done +wait + +echo "Shutting down" +bin/ctdb shutdown -n all --socket=sock.1 +exit 0 diff --git a/source4/cluster/ctdb/tests/nodes.txt b/source4/cluster/ctdb/tests/nodes.txt new file mode 100644 index 0000000000..99b07328b3 --- /dev/null +++ b/source4/cluster/ctdb/tests/nodes.txt @@ -0,0 +1,4 @@ +127.0.0.1 +127.0.0.2 +127.0.0.3 +127.0.0.4 diff --git a/source4/cluster/ctdb/tests/public_addresses b/source4/cluster/ctdb/tests/public_addresses new file mode 100644 index 0000000000..97c85af7a8 --- /dev/null +++ b/source4/cluster/ctdb/tests/public_addresses @@ -0,0 +1,4 @@ +10.99.99.0/24 +10.99.99.1/24 +10.99.99.2/24 +10.99.99.3/24 diff --git a/source4/cluster/ctdb/tests/recover.sh b/source4/cluster/ctdb/tests/recover.sh new file mode 100755 index 0000000000..c626441786 --- /dev/null +++ b/source4/cluster/ctdb/tests/recover.sh @@ -0,0 +1,107 @@ +#!/bin/sh + +killall -q ctdbd + +echo "Starting 4 ctdb daemons" +bin/ctdbd --recovery-daemon --nlist tests/4nodes.txt +bin/ctdbd --recovery-daemon --nlist tests/4nodes.txt --listen=127.0.0.2 --socket=/tmp/ctdb.socket.127.0.0.2 +bin/ctdbd --recovery-daemon --nlist tests/4nodes.txt --listen=127.0.0.3 --socket=/tmp/ctdb.socket.127.0.0.3 +bin/ctdbd --recovery-daemon --nlist tests/4nodes.txt --listen=127.0.0.4 --socket=/tmp/ctdb.socket.127.0.0.4 + +echo +echo "Attaching to some databases" +bin/ctdb_control attach test1.tdb || exit 1 +bin/ctdb_control attach test2.tdb || exit 1 +bin/ctdb_control attach test3.tdb || exit 1 +bin/ctdb_control attach test4.tdb || exit 1 + +echo "Clearing all databases to make sure they are all empty" +bin/ctdb_control getdbmap 0 | egrep "^dbid:" | sed -e "s/^dbid://" -e "s/ .*$//" | while read DB; do + seq 0 3 | while read NODE; do + bin/ctdb_control cleardb $NODE $DB + done +done + + +echo +echo +echo "Printing all databases on all nodes. they should all be empty" +echo "=============================================================" +bin/ctdb_control getdbmap 0 | egrep "^dbid:" | sed -e "s/^.*name://" -e "s/ .*$//" | while read DBNAME; do + seq 0 3 | while read NODE; do + echo "Content of DBNAME:$DBNAME NODE:$NODE :" + bin/ctdb_control catdb $DBNAME $NODE + done +done + +echo +echo +echo "Populating the databases" +./bin/ctdb_control writerecord 0 0x220c2a7b testkey1 testdata1 +./bin/ctdb_control setdmaster 0 0x220c2a7b 1 + +./bin/ctdb_control writerecord 1 0x220c2a7b testkey1 testdata1 +./bin/ctdb_control writerecord 1 0x220c2a7b testkey1 testdata1 +./bin/ctdb_control setdmaster 1 0x220c2a7b 2 + +./bin/ctdb_control writerecord 2 0x220c2a7b testkey1 testdata1 +./bin/ctdb_control writerecord 2 0x220c2a7b testkey1 testdata1 +./bin/ctdb_control writerecord 2 0x220c2a7b testkey1 testdata1 +./bin/ctdb_control setdmaster 2 0x220c2a7b 3 + +./bin/ctdb_control writerecord 3 0x220c2a7b testkey1 testdata1 +./bin/ctdb_control writerecord 3 0x220c2a7b testkey1 testdata1 +./bin/ctdb_control writerecord 3 0x220c2a7b testkey1 testdata1 +./bin/ctdb_control writerecord 3 0x220c2a7b testkey1 testdata1 +./bin/ctdb_control setdmaster 3 0x220c2a7b 3 + + +echo +echo +echo "Printing all databases on all nodes. there should be a record there" +echo "=============================================================" +bin/ctdb_control getdbmap 0 | egrep "^dbid:" | sed -e "s/^.*name://" -e "s/ .*$//" | while read DBNAME; do + seq 0 3 | while read NODE; do + echo "Content of DBNAME:$DBNAME NODE:$NODE :" + bin/ctdb_control catdb $DBNAME $NODE + done +done + +echo +echo +echo "killing off node #2" +echo "===================" +CTDBPID=`./bin/ctdb_control getpid 2 | sed -e "s/Pid://"` +kill $CTDBPID +sleep 1 + + +echo +echo +echo "wait 3 seconds to let the recovery daemon do its job" +echo "====================================================" +sleep 3 + +echo +echo +echo "Printing all databases on all nodes." +echo "The databases should be the same now on all nodes" +echo "and the record will have been migrated to node 0" +echo "=================================================" +echo "Node 0:" +bin/ctdb_control catdb test4.tdb 0 +echo "Node 1:" +bin/ctdb_control catdb test4.tdb 1 +echo "Node 3:" +bin/ctdb_control catdb test4.tdb 3 +echo "nodemap:" +bin/ctdb_control getnodemap 0 + +echo +echo +echo "Traverse the cluster and dump the database" +bin/ctdb_control catdb test4.tdb + + +#leave the ctdb daemons running so one can look at the box in more detail +#killall -q ctdbd diff --git a/source4/cluster/ctdb/tests/run_tests.sh b/source4/cluster/ctdb/tests/run_tests.sh new file mode 100755 index 0000000000..356a9b21a0 --- /dev/null +++ b/source4/cluster/ctdb/tests/run_tests.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +tests/fetch.sh 4 || exit 1 +tests/bench.sh 4 || exit 1 +tests/ctdbd.sh || exit 1 + +echo "All OK" +exit 0 diff --git a/source4/cluster/ctdb/tests/start_daemons.sh b/source4/cluster/ctdb/tests/start_daemons.sh new file mode 100755 index 0000000000..d3c99d075a --- /dev/null +++ b/source4/cluster/ctdb/tests/start_daemons.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +NUMNODES="$1" +NODES=$2 +shift +shift + +killall -q ctdbd + +CTDB_OPTIONS="--reclock=rec.lock --nlist $NODES --event-script=tests/events --logfile=- --dbdir=test.db $*" +if [ `id -u` -eq 0 ]; then + CTDB_OPTIONS="$CTDB_OPTIONS --public-addresses=tests/public_addresses --public-interface=lo" +fi + +echo "Starting $NUMNODES ctdb daemons" +for i in `seq 1 $NUMNODES`; do + $VALGRIND bin/ctdbd --socket=sock.$i $CTDB_OPTIONS || exit 1 +done +ln -sf $PWD/sock.1 /tmp/ctdb.socket || exit 1 + +while bin/ctdb status | grep RECOVERY > /dev/null; do + echo "`date` Waiting for recovery" + sleep 1; +done + +echo "$NUMNODES daemons started" + +exit 0 |