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 btrfs_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));
47 if (i == run_size - 5) {
48 commit_transaction(root, &super);
52 close_ctree(root, &super);
54 root = open_ctree("dbfile", &super);
55 printf("starting search\n");
57 for (i = 0; i < run_size; i++) {
58 num = next_key(i, max_key);
62 fprintf(stderr, "search %d:%d\n", num, i);
63 ret = search_slot(root, &ins, &path, 0, 0);
65 print_tree(root, root->node);
66 printf("unable to find %d\n", num);
69 release_path(root, &path);
71 close_ctree(root, &super);
72 root = open_ctree("dbfile", &super);
73 printf("node %p level %d total ptrs %d free spc %lu\n", root->node,
74 btrfs_header_level(&root->node->node.header),
75 btrfs_header_nritems(&root->node->node.header),
77 btrfs_header_nritems(&root->node->node.header));
78 printf("all searches good, deleting some items\n");
81 for (i = 0 ; i < run_size/4; i++) {
82 num = next_key(i, max_key);
85 ret = search_slot(root, &ins, &path, -1, 1);
88 fprintf(stderr, "del %d:%d\n", num, i);
89 ret = del_item(root, &path);
94 release_path(root, &path);
96 close_ctree(root, &super);
97 root = open_ctree("dbfile", &super);
99 for (i = 0; i < run_size; i++) {
101 num = next_key(i, max_key);
102 sprintf(buf, "string-%d", num);
105 fprintf(stderr, "insert %d:%d\n", num, i);
106 ret = insert_item(root, &ins, buf, strlen(buf));
111 close_ctree(root, &super);
112 root = open_ctree("dbfile", &super);
114 printf("starting search2\n");
115 for (i = 0; i < run_size; i++) {
116 num = next_key(i, max_key);
120 fprintf(stderr, "search %d:%d\n", num, i);
121 ret = search_slot(root, &ins, &path, 0, 0);
123 print_tree(root, root->node);
124 printf("unable to find %d\n", num);
127 release_path(root, &path);
129 printf("starting big long delete run\n");
131 btrfs_header_nritems(&root->node->node.header) > 0) {
134 ins.objectid = (u64)-1;
136 ret = search_slot(root, &ins, &path, -1, 1);
140 leaf = &path.nodes[0]->leaf;
141 slot = path.slots[0];
142 if (slot != btrfs_header_nritems(&leaf->header))
144 while(path.slots[0] > 0) {
146 slot = path.slots[0];
147 leaf = &path.nodes[0]->leaf;
149 btrfs_disk_key_to_cpu(&last, &leaf->items[slot].key);
150 if (tree_size % 10000 == 0)
151 printf("big del %d:%d\n", tree_size, i);
152 ret = del_item(root, &path);
154 printf("del_item returned %d\n", ret);
159 release_path(root, &path);
162 printf("previous tree:\n");
163 print_tree(root, root->commit_root);
164 printf("map before commit\n");
165 print_tree(root->extent_root, root->extent_root->node);
167 commit_transaction(root, &super);
168 printf("tree size is now %d\n", tree_size);
169 printf("root %p commit root %p\n", root->node, root->commit_root);
170 printf("map tree\n");
171 print_tree(root->extent_root, root->extent_root->node);
172 close_ctree(root, &super);