From 1b02e88aaf193179d2b1bd30e5ea07bf965bd853 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 7 Apr 2007 00:03:09 +0000 Subject: r22114: merge from bzr tree (This used to be commit e60a485ff5c5d8deb7c0aea5e49d0c1d0ea4fa37) --- source4/cluster/ctdb/tests/ctdb_fetch.c | 286 ++++++++++++++++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 source4/cluster/ctdb/tests/ctdb_fetch.c (limited to 'source4/cluster/ctdb/tests/ctdb_fetch.c') diff --git a/source4/cluster/ctdb/tests/ctdb_fetch.c b/source4/cluster/ctdb/tests/ctdb_fetch.c new file mode 100644 index 0000000000..c0491e9bb5 --- /dev/null +++ b/source4/cluster/ctdb/tests/ctdb_fetch.c @@ -0,0 +1,286 @@ +/* + simple ctdb benchmark + + Copyright (C) Andrew Tridgell 2006 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "system/filesys.h" +#include "popt.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_msgs = 1; + +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_record_handle *rec; + struct ctdb_db_context *ctdb_db; + TALLOC_CTX *tmp_ctx = talloc_new(ctdb); + int dest, ret; + + key.dptr = discard_const("testkey"); + key.dsize = strlen((const char *)key.dptr); + + ctdb_db = ctdb_db_handle(ctdb, "test.tdb"); + + rec = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data); + if (rec == 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(rec, data); + 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) % ctdb_get_num_nodes(ctdb); + ctdb_send_message(ctdb, dest, 0, nulldata); +} + +/* + handler for messages in bench_ring() +*/ +static void message_handler(struct ctdb_context *ctdb, uint32_t srvid, + TDB_DATA data, void *private) +{ + 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 == ctdb_get_num_nodes(ctdb)-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; +} + +/* + main program +*/ +int main(int argc, const char *argv[]) +{ + struct ctdb_context *ctdb; + struct ctdb_db_context *ctdb_db; + const char *nlist = NULL; + const char *transport = "tcp"; + const char *myaddress = NULL; + int self_connect=0; + + struct poptOption popt_options[] = { + POPT_AUTOHELP + { "nlist", 0, POPT_ARG_STRING, &nlist, 0, "node list file", "filename" }, + { "listen", 0, POPT_ARG_STRING, &myaddress, 0, "address to listen on", "address" }, + { "transport", 0, POPT_ARG_STRING, &transport, 0, "protocol transport", NULL }, + { "self-connect", 0, POPT_ARG_NONE, &self_connect, 0, "enable self connect", "boolean" }, + { "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" }, + POPT_TABLEEND + }; + int opt; + const char **extra_argv; + int extra_argc = 0; + int ret; + poptContext pc; + struct event_context *ev; + struct ctdb_call call; + + 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++; + } + + if (nlist == NULL || myaddress == NULL) { + printf("You must provide a node list with --nlist and an address with --listen\n"); + exit(1); + } + + ev = event_context_init(NULL); + + /* initialise ctdb */ + ctdb = ctdb_init(ev); + if (ctdb == NULL) { + printf("Failed to init ctdb\n"); + exit(1); + } + + if (self_connect) { + ctdb_set_flags(ctdb, CTDB_FLAG_SELF_CONNECT); + } + + ret = ctdb_set_transport(ctdb, transport); + if (ret == -1) { + printf("ctdb_set_transport failed - %s\n", ctdb_errstr(ctdb)); + exit(1); + } + + /* tell ctdb what address to listen on */ + ret = ctdb_set_address(ctdb, myaddress); + if (ret == -1) { + printf("ctdb_set_address failed - %s\n", ctdb_errstr(ctdb)); + exit(1); + } + + /* tell ctdb what nodes are available */ + ret = ctdb_set_nlist(ctdb, nlist); + if (ret == -1) { + printf("ctdb_set_nlist failed - %s\n", ctdb_errstr(ctdb)); + exit(1); + } + + /* attach to a specific database */ + ctdb_db = ctdb_attach(ctdb, "test.tdb", TDB_DEFAULT, O_RDWR|O_CREAT|O_TRUNC, 0666); + 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, message_handler, &msg_count); + + /* start the protocol running */ + ret = ctdb_start(ctdb); + + /* wait until all nodes are connected (should not be needed + outside of test code) */ + ctdb_connect_wait(ctdb); + + bench_fetch(ctdb, ev); + + ZERO_STRUCT(call); + call.key.dptr = discard_const(TESTKEY); + call.key.dsize = strlen(TESTKEY); + + /* 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); + + /* shut it down */ + talloc_free(ctdb); + return 0; +} -- cgit From c9f04d8648cfdd573d45d47467bc964ef01f754d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 16 Apr 2007 00:18:54 +0000 Subject: r22231: merge from bzr ctdb tree (This used to be commit 807b959082d3b9a929c9f6597714e636638a940e) --- source4/cluster/ctdb/tests/ctdb_fetch.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source4/cluster/ctdb/tests/ctdb_fetch.c') diff --git a/source4/cluster/ctdb/tests/ctdb_fetch.c b/source4/cluster/ctdb/tests/ctdb_fetch.c index c0491e9bb5..45e5248980 100644 --- a/source4/cluster/ctdb/tests/ctdb_fetch.c +++ b/source4/cluster/ctdb/tests/ctdb_fetch.c @@ -87,7 +87,7 @@ static void bench_fetch_1node(struct ctdb_context *ctdb) msg_count, ctdb_get_vnn(ctdb)); data.dsize = strlen((const char *)data.dptr)+1; - ret = ctdb_record_store(rec, data); + ret = ctdb_store_unlock(rec, data); if (ret != 0) { printf("Failed to store record\n"); } @@ -106,7 +106,7 @@ static void bench_fetch_1node(struct ctdb_context *ctdb) handler for messages in bench_ring() */ static void message_handler(struct ctdb_context *ctdb, uint32_t srvid, - TDB_DATA data, void *private) + TDB_DATA data, void *private_data) { msg_count++; bench_fetch_1node(ctdb); @@ -167,6 +167,7 @@ int main(int argc, const char *argv[]) const char *transport = "tcp"; const char *myaddress = NULL; int self_connect=0; + int daemon_mode=0; struct poptOption popt_options[] = { POPT_AUTOHELP @@ -174,6 +175,7 @@ int main(int argc, const char *argv[]) { "listen", 0, POPT_ARG_STRING, &myaddress, 0, "address to listen on", "address" }, { "transport", 0, POPT_ARG_STRING, &transport, 0, "protocol transport", NULL }, { "self-connect", 0, POPT_ARG_NONE, &self_connect, 0, "enable self connect", "boolean" }, + { "daemon", 0, POPT_ARG_NONE, &daemon_mode, 0, "spawn a ctdb daemon", "boolean" }, { "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" }, @@ -222,6 +224,9 @@ int main(int argc, const char *argv[]) if (self_connect) { ctdb_set_flags(ctdb, CTDB_FLAG_SELF_CONNECT); } + if (daemon_mode) { + ctdb_set_flags(ctdb, CTDB_FLAG_DAEMON_MODE); + } ret = ctdb_set_transport(ctdb, transport); if (ret == -1) { @@ -252,11 +257,11 @@ int main(int argc, const char *argv[]) ret = ctdb_set_call(ctdb_db, fetch_func, FUNC_FETCH); - ctdb_set_message_handler(ctdb, message_handler, &msg_count); - /* start the protocol running */ ret = ctdb_start(ctdb); + 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); -- cgit From e24cf892883b54a567f294eacbd94a23d7d420e4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 16 Apr 2007 04:47:11 +0000 Subject: r22234: merge test suite changes from bzr tree (This used to be commit d825f4e6cc96a365061805352a2df3818df2364e) --- source4/cluster/ctdb/tests/ctdb_fetch.c | 51 ++------------------------------- 1 file changed, 3 insertions(+), 48 deletions(-) (limited to 'source4/cluster/ctdb/tests/ctdb_fetch.c') diff --git a/source4/cluster/ctdb/tests/ctdb_fetch.c b/source4/cluster/ctdb/tests/ctdb_fetch.c index 45e5248980..febaf13fe4 100644 --- a/source4/cluster/ctdb/tests/ctdb_fetch.c +++ b/source4/cluster/ctdb/tests/ctdb_fetch.c @@ -22,6 +22,7 @@ #include "lib/events/events.h" #include "system/filesys.h" #include "popt.h" +#include "tests/cmdline.h" #include #include @@ -163,19 +164,10 @@ int main(int argc, const char *argv[]) { struct ctdb_context *ctdb; struct ctdb_db_context *ctdb_db; - const char *nlist = NULL; - const char *transport = "tcp"; - const char *myaddress = NULL; - int self_connect=0; - int daemon_mode=0; struct poptOption popt_options[] = { POPT_AUTOHELP - { "nlist", 0, POPT_ARG_STRING, &nlist, 0, "node list file", "filename" }, - { "listen", 0, POPT_ARG_STRING, &myaddress, 0, "address to listen on", "address" }, - { "transport", 0, POPT_ARG_STRING, &transport, 0, "protocol transport", NULL }, - { "self-connect", 0, POPT_ARG_NONE, &self_connect, 0, "enable self connect", "boolean" }, - { "daemon", 0, POPT_ARG_NONE, &daemon_mode, 0, "spawn a ctdb daemon", "boolean" }, + 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" }, @@ -207,46 +199,9 @@ int main(int argc, const char *argv[]) while (extra_argv[extra_argc]) extra_argc++; } - if (nlist == NULL || myaddress == NULL) { - printf("You must provide a node list with --nlist and an address with --listen\n"); - exit(1); - } - ev = event_context_init(NULL); - /* initialise ctdb */ - ctdb = ctdb_init(ev); - if (ctdb == NULL) { - printf("Failed to init ctdb\n"); - exit(1); - } - - if (self_connect) { - ctdb_set_flags(ctdb, CTDB_FLAG_SELF_CONNECT); - } - if (daemon_mode) { - ctdb_set_flags(ctdb, CTDB_FLAG_DAEMON_MODE); - } - - ret = ctdb_set_transport(ctdb, transport); - if (ret == -1) { - printf("ctdb_set_transport failed - %s\n", ctdb_errstr(ctdb)); - exit(1); - } - - /* tell ctdb what address to listen on */ - ret = ctdb_set_address(ctdb, myaddress); - if (ret == -1) { - printf("ctdb_set_address failed - %s\n", ctdb_errstr(ctdb)); - exit(1); - } - - /* tell ctdb what nodes are available */ - ret = ctdb_set_nlist(ctdb, nlist); - if (ret == -1) { - printf("ctdb_set_nlist failed - %s\n", ctdb_errstr(ctdb)); - exit(1); - } + ctdb = ctdb_cmdline_init(ev); /* attach to a specific database */ ctdb_db = ctdb_attach(ctdb, "test.tdb", TDB_DEFAULT, O_RDWR|O_CREAT|O_TRUNC, 0666); -- cgit From 650d81b252cc669ef848448afad7e9bb79c4f20e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 21 Apr 2007 07:23:42 +0000 Subject: r22421: merged in latest ctdb changes from bzr (This used to be commit 3633f862b966866819c9a0a6ad0238a858e15e62) --- source4/cluster/ctdb/tests/ctdb_fetch.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'source4/cluster/ctdb/tests/ctdb_fetch.c') diff --git a/source4/cluster/ctdb/tests/ctdb_fetch.c b/source4/cluster/ctdb/tests/ctdb_fetch.c index febaf13fe4..39bd861fc1 100644 --- a/source4/cluster/ctdb/tests/ctdb_fetch.c +++ b/source4/cluster/ctdb/tests/ctdb_fetch.c @@ -22,7 +22,7 @@ #include "lib/events/events.h" #include "system/filesys.h" #include "popt.h" -#include "tests/cmdline.h" +#include "cmdline.h" #include #include @@ -58,18 +58,18 @@ static int msg_count; static void bench_fetch_1node(struct ctdb_context *ctdb) { TDB_DATA key, data, nulldata; - struct ctdb_record_handle *rec; 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((const char *)key.dptr); + key.dptr = discard_const(TESTKEY); + key.dsize = strlen(TESTKEY); ctdb_db = ctdb_db_handle(ctdb, "test.tdb"); - rec = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data); - if (rec == NULL) { + 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); @@ -88,7 +88,8 @@ static void bench_fetch_1node(struct ctdb_context *ctdb) msg_count, ctdb_get_vnn(ctdb)); data.dsize = strlen((const char *)data.dptr)+1; - ret = ctdb_store_unlock(rec, data); + ret = ctdb_record_store(h, data); + talloc_free(h); if (ret != 0) { printf("Failed to store record\n"); } @@ -141,6 +142,10 @@ static void bench_fetch(struct ctdb_context *ctdb, struct event_context *ev) printf("Event loop failed!\n"); break; } + + if (LogLevel > 9) { + talloc_report_null_full(); + } } printf("Fetch: %.2f msgs/sec\n", msg_count/end_timer()); @@ -192,6 +197,8 @@ int main(int argc, const char *argv[]) } } + /* talloc_enable_leak_report_full(); */ + /* setup the remaining options for the main program to use */ extra_argv = poptGetArgs(pc); if (extra_argv) { @@ -240,7 +247,8 @@ int main(int argc, const char *argv[]) printf("DATA:\n%s\n", (char *)call.reply_data.dptr); - /* shut it down */ - talloc_free(ctdb); + /* go into a wait loop to allow other nodes to complete */ + ctdb_shutdown(ctdb); + return 0; } -- cgit From b8d69a7ea2505b706ff7c74d7c97bc89d82dfa07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:46:15 +0000 Subject: r23795: more v2->v3 conversion (This used to be commit 84b468b2f8f2dffda89593f816e8bc6a8b6d42ac) --- source4/cluster/ctdb/tests/ctdb_fetch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/cluster/ctdb/tests/ctdb_fetch.c') diff --git a/source4/cluster/ctdb/tests/ctdb_fetch.c b/source4/cluster/ctdb/tests/ctdb_fetch.c index 39bd861fc1..61af4c3a79 100644 --- a/source4/cluster/ctdb/tests/ctdb_fetch.c +++ b/source4/cluster/ctdb/tests/ctdb_fetch.c @@ -6,7 +6,7 @@ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- cgit From 6c973f4e8ccbcb6c9275f8a54e26abb19df7e15a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 03:42:26 +0000 Subject: r23798: updated old Temple Place FSF addresses to new URL (This used to be commit 40c0919aaa9c1b14bbaebb95ecce53eb0380fdbb) --- source4/cluster/ctdb/tests/ctdb_fetch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/cluster/ctdb/tests/ctdb_fetch.c') diff --git a/source4/cluster/ctdb/tests/ctdb_fetch.c b/source4/cluster/ctdb/tests/ctdb_fetch.c index 61af4c3a79..38d652bf5f 100644 --- a/source4/cluster/ctdb/tests/ctdb_fetch.c +++ b/source4/cluster/ctdb/tests/ctdb_fetch.c @@ -14,8 +14,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + License along with this library; if not, see . */ #include "includes.h" -- cgit From 6504900f1f52927adab3489b8d04b6644ceaee7d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 08:06:51 +0000 Subject: r23806: update Samba4 with the latest ctdb code. This doesn't get the ctdb code fully working in Samba4, it just gets it building and not breaking non-clustered use of Samba. It will take a bit longer to update some of the calling ctdb_cluster.c code to make it work correctly in Samba4. Note also that Samba4 now only links to the client portion of ctdb. For the moment I am leaving the ctdbd as a separate daemon, which you install separately from http://ctdb.samba.org/. (This used to be commit b196077cbb55cbecad87065133c2d67198e31066) --- source4/cluster/ctdb/tests/ctdb_fetch.c | 73 ++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 32 deletions(-) (limited to 'source4/cluster/ctdb/tests/ctdb_fetch.c') diff --git a/source4/cluster/ctdb/tests/ctdb_fetch.c b/source4/cluster/ctdb/tests/ctdb_fetch.c index 38d652bf5f..f57d05d099 100644 --- a/source4/cluster/ctdb/tests/ctdb_fetch.c +++ b/source4/cluster/ctdb/tests/ctdb_fetch.c @@ -3,18 +3,18 @@ Copyright (C) Andrew Tridgell 2006 - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, + 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . + 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" @@ -43,8 +43,7 @@ static double end_timer(void) static int timelimit = 10; static int num_records = 10; -static int num_msgs = 1; - +static int num_nodes; static int msg_count; #define TESTKEY "testkey" @@ -99,14 +98,14 @@ static void bench_fetch_1node(struct ctdb_context *ctdb) nulldata.dptr = NULL; nulldata.dsize = 0; - dest = (ctdb_get_vnn(ctdb) + 1) % ctdb_get_num_nodes(ctdb); + dest = (ctdb_get_vnn(ctdb) + 1) % num_nodes; ctdb_send_message(ctdb, dest, 0, nulldata); } /* handler for messages in bench_ring() */ -static void message_handler(struct ctdb_context *ctdb, uint32_t srvid, +static void message_handler(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data, void *private_data) { msg_count++; @@ -126,7 +125,7 @@ static void bench_fetch(struct ctdb_context *ctdb, struct event_context *ev) { int vnn=ctdb_get_vnn(ctdb); - if (vnn == ctdb_get_num_nodes(ctdb)-1) { + if (vnn == num_nodes - 1) { bench_fetch_1node(ctdb); } @@ -141,10 +140,6 @@ static void bench_fetch(struct ctdb_context *ctdb, struct event_context *ev) printf("Event loop failed!\n"); break; } - - if (LogLevel > 9) { - talloc_report_null_full(); - } } printf("Fetch: %.2f msgs/sec\n", msg_count/end_timer()); @@ -161,6 +156,16 @@ static int fetch_func(struct ctdb_call_info *call) return 0; } +/* + handler for reconfigure message +*/ +static void reconfigure_handler(struct ctdb_context *ctdb, uint64_t srvid, + TDB_DATA data, void *private_data) +{ + int *ready = (int *)private_data; + *ready = 1; +} + /* main program */ @@ -174,7 +179,7 @@ int main(int argc, const char *argv[]) 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" }, + { NULL, 'n', POPT_ARG_INT, &num_nodes, 0, "num_nodes", "integer" }, POPT_TABLEEND }; int opt; @@ -184,6 +189,7 @@ int main(int argc, const char *argv[]) poptContext pc; struct event_context *ev; struct ctdb_call call; + int cluster_ready=0; pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST); @@ -207,10 +213,13 @@ int main(int argc, const char *argv[]) ev = event_context_init(NULL); - ctdb = ctdb_cmdline_init(ev); + 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", TDB_DEFAULT, O_RDWR|O_CREAT|O_TRUNC, 0666); + ctdb_db = ctdb_attach(ctdb, "test.tdb"); if (!ctdb_db) { printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb)); exit(1); @@ -218,14 +227,15 @@ int main(int argc, const char *argv[]) ret = ctdb_set_call(ctdb_db, fetch_func, FUNC_FETCH); - /* start the protocol running */ - ret = ctdb_start(ctdb); - 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 (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); @@ -233,6 +243,8 @@ int main(int argc, const char *argv[]) call.key.dptr = discard_const(TESTKEY); call.key.dsize = strlen(TESTKEY); + printf("Fetching final record\n"); + /* fetch the record */ call.call_id = FUNC_FETCH; call.call_data.dptr = NULL; @@ -246,8 +258,5 @@ int main(int argc, const char *argv[]) printf("DATA:\n%s\n", (char *)call.reply_data.dptr); - /* go into a wait loop to allow other nodes to complete */ - ctdb_shutdown(ctdb); - return 0; } -- cgit From 2daf2897d5c70c0efbeba9b827c62700b9a9537c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 14 Jun 2008 13:00:53 -0400 Subject: Use a custom init function for samba4 that sets a samba4 specific debug function. By default do not debug, this is the most appropriate action for a library as we cannot assume what stderr is use for in the main app. The main app is responsible to set ev_debug_stderr if they so desire. (This used to be commit e566a2f308ac6fb4b526a744f7059b565670aea5) --- source4/cluster/ctdb/tests/ctdb_fetch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/cluster/ctdb/tests/ctdb_fetch.c') diff --git a/source4/cluster/ctdb/tests/ctdb_fetch.c b/source4/cluster/ctdb/tests/ctdb_fetch.c index f57d05d099..d5ec645757 100644 --- a/source4/cluster/ctdb/tests/ctdb_fetch.c +++ b/source4/cluster/ctdb/tests/ctdb_fetch.c @@ -211,7 +211,7 @@ int main(int argc, const char *argv[]) while (extra_argv[extra_argc]) extra_argc++; } - ev = event_context_init(NULL); + ev = s4_event_context_init(NULL); ctdb = ctdb_cmdline_client(ev); -- cgit