2 simple trackingdb test tool
4 This program is used to test the funcitons to manipulate and enumerate
5 the trackingdb records :
6 ctdb_trackingdb_add_pnn()
7 ctdb_trackingdb_traverse()
9 Copyright (C) Ronnie Sahlberg 2009
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, see <http://www.gnu.org/licenses/>.
28 #include "lib/tevent/tevent.h"
29 #include "system/filesys.h"
32 #include "ctdb_private.h"
36 char indices[MAXINDEX];
38 void vn_cb(struct ctdb_context *ctdb, uint32_t pnn, void *private_data)
40 char *ind = private_data;
42 printf("Callback for node %d\n", pnn);
44 printf("ERROR, node %d from callback was never added\n", pnn);
50 void verify_nodes(struct ctdb_context *ctdb, TDB_DATA data)
54 printf("Verify the nodes\n");
55 ctdb_trackingdb_traverse(ctdb, data, vn_cb, indices);
56 for(i = 0; i < MAXINDEX; i++) {
57 if (indices[i] != 0) {
58 printf("Callback for %d was never invoked\n", i);
66 void add_node(struct ctdb_context *ctdb, TDB_DATA *data, int pnn)
68 printf("Add node %d\n", pnn);
69 if (ctdb_trackingdb_add_pnn(ctdb, data, pnn)) {
70 printf("Failed to add tracking db data\n");
76 static void trackdb_test(struct ctdb_context *ctdb)
78 TDB_DATA data = {NULL,0};
81 printf("Add 10 nodes\n");
84 add_node(ctdb, &data, random()%MAXINDEX);
87 verify_nodes(ctdb, data);
88 printf("OK all seems well\n");
94 int main(int argc, const char *argv[])
96 struct ctdb_context *ctdb;
98 struct poptOption popt_options[] = {
104 const char **extra_argv;
107 struct event_context *ev;
109 pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
111 while ((opt = poptGetNextOpt(pc)) != -1) {
114 fprintf(stderr, "Invalid option %s: %s\n",
115 poptBadOption(pc, 0), poptStrerror(opt));
120 /* setup the remaining options for the main program to use */
121 extra_argv = poptGetArgs(pc);
124 while (extra_argv[extra_argc]) extra_argc++;
127 ev = event_context_init(NULL);
129 ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(5, 0));