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/>.
26 #include "system/filesys.h"
27 #include "system/time.h"
30 #include "ctdb_private.h"
31 #include "lib/tdb_wrap/tdb_wrap.h"
34 char indices
[MAXINDEX
];
36 static void vn_cb(struct ctdb_context
*ctdb
, uint32_t pnn
, void *private_data
)
38 char *ind
= private_data
;
40 printf("Callback for node %d\n", pnn
);
42 printf("ERROR, node %d from callback was never added\n", pnn
);
48 static void verify_nodes(struct ctdb_context
*ctdb
, TDB_DATA data
)
52 printf("Verify the nodes\n");
53 ctdb_trackingdb_traverse(ctdb
, data
, vn_cb
, indices
);
54 for(i
= 0; i
< MAXINDEX
; i
++) {
55 if (indices
[i
] != 0) {
56 printf("Callback for %d was never invoked\n", i
);
64 static void add_node(struct ctdb_context
*ctdb
, TDB_DATA
*data
, int pnn
)
66 printf("Add node %d\n", pnn
);
67 if (ctdb_trackingdb_add_pnn(ctdb
, data
, pnn
)) {
68 printf("Failed to add tracking db data\n");
74 static void trackdb_test(struct ctdb_context
*ctdb
)
76 TDB_DATA data
= {NULL
,0};
79 printf("Add 10 nodes\n");
82 add_node(ctdb
, &data
, random()%MAXINDEX
);
85 verify_nodes(ctdb
, data
);
86 printf("OK all seems well\n");
92 int main(int argc
, const char *argv
[])
94 struct ctdb_context
*ctdb
;
96 struct poptOption popt_options
[] = {
102 const char **extra_argv
;
105 struct event_context
*ev
;
107 pc
= poptGetContext(argv
[0], argc
, argv
, popt_options
, POPT_CONTEXT_KEEP_FIRST
);
109 while ((opt
= poptGetNextOpt(pc
)) != -1) {
112 fprintf(stderr
, "Invalid option %s: %s\n",
113 poptBadOption(pc
, 0), poptStrerror(opt
));
118 /* setup the remaining options for the main program to use */
119 extra_argv
= poptGetArgs(pc
);
122 while (extra_argv
[extra_argc
]) extra_argc
++;
125 ev
= event_context_init(NULL
);
127 ctdb
= ctdb_cmdline_client(ev
, timeval_current_ofs(5, 0));