4 Copyright (C) Andrew Tridgell 2006
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "lib/events/events.h"
23 #include "system/filesys.h"
27 static int timelimit = 10;
28 static int num_records = 10;
29 static int num_msgs = 1;
30 static int num_clients = 2;
34 handler for messages in bench_ring()
36 static void message_handler(struct ctdb_context *ctdb, uint64_t srvid,
37 TDB_DATA data, void *private_data)
39 printf("client vnn:%d received a message to srvid:%lld [%s]\n",ctdb_get_vnn(ctdb),srvid,data.dptr);
46 int main(int argc, const char *argv[])
48 struct ctdb_context *ctdb;
49 struct ctdb_db_context *ctdb_db;
52 struct poptOption popt_options[] = {
55 { "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" },
56 { "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" },
57 { "num-msgs", 'n', POPT_ARG_INT, &num_msgs, 0, "num_msgs", "integer" },
58 { "num-clients", 0, POPT_ARG_INT, &num_clients, 0, "num_clients", "integer" },
62 const char **extra_argv;
66 struct event_context *ev;
71 pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
73 while ((opt = poptGetNextOpt(pc)) != -1) {
76 fprintf(stderr, "Invalid option %s: %s\n",
77 poptBadOption(pc, 0), poptStrerror(opt));
82 /* setup the remaining options for the main program to use */
83 extra_argv = poptGetArgs(pc);
86 while (extra_argv[extra_argc]) extra_argc++;
89 ev = event_context_init(NULL);
92 ctdb = ctdb_cmdline_init(ev);
94 printf("Failed to init ctdb\n");
98 /* attach to a specific database */
99 ctdb_db = ctdb_attach(ctdb, "test.tdb", TDB_DEFAULT, O_RDWR|O_CREAT|O_TRUNC, 0666);
101 printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
105 /* start the protocol running */
106 ret = ctdb_start(ctdb);
109 for (i=0;i<num_clients-1;i++) {
117 srvid = num_clients-1;
120 ctdb_set_message_handler(ctdb, srvid, message_handler, NULL);
122 /* wait until all nodes are connected (should not be needed
123 outside of test code) */
124 ctdb_connect_wait(ctdb);
128 printf("sending message from vnn:%d to vnn:%d/srvid:%d\n",ctdb_get_vnn(ctdb),ctdb_get_vnn(ctdb), 1-srvid);
129 for (i=0;i<ctdb_get_num_nodes(ctdb);i++) {
130 for (j=0;j<num_clients;j++) {
131 printf("sending message to %d:%d\n", i, j);
132 sprintf(buf,"Message from %d to vnn:%d srvid:%d",ctdb_get_vnn(ctdb),i,j);
133 data.dptr = (unsigned char *)buf;
134 data.dsize=strlen(buf)+1;
135 ctdb_send_message(ctdb, i, j, data);