From 734f3ada52e6ff21ca1f69dd16bc7969181c49e9 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 21 Nov 2008 19:01:48 +1100 Subject: Move tests/*.c to tests/src/*.c and adjust Makefile.in accordingly. Move setting of $CTDB_NODES_SOCKETS to tests/scripts/run_tests and make it only happen if $CTDB_TEST_REAL_CLUSTER is not set. Bugfix in function ips_are_on_nodeglob. New/proper implementations of functions stop_daemons and start_daemons, now called by function restart_ctdb. In start_daemons.sh, add public addresses file generation/usage, use new option --nopublicipcheck to ctdbd to avoid crazy behaviour and kill ctdbd more carefully to avoid killing real daemons on a real cluster - this should be able to coexist on a node of a real cluster. start_daemons.sh is temporarily incompatible with start_daemons function, but expecting to replace that script with function calls very soon anyway... Signed-off-by: Martin Schwenke (This used to be ctdb commit 4c54772c5c2fa7d2a25963379b5b96caf0c2521c) --- ctdb/.gitignore | 2 +- ctdb/Makefile.in | 32 +-- ctdb/tests/ctdb_bench.c | 229 -------------------- ctdb/tests/ctdb_fetch.c | 262 ---------------------- ctdb/tests/ctdb_persistent.c | 248 --------------------- ctdb/tests/ctdb_randrec.c | 155 ------------- ctdb/tests/ctdb_store.c | 159 -------------- ctdb/tests/ctdb_transaction.c | 258 ---------------------- ctdb/tests/ctdb_traverse.c | 114 ---------- ctdb/tests/rb_perftest.c | 123 ----------- ctdb/tests/rb_test.c | 323 ---------------------------- ctdb/tests/scripts/ctdb_test_functions.bash | 82 +++++-- ctdb/tests/scripts/run_tests | 18 +- ctdb/tests/simple/31_ctdb_disable_simple.sh | 2 + ctdb/tests/src/ctdb_bench.c | 229 ++++++++++++++++++++ ctdb/tests/src/ctdb_fetch.c | 262 ++++++++++++++++++++++ ctdb/tests/src/ctdb_persistent.c | 248 +++++++++++++++++++++ ctdb/tests/src/ctdb_randrec.c | 155 +++++++++++++ ctdb/tests/src/ctdb_store.c | 159 ++++++++++++++ ctdb/tests/src/ctdb_transaction.c | 258 ++++++++++++++++++++++ ctdb/tests/src/ctdb_traverse.c | 114 ++++++++++ ctdb/tests/src/rb_perftest.c | 123 +++++++++++ ctdb/tests/src/rb_test.c | 323 ++++++++++++++++++++++++++++ ctdb/tests/start_daemons.sh | 10 +- 24 files changed, 1973 insertions(+), 1915 deletions(-) delete mode 100644 ctdb/tests/ctdb_bench.c delete mode 100644 ctdb/tests/ctdb_fetch.c delete mode 100644 ctdb/tests/ctdb_persistent.c delete mode 100644 ctdb/tests/ctdb_randrec.c delete mode 100644 ctdb/tests/ctdb_store.c delete mode 100644 ctdb/tests/ctdb_transaction.c delete mode 100644 ctdb/tests/ctdb_traverse.c delete mode 100644 ctdb/tests/rb_perftest.c delete mode 100644 ctdb/tests/rb_test.c create mode 100644 ctdb/tests/src/ctdb_bench.c create mode 100644 ctdb/tests/src/ctdb_fetch.c create mode 100644 ctdb/tests/src/ctdb_persistent.c create mode 100644 ctdb/tests/src/ctdb_randrec.c create mode 100644 ctdb/tests/src/ctdb_store.c create mode 100644 ctdb/tests/src/ctdb_transaction.c create mode 100644 ctdb/tests/src/ctdb_traverse.c create mode 100644 ctdb/tests/src/rb_perftest.c create mode 100644 ctdb/tests/src/rb_test.c diff --git a/ctdb/.gitignore b/ctdb/.gitignore index 91124db066..b84c676909 100644 --- a/ctdb/.gitignore +++ b/ctdb/.gitignore @@ -18,4 +18,4 @@ nodes.txt public_addresses.txt rec.lock test.db -var +tests/var diff --git a/ctdb/Makefile.in b/ctdb/Makefile.in index 779bd8b4b0..212fa69b15 100755 --- a/ctdb/Makefile.in +++ b/ctdb/Makefile.in @@ -114,37 +114,37 @@ utils/smnotify/gen_smnotify.c: utils/smnotify/smnotify.x utils/smnotify/smnotify @echo Generating $@ rpcgen -l utils/smnotify/smnotify.x > utils/smnotify/gen_smnotify.c -bin/rb_test: $(CTDB_CLIENT_OBJ) tests/rb_test.o +bin/rb_test: $(CTDB_CLIENT_OBJ) tests/src/rb_test.o @echo Linking $@ - @$(CC) $(CFLAGS) -o $@ tests/rb_test.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) + @$(CC) $(CFLAGS) -o $@ tests/src/rb_test.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) -bin/ctdb_bench: $(CTDB_CLIENT_OBJ) tests/ctdb_bench.o +bin/ctdb_bench: $(CTDB_CLIENT_OBJ) tests/src/ctdb_bench.o @echo Linking $@ - @$(CC) $(CFLAGS) -o $@ tests/ctdb_bench.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) + @$(CC) $(CFLAGS) -o $@ tests/src/ctdb_bench.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) -bin/ctdb_fetch: $(CTDB_CLIENT_OBJ) tests/ctdb_fetch.o +bin/ctdb_fetch: $(CTDB_CLIENT_OBJ) tests/src/ctdb_fetch.o @echo Linking $@ - @$(CC) $(CFLAGS) -o $@ tests/ctdb_fetch.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) + @$(CC) $(CFLAGS) -o $@ tests/src/ctdb_fetch.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) -bin/ctdb_store: $(CTDB_CLIENT_OBJ) tests/ctdb_store.o +bin/ctdb_store: $(CTDB_CLIENT_OBJ) tests/src/ctdb_store.o @echo Linking $@ - @$(CC) $(CFLAGS) -o $@ tests/ctdb_store.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) + @$(CC) $(CFLAGS) -o $@ tests/src/ctdb_store.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) -bin/ctdb_traverse: $(CTDB_CLIENT_OBJ) tests/ctdb_traverse.o +bin/ctdb_traverse: $(CTDB_CLIENT_OBJ) tests/src/ctdb_traverse.o @echo Linking $@ - @$(CC) $(CFLAGS) -o $@ tests/ctdb_traverse.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) + @$(CC) $(CFLAGS) -o $@ tests/src/ctdb_traverse.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) -bin/ctdb_randrec: $(CTDB_CLIENT_OBJ) tests/ctdb_randrec.o +bin/ctdb_randrec: $(CTDB_CLIENT_OBJ) tests/src/ctdb_randrec.o @echo Linking $@ - @$(CC) $(CFLAGS) -o $@ tests/ctdb_randrec.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) + @$(CC) $(CFLAGS) -o $@ tests/src/ctdb_randrec.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) -bin/ctdb_persistent: $(CTDB_CLIENT_OBJ) tests/ctdb_persistent.o +bin/ctdb_persistent: $(CTDB_CLIENT_OBJ) tests/src/ctdb_persistent.o @echo Linking $@ - @$(CC) $(CFLAGS) -o $@ tests/ctdb_persistent.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) + @$(CC) $(CFLAGS) -o $@ tests/src/ctdb_persistent.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) -bin/ctdb_transaction: $(CTDB_CLIENT_OBJ) tests/ctdb_transaction.o +bin/ctdb_transaction: $(CTDB_CLIENT_OBJ) tests/src/ctdb_transaction.o @echo Linking $@ - @$(CC) $(CFLAGS) -o $@ tests/ctdb_transaction.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) + @$(CC) $(CFLAGS) -o $@ tests/src/ctdb_transaction.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) bin/ibwrapper_test: $(CTDB_CLIENT_OBJ) ib/ibwrapper_test.o @echo Linking $@ diff --git a/ctdb/tests/ctdb_bench.c b/ctdb/tests/ctdb_bench.c deleted file mode 100644 index 2d6b3ab298..0000000000 --- a/ctdb/tests/ctdb_bench.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - 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 . -*/ - -#include "includes.h" -#include "lib/events/events.h" -#include "system/filesys.h" -#include "popt.h" -#include "cmdline.h" - -#include -#include - -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_pnn(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 pnn=ctdb_get_pnn(ctdb); - - if (pnn == 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_pnn(ctdb) + incr) % num_nodes; - ctdb_send_message(ctdb, dest, 0, data); - - incr = -1; - dest = (ctdb_get_pnn(ctdb) + incr) % num_nodes; - ctdb_send_message(ctdb, dest, 0, data); - } - - start_timer(); - - while (end_timer() < timelimit) { - if (pnn == 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 = 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", false, 0); - 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, 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/ctdb/tests/ctdb_fetch.c b/ctdb/tests/ctdb_fetch.c deleted file mode 100644 index 2cc51d51bc..0000000000 --- a/ctdb/tests/ctdb_fetch.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - 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 . -*/ - -#include "includes.h" -#include "lib/events/events.h" -#include "system/filesys.h" -#include "popt.h" -#include "cmdline.h" - -#include -#include - -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_pnn(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_pnn(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_pnn(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 pnn=ctdb_get_pnn(ctdb); - - if (pnn == num_nodes - 1) { - bench_fetch_1node(ctdb); - } - - start_timer(); - - while (end_timer() < timelimit) { - if (pnn == 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 = 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", false, 0); - 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, 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/ctdb/tests/ctdb_persistent.c b/ctdb/tests/ctdb_persistent.c deleted file mode 100644 index 8f0452abad..0000000000 --- a/ctdb/tests/ctdb_persistent.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - simple tool to test persistent databases - - Copyright (C) Andrew Tridgell 2006-2007 - Copyright (c) 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 . -*/ - -#include "includes.h" -#include "lib/events/events.h" -#include "system/filesys.h" -#include "popt.h" -#include "cmdline.h" - -#include -#include - -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 unsigned int pnn; - -static TDB_DATA old_data; - -static int success = true; - -static void each_second(struct event_context *ev, struct timed_event *te, - struct timeval t, void *private_data) -{ - struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context); - int i; - uint32_t *old_counters; - - - printf("[%4u] Counters: ", getpid()); - old_counters = (uint32_t *)old_data.dptr; - for (i=0;i. -*/ - -#include "includes.h" -#include "lib/events/events.h" -#include "system/filesys.h" -#include "popt.h" -#include "cmdline.h" - -#include -#include - -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 num_records = 10; -static int delete_pct = 75; -static int base_rec; - -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=0; - - ctdb_db = ctdb_db_handle(ctdb, "test.tdb"); - - srandom(time(NULL) ^ getpid()); - - start_timer(); - - printf("working with %d records\n", num_records); - while (1) { - unsigned r = random() % num_records; - key.dptr = (uint8_t *)&r; - key.dsize = sizeof(r); - - 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_pnn(ctdb)); - talloc_free(tmp_ctx); - return; - } - - if (random() % 100 < delete_pct) { - data.dptr = NULL; - data.dsize = 0; - } else { - data.dptr = talloc_zero_size(h, data.dsize + sizeof(r)); - data.dsize += sizeof(r); - } - - ret = ctdb_record_store(h, data); - talloc_free(h); - if (ret != 0) { - printf("Failed to store record\n"); - } - if (i % 1000 == 0) { - printf("%7.0f recs/second %u total\r", 1000.0 / end_timer(), i); - fflush(stdout); - start_timer(); - } - i++; - } - - 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" }, - { "base-rec", 'b', POPT_ARG_INT, &base_rec, 0, "base_rec", "integer" }, - { "delete-pct", 'p', POPT_ARG_INT, &delete_pct, 0, "delete_pct", "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); - } - } - - /* 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); - - ctdb = ctdb_cmdline_client(ev); - - /* attach to a specific database */ - ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0); - if (!ctdb_db) { - printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb)); - exit(1); - } - - store_records(ctdb, ev); - - return 0; -} diff --git a/ctdb/tests/ctdb_store.c b/ctdb/tests/ctdb_store.c deleted file mode 100644 index ce4195c65f..0000000000 --- a/ctdb/tests/ctdb_store.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - 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 . -*/ - -#include "includes.h" -#include "lib/events/events.h" -#include "system/filesys.h" -#include "popt.h" -#include "cmdline.h" - -#include -#include - -static int num_records = 10; -static int base_rec; - -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. -*/ - -#include "includes.h" -#include "lib/events/events.h" -#include "system/filesys.h" -#include "popt.h" -#include "cmdline.h" - -#include -#include - -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 unsigned int pnn; - -static TDB_DATA old_data; - -static int success = true; - -static void each_second(struct event_context *ev, struct timed_event *te, - struct timeval t, void *private_data) -{ - struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context); - int i; - uint32_t *old_counters; - - - printf("[%4u] Counters: ", getpid()); - old_counters = (uint32_t *)old_data.dptr; - for (i=0;i. -*/ - -#include "includes.h" -#include "lib/events/events.h" -#include "system/filesys.h" -#include "popt.h" -#include "cmdline.h" - -#include -#include - -static const char *dbname = "test.tdb"; - -static int traverse_callback(struct ctdb_context *ctdb, TDB_DATA key, TDB_DATA data, void *private_data) -{ - uint32_t *count = private_data; - - (*count)++; - return 0; -} - -static void traverse_loop(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db, struct event_context *ev) -{ - uint32_t count; - - printf("traversing database\n"); - count = 0; - ctdb_traverse(ctdb_db, traverse_callback, &count); - printf("traversed %d records\n", count); -} - -/* - 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 - { "database", 0, POPT_ARG_STRING, &dbname, 0, "database to traverse", "name" }, - 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 = event_context_init(NULL); - - ctdb = ctdb_cmdline_client(ev); - - /* attach to a specific database */ - ctdb_db = ctdb_attach(ctdb, dbname, false, 0); - 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, ctdb, timeval_zero(), CTDB_CURRENT_NODE, &recmode); - if (recmode == 0) break; - event_loop_once(ev); - } - - while (1) { - traverse_loop(ctdb, ctdb_db, ev); - } - - return 0; -} diff --git a/ctdb/tests/rb_perftest.c b/ctdb/tests/rb_perftest.c deleted file mode 100644 index 1760cd1149..0000000000 --- a/ctdb/tests/rb_perftest.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - simple rb vs dlist benchmark - - Copyright (C) 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 . -*/ - -#include "includes.h" -#include "lib/events/events.h" -#include "lib/util/dlinklist.h" -#include "system/filesys.h" -#include "popt.h" -#include "cmdline.h" - -#include -#include -#include "common/rb_tree.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 num_records = 1000; - - -struct list_node { - struct list_node *prev, *next; -}; - -/* - main program -*/ -int main(int argc, const char *argv[]) -{ - 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; - int ret; - poptContext pc; - struct event_context *ev; - double elapsed; - int i; - trbt_tree_t *tree; - struct list_node *list, *list_new, *list_head=NULL; - - 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); - - - printf("testing tree insert for %d records\n", num_records); - tree = trbt_create(NULL); - start_timer(); - for (i=0;inext;list=list->next) { - /* the events code does a timeval_compare */ - timeval_compare(&tp1, &tp2); - } - - list_new=talloc(NULL, struct list_node); - DLIST_ADD_AFTER(list_head, list_new, list); - } - elapsed=end_timer(); - printf("%f seconds\n",(float)elapsed); - - return 0; -} diff --git a/ctdb/tests/rb_test.c b/ctdb/tests/rb_test.c deleted file mode 100644 index 553a0f6c48..0000000000 --- a/ctdb/tests/rb_test.c +++ /dev/null @@ -1,323 +0,0 @@ -/* - simple rb test tool - - Copyright (C) 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 . -*/ - -#include "includes.h" -#include "lib/events/events.h" -#include "lib/util/dlinklist.h" -#include "system/filesys.h" -#include "popt.h" -#include "cmdline.h" - -#include -#include -#include "common/rb_tree.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)); -} - -int num_records=5; - -void *callback(void *p, void *d) -{ - uint32_t *data = (uint32_t *)d; - - if (d==NULL) { - data = (uint32_t *)p; - } - - (*data)++; - - return data; -} - -void *random_add(void *p, void *d) -{ - return p; -} - -void traverse(void *p, void *d) -{ - uint32_t *data = (uint32_t *)d; - - printf("traverse data:%d\n",*data); -} - -void random_traverse(void *p, void *d) -{ - printf("%s ",(char *)d); -} - -static uint32_t calc_checksum = 0; -void traverse_checksum(void *p, void *d) -{ - int i,j,k; - - sscanf(d, "%d.%d.%d", &i, &j, &k); - calc_checksum += i*100+j*10+k; -} - -/* - main program -*/ -int main(int argc, const char *argv[]) -{ - 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; - int i,j,k; - trbt_tree_t *tree; - uint32_t *data; - uint32_t key[3]; - uint32_t key1[3] = {0,10,20}; - uint32_t key2[3] = {0,10,21}; - uint32_t key3[3] = {0,11,20}; - uint32_t key4[3] = {2,10,20}; - TALLOC_CTX *memctx; - uint32_t **u32array; - uint32_t checksum; - - 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); - - - printf("testing trbt_insert32_callback for %d records\n", num_records); - memctx = talloc_new(NULL); - u32array = talloc_array(memctx, uint32_t *, num_records); - tree = trbt_create(memctx, 0); - for (i=0; i/dev/null ; then + echo "Killing remaining daemons..." + killall $CTDB_DIR/bin/ctdbd + + if pidof $CTDB_DIR/bin/ctdbd >/dev/null ; then + echo "Once more with feeling.." + killall -9 $CTDB_DIR/bin/ctdbd + fi + fi + + var_dir=$CTDB_DIR/tests/var + rm -rf $var_dir/test.db +} start_daemons () { - $CTDB_DIR/tests/start_daemons.sh $numnodes >$CTDB_DIR/var/daemons.log + local num_nodes="${1:-2}" # default is 2 nodes + shift # "$@" gets passed to ctdbd + + local var_dir=$CTDB_DIR/tests/var + + mkdir -p $var_dir/test.db/persistent + + local nodes=$var_dir/nodes.txt + local public_addresses=$var_dir/public_addresses.txt + rm -f $nodes $public_addresses + + local i + for i in $(seq 1 $num_nodes) ; do + if [ "${CTDB_USE_IPV6}x" != "x" ]; then + echo ::$i >> $nodes + ip addr add ::$i/128 dev lo + else + echo 127.0.0.$i >> $nodes + # 2 public addresses per node, just to make things interesting. + echo "192.0.2.$i/24 lo" >> $public_addresses + echo "192.0.2.$(($i + $num_nodes))/24 lo" >> $public_addresses + fi + done + + local ctdb_options="--reclock=$var_dir/rec.lock --nlist $nodes --public-addresses $public_addresses --nopublicipcheck --event-script-dir=tests/events.d --logfile=$var_dir/daemons.log -d 0 --dbdir=$var_dir/test.db --dbdir-persistent=$var_dir/test.db/persistent" + + echo "Starting $num_nodes ctdb daemons..." + for i in $(seq 1 $num_nodes) ; do + if [ $(id -u) -eq 0 ]; then + ctdb_options="$ctdb_options --public-interface=lo" + fi + + $VALGRIND bin/ctdbd --socket=$var_dir/sock.$i $ctdb_options "$@" || return 1 + done + + if [ -L /tmp/ctdb.socket -o ! -S /tmp/ctdb.socket ] ; then + ln -sf $var_dir/sock.1 /tmp/ctdb.socket || return 1 + fi } _restart_ctdb () @@ -301,8 +349,8 @@ _restart_ctdb () restart_ctdb () { if [ -n "$CTDB_NODES_SOCKETS" ] ; then - onnode all ctdb shutdown - start_daemons + stop_daemons + start_daemons $CTDB_NUM_NODES else onnode -pq all $TEST_WRAP _restart_ctdb fi || return 1 @@ -327,7 +375,3 @@ ctdb_test_exit () test_exit } - -######################################## - -export PATH=/usr/local/autocluster:$PATH diff --git a/ctdb/tests/scripts/run_tests b/ctdb/tests/scripts/run_tests index eab28f06ea..9827ebed63 100755 --- a/ctdb/tests/scripts/run_tests +++ b/ctdb/tests/scripts/run_tests @@ -1,9 +1,23 @@ #!/bin/bash export CTDB_DIR=$(cd $(dirname $(dirname $(dirname $0))) ; pwd) +var_dir=$CTDB_DIR/tests/var -ctdb_bin_dir="${CTDB_DIR}/bin" -ctdb_tools_dir="${CTDB_DIR}/tools" +export CTDB_NUM_NODES=3 + +###################################################################### + +if [ ! -n "$CTDB_TEST_REAL_CLUSTER" ] ; then + export CTDB_NODES_SOCKETS="" + for i in $(seq 1 $CTDB_NUM_NODES) ; do + CTDB_NODES_SOCKETS="${CTDB_NODES_SOCKETS}${CTDB_NODES_SOCKETS:+ }${var_dir}/sock.${i}" + done +fi + +###################################################################### + +ctdb_bin_dir=$CTDB_DIR/bin +ctdb_tools_dir=$CTDB_DIR/tools ctdb_test_scripts_dir=$(cd $(dirname $0) ; pwd) PATH="${ctdb_test_scripts_dir}:${ctdb_bin_dir}:${ctdb_tools_dir}:${PATH}" diff --git a/ctdb/tests/simple/31_ctdb_disable_simple.sh b/ctdb/tests/simple/31_ctdb_disable_simple.sh index fdb7daed87..f49af88396 100755 --- a/ctdb/tests/simple/31_ctdb_disable_simple.sh +++ b/ctdb/tests/simple/31_ctdb_disable_simple.sh @@ -36,4 +36,6 @@ else testfailures=1 fi +echo "Expect a restart here..." + ctdb_test_exit diff --git a/ctdb/tests/src/ctdb_bench.c b/ctdb/tests/src/ctdb_bench.c new file mode 100644 index 0000000000..2d6b3ab298 --- /dev/null +++ b/ctdb/tests/src/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 . +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "system/filesys.h" +#include "popt.h" +#include "cmdline.h" + +#include +#include + +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_pnn(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 pnn=ctdb_get_pnn(ctdb); + + if (pnn == 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_pnn(ctdb) + incr) % num_nodes; + ctdb_send_message(ctdb, dest, 0, data); + + incr = -1; + dest = (ctdb_get_pnn(ctdb) + incr) % num_nodes; + ctdb_send_message(ctdb, dest, 0, data); + } + + start_timer(); + + while (end_timer() < timelimit) { + if (pnn == 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 = 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", false, 0); + 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, 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/ctdb/tests/src/ctdb_fetch.c b/ctdb/tests/src/ctdb_fetch.c new file mode 100644 index 0000000000..2cc51d51bc --- /dev/null +++ b/ctdb/tests/src/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 . +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "system/filesys.h" +#include "popt.h" +#include "cmdline.h" + +#include +#include + +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_pnn(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_pnn(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_pnn(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 pnn=ctdb_get_pnn(ctdb); + + if (pnn == num_nodes - 1) { + bench_fetch_1node(ctdb); + } + + start_timer(); + + while (end_timer() < timelimit) { + if (pnn == 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 = 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", false, 0); + 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, 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/ctdb/tests/src/ctdb_persistent.c b/ctdb/tests/src/ctdb_persistent.c new file mode 100644 index 0000000000..8f0452abad --- /dev/null +++ b/ctdb/tests/src/ctdb_persistent.c @@ -0,0 +1,248 @@ +/* + simple tool to test persistent databases + + Copyright (C) Andrew Tridgell 2006-2007 + Copyright (c) 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 . +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "system/filesys.h" +#include "popt.h" +#include "cmdline.h" + +#include +#include + +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 unsigned int pnn; + +static TDB_DATA old_data; + +static int success = true; + +static void each_second(struct event_context *ev, struct timed_event *te, + struct timeval t, void *private_data) +{ + struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context); + int i; + uint32_t *old_counters; + + + printf("[%4u] Counters: ", getpid()); + old_counters = (uint32_t *)old_data.dptr; + for (i=0;i. +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "system/filesys.h" +#include "popt.h" +#include "cmdline.h" + +#include +#include + +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 num_records = 10; +static int delete_pct = 75; +static int base_rec; + +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=0; + + ctdb_db = ctdb_db_handle(ctdb, "test.tdb"); + + srandom(time(NULL) ^ getpid()); + + start_timer(); + + printf("working with %d records\n", num_records); + while (1) { + unsigned r = random() % num_records; + key.dptr = (uint8_t *)&r; + key.dsize = sizeof(r); + + 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_pnn(ctdb)); + talloc_free(tmp_ctx); + return; + } + + if (random() % 100 < delete_pct) { + data.dptr = NULL; + data.dsize = 0; + } else { + data.dptr = talloc_zero_size(h, data.dsize + sizeof(r)); + data.dsize += sizeof(r); + } + + ret = ctdb_record_store(h, data); + talloc_free(h); + if (ret != 0) { + printf("Failed to store record\n"); + } + if (i % 1000 == 0) { + printf("%7.0f recs/second %u total\r", 1000.0 / end_timer(), i); + fflush(stdout); + start_timer(); + } + i++; + } + + 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" }, + { "base-rec", 'b', POPT_ARG_INT, &base_rec, 0, "base_rec", "integer" }, + { "delete-pct", 'p', POPT_ARG_INT, &delete_pct, 0, "delete_pct", "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); + } + } + + /* 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); + + ctdb = ctdb_cmdline_client(ev); + + /* attach to a specific database */ + ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0); + if (!ctdb_db) { + printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb)); + exit(1); + } + + store_records(ctdb, ev); + + return 0; +} diff --git a/ctdb/tests/src/ctdb_store.c b/ctdb/tests/src/ctdb_store.c new file mode 100644 index 0000000000..ce4195c65f --- /dev/null +++ b/ctdb/tests/src/ctdb_store.c @@ -0,0 +1,159 @@ +/* + 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 . +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "system/filesys.h" +#include "popt.h" +#include "cmdline.h" + +#include +#include + +static int num_records = 10; +static int base_rec; + +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. +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "system/filesys.h" +#include "popt.h" +#include "cmdline.h" + +#include +#include + +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 unsigned int pnn; + +static TDB_DATA old_data; + +static int success = true; + +static void each_second(struct event_context *ev, struct timed_event *te, + struct timeval t, void *private_data) +{ + struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context); + int i; + uint32_t *old_counters; + + + printf("[%4u] Counters: ", getpid()); + old_counters = (uint32_t *)old_data.dptr; + for (i=0;i. +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "system/filesys.h" +#include "popt.h" +#include "cmdline.h" + +#include +#include + +static const char *dbname = "test.tdb"; + +static int traverse_callback(struct ctdb_context *ctdb, TDB_DATA key, TDB_DATA data, void *private_data) +{ + uint32_t *count = private_data; + + (*count)++; + return 0; +} + +static void traverse_loop(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db, struct event_context *ev) +{ + uint32_t count; + + printf("traversing database\n"); + count = 0; + ctdb_traverse(ctdb_db, traverse_callback, &count); + printf("traversed %d records\n", count); +} + +/* + 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 + { "database", 0, POPT_ARG_STRING, &dbname, 0, "database to traverse", "name" }, + 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 = event_context_init(NULL); + + ctdb = ctdb_cmdline_client(ev); + + /* attach to a specific database */ + ctdb_db = ctdb_attach(ctdb, dbname, false, 0); + 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, ctdb, timeval_zero(), CTDB_CURRENT_NODE, &recmode); + if (recmode == 0) break; + event_loop_once(ev); + } + + while (1) { + traverse_loop(ctdb, ctdb_db, ev); + } + + return 0; +} diff --git a/ctdb/tests/src/rb_perftest.c b/ctdb/tests/src/rb_perftest.c new file mode 100644 index 0000000000..1760cd1149 --- /dev/null +++ b/ctdb/tests/src/rb_perftest.c @@ -0,0 +1,123 @@ +/* + simple rb vs dlist benchmark + + Copyright (C) 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 . +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "lib/util/dlinklist.h" +#include "system/filesys.h" +#include "popt.h" +#include "cmdline.h" + +#include +#include +#include "common/rb_tree.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 num_records = 1000; + + +struct list_node { + struct list_node *prev, *next; +}; + +/* + main program +*/ +int main(int argc, const char *argv[]) +{ + 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; + int ret; + poptContext pc; + struct event_context *ev; + double elapsed; + int i; + trbt_tree_t *tree; + struct list_node *list, *list_new, *list_head=NULL; + + 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); + + + printf("testing tree insert for %d records\n", num_records); + tree = trbt_create(NULL); + start_timer(); + for (i=0;inext;list=list->next) { + /* the events code does a timeval_compare */ + timeval_compare(&tp1, &tp2); + } + + list_new=talloc(NULL, struct list_node); + DLIST_ADD_AFTER(list_head, list_new, list); + } + elapsed=end_timer(); + printf("%f seconds\n",(float)elapsed); + + return 0; +} diff --git a/ctdb/tests/src/rb_test.c b/ctdb/tests/src/rb_test.c new file mode 100644 index 0000000000..553a0f6c48 --- /dev/null +++ b/ctdb/tests/src/rb_test.c @@ -0,0 +1,323 @@ +/* + simple rb test tool + + Copyright (C) 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 . +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "lib/util/dlinklist.h" +#include "system/filesys.h" +#include "popt.h" +#include "cmdline.h" + +#include +#include +#include "common/rb_tree.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)); +} + +int num_records=5; + +void *callback(void *p, void *d) +{ + uint32_t *data = (uint32_t *)d; + + if (d==NULL) { + data = (uint32_t *)p; + } + + (*data)++; + + return data; +} + +void *random_add(void *p, void *d) +{ + return p; +} + +void traverse(void *p, void *d) +{ + uint32_t *data = (uint32_t *)d; + + printf("traverse data:%d\n",*data); +} + +void random_traverse(void *p, void *d) +{ + printf("%s ",(char *)d); +} + +static uint32_t calc_checksum = 0; +void traverse_checksum(void *p, void *d) +{ + int i,j,k; + + sscanf(d, "%d.%d.%d", &i, &j, &k); + calc_checksum += i*100+j*10+k; +} + +/* + main program +*/ +int main(int argc, const char *argv[]) +{ + 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; + int i,j,k; + trbt_tree_t *tree; + uint32_t *data; + uint32_t key[3]; + uint32_t key1[3] = {0,10,20}; + uint32_t key2[3] = {0,10,21}; + uint32_t key3[3] = {0,11,20}; + uint32_t key4[3] = {2,10,20}; + TALLOC_CTX *memctx; + uint32_t **u32array; + uint32_t checksum; + + 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); + + + printf("testing trbt_insert32_callback for %d records\n", num_records); + memctx = talloc_new(NULL); + u32array = talloc_array(memctx, uint32_t *, num_records); + tree = trbt_create(memctx, 0); + for (i=0; i> $NODES ip addr add ::$i/128 dev lo else echo 127.0.0.$i >> $NODES - #echo "127.0.1.$i/24 lo" >> $PUBLIC_ADDRESSES - #echo "127.0.1.$(($i + $NUMNODES))/24 lo" >> $PUBLIC_ADDRESSES + # 2 public addresses per node, just to make things interesting. echo "192.0.2.$i/24 lo" >> $PUBLIC_ADDRESSES echo "192.0.2.$(($i + $NUMNODES))/24 lo" >> $PUBLIC_ADDRESSES fi done -killall -q ctdbd +killall -q $PWD/bin/ctdbd rm -rf test.db/persistent/* -CTDB_OPTIONS="--reclock=rec.lock --nlist $NODES --public-addresses $PUBLIC_ADDRESSES --event-script-dir=tests/events.d --logfile=- -d 0 --dbdir=test.db --dbdir-persistent=test.db/persistent $*" +CTDB_OPTIONS="--reclock=rec.lock --nlist $NODES --public-addresses $PUBLIC_ADDRESSES --nopublicipcheck --event-script-dir=tests/events.d --logfile=- -d 0 --dbdir=test.db --dbdir-persistent=test.db/persistent $*" echo "Starting $NUMNODES ctdb daemons" for i in `seq 1 $NUMNODES`; do -- cgit