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
));
49 close_ctree(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, 0);
62 print_tree(root
, root
->node
);
63 printf("unable to find %d\n", num
);
66 release_path(root
, &path
);
68 close_ctree(root
, &super
);
69 root
= open_ctree("dbfile", &super
);
70 printf("node %p level %d total ptrs %d free spc %lu\n", root
->node
,
71 node_level(root
->node
->node
.header
.flags
),
72 root
->node
->node
.header
.nritems
,
73 NODEPTRS_PER_BLOCK
- root
->node
->node
.header
.nritems
);
74 printf("all searches good, deleting some items\n");
77 for (i
= 0 ; i
< run_size
/4; i
++) {
78 num
= next_key(i
, max_key
);
81 ret
= search_slot(root
, &ins
, &path
, -1, 1);
84 fprintf(stderr
, "del %d:%d\n", num
, i
);
85 ret
= del_item(root
, &path
);
90 release_path(root
, &path
);
92 close_ctree(root
, &super
);
93 root
= open_ctree("dbfile", &super
);
95 for (i
= 0; i
< run_size
; i
++) {
97 num
= next_key(i
, max_key
);
98 sprintf(buf
, "string-%d", num
);
101 fprintf(stderr
, "insert %d:%d\n", num
, i
);
102 ret
= insert_item(root
, &ins
, buf
, strlen(buf
));
107 close_ctree(root
, &super
);
108 root
= open_ctree("dbfile", &super
);
110 printf("starting search2\n");
111 for (i
= 0; i
< run_size
; i
++) {
112 num
= next_key(i
, max_key
);
116 fprintf(stderr
, "search %d:%d\n", num
, i
);
117 ret
= search_slot(root
, &ins
, &path
, 0, 0);
119 print_tree(root
, root
->node
);
120 printf("unable to find %d\n", num
);
123 release_path(root
, &path
);
125 printf("starting big long delete run\n");
126 while(root
->node
&& root
->node
->node
.header
.nritems
> 0) {
129 ins
.objectid
= (u64
)-1;
131 ret
= search_slot(root
, &ins
, &path
, -1, 1);
135 leaf
= &path
.nodes
[0]->leaf
;
136 slot
= path
.slots
[0];
137 if (slot
!= leaf
->header
.nritems
)
139 while(path
.slots
[0] > 0) {
141 slot
= path
.slots
[0];
142 leaf
= &path
.nodes
[0]->leaf
;
144 memcpy(&last
, &leaf
->items
[slot
].key
, sizeof(last
));
145 if (tree_size
% 10000 == 0)
146 printf("big del %d:%d\n", tree_size
, i
);
147 ret
= del_item(root
, &path
);
149 printf("del_item returned %d\n", ret
);
154 release_path(root
, &path
);
157 printf("previous tree:\n");
158 print_tree(root, root->commit_root);
159 printf("map before commit\n");
160 print_tree(root->extent_root, root->extent_root->node);
162 commit_transaction(root
, &super
);
163 printf("tree size is now %d\n", tree_size
);
164 printf("root %p commit root %p\n", root
->node
, root
->commit_root
);
165 printf("map tree\n");
166 print_tree(root
->extent_root
, root
->extent_root
->node
);
167 close_ctree(root
, &super
);