3 #include "kerncompat.h"
4 #include "radix-tree.h"
7 #include "print-tree.h"
10 int next_key(int i
, int max_key
) {
11 return rand() % max_key
;
15 int main(int ac
, char **av
) {
17 struct key last
= { (u64
)-1, 0, 0};
22 int run_size
= 100000;
23 int max_key
= 100000000;
25 struct ctree_path path
;
26 struct ctree_super_block super
;
27 struct ctree_root
*root
;
31 root
= open_ctree("dbfile", &super
);
33 for (i
= 0; i
< run_size
; i
++) {
35 num
= next_key(i
, max_key
);
37 sprintf(buf
, "string-%d", num
);
39 fprintf(stderr
, "insert %d:%d\n", num
, i
);
43 ret
= insert_item(root
, &ins
, buf
, strlen(buf
));
48 write_ctree_super(root
, &super
);
51 root
= open_ctree("dbfile", &super
);
52 printf("starting search\n");
54 for (i
= 0; i
< run_size
; i
++) {
55 num
= next_key(i
, max_key
);
59 fprintf(stderr
, "search %d:%d\n", num
, i
);
60 ret
= search_slot(root
, &ins
, &path
, 0);
62 print_tree(root
, root
->node
);
63 printf("unable to find %d\n", num
);
66 release_path(root
, &path
);
68 write_ctree_super(root
, &super
);
70 root
= open_ctree("dbfile", &super
);
71 printf("node %p level %d total ptrs %d free spc %lu\n", root
->node
,
72 node_level(root
->node
->node
.header
.flags
),
73 root
->node
->node
.header
.nritems
,
74 NODEPTRS_PER_BLOCK
- root
->node
->node
.header
.nritems
);
75 printf("all searches good, deleting some items\n");
78 for (i
= 0 ; i
< run_size
/4; i
++) {
79 num
= next_key(i
, max_key
);
82 ret
= search_slot(root
, &ins
, &path
, -1);
85 fprintf(stderr
, "del %d:%d\n", num
, i
);
86 ret
= del_item(root
, &path
);
91 release_path(root
, &path
);
93 write_ctree_super(root
, &super
);
95 root
= open_ctree("dbfile", &super
);
97 for (i
= 0; i
< run_size
; i
++) {
99 num
= next_key(i
, max_key
);
100 sprintf(buf
, "string-%d", num
);
103 fprintf(stderr
, "insert %d:%d\n", num
, i
);
104 ret
= insert_item(root
, &ins
, buf
, strlen(buf
));
109 write_ctree_super(root
, &super
);
111 root
= open_ctree("dbfile", &super
);
113 printf("starting search2\n");
114 for (i
= 0; i
< run_size
; i
++) {
115 num
= next_key(i
, max_key
);
119 fprintf(stderr
, "search %d:%d\n", num
, i
);
120 ret
= search_slot(root
, &ins
, &path
, 0);
122 print_tree(root
, root
->node
);
123 printf("unable to find %d\n", num
);
126 release_path(root
, &path
);
128 printf("starting big long delete run\n");
129 while(root
->node
&& root
->node
->node
.header
.nritems
> 0) {
132 ins
.objectid
= (u64
)-1;
134 ret
= search_slot(root
, &ins
, &path
, -1);
138 leaf
= &path
.nodes
[0]->leaf
;
139 slot
= path
.slots
[0];
140 if (slot
!= leaf
->header
.nritems
)
142 while(path
.slots
[0] > 0) {
144 slot
= path
.slots
[0];
145 leaf
= &path
.nodes
[0]->leaf
;
147 memcpy(&last
, &leaf
->items
[slot
].key
, sizeof(last
));
148 if (tree_size
% 10000 == 0)
149 printf("big del %d:%d\n", tree_size
, i
);
150 ret
= del_item(root
, &path
);
152 printf("del_item returned %d\n", ret
);
157 release_path(root
, &path
);
159 printf("tree size is now %d\n", tree_size
);
160 printf("map tree\n");
161 print_tree(root
->extent_root
, root
->extent_root
->node
);
162 write_ctree_super(root
, &super
);