[Tux3] Patch: Should update btree cursor path in insert_node

OGAWA Hirofumi hirofumi at mail.parknet.co.jp
Thu Dec 25 01:26:36 PST 2008


Daniel Phillips <phillips at phunq.net> writes:

> Suggested fix?  It just advances next pointers in two places, and
> tries to set the correct next pointer for new root.  Gets rid of
> the cached "next" pointer and operates directly on the cursor.

I've wrote the test of this.

diff -puN user/btree.c~cursor-check user/btree.c
--- tux3/user/btree.c~cursor-check	2008-12-25 16:39:14.000000000 +0900
+++ tux3-hirofumi/user/btree.c	2008-12-25 18:25:28.000000000 +0900
@@ -191,6 +191,31 @@ int main(int argc, char *argv[])
 	show_buffers(sb->devmap);
 	tree_chop(&btree, &(struct delete_info){ .key = 0x10 }, -1);
 	show_tree_range(&btree, 0, -1);
+
+	/* insert_node test */
+	tree_chop(&btree, &(struct delete_info){ .key = 0 }, 0);
+	cursor = alloc_cursor(&btree, 1); /* +1 for new depth */
+	assert(!probe(&btree, 0, cursor));
+	for (int i = 0; i < sb->entries_per_node - 1; i++) {
+		struct buffer_head *buffer = new_leaf(&btree);
+		assert(buffer);
+		insert_node(&btree, 100 + i, bufindex(buffer), cursor);
+	}
+	release_cursor(cursor);
+	assert(!probe(&btree, 0, cursor));
+	struct buffer_head *buffer = new_leaf(&btree);
+	insert_node(&btree, 1, bufindex(buffer), cursor);
+	struct cursor *cursor2 = alloc_cursor(&btree, 0);
+	assert(!probe(&btree, 1, cursor2));
+	for (int i = 0; i < cursor->len; i++) {
+		assert(cursor->path[i].buffer == cursor2->path[i].buffer);
+		assert(cursor->path[i].next == cursor2->path[i].next);
+	}
+	release_cursor(cursor);
+	release_cursor(cursor2);
+	free_cursor(cursor);
+	free_cursor(cursor2);
+	tree_chop(&btree, &(struct delete_info){ .key = 0 }, 0);
 	exit(0);
 }
 #endif
_
-- 
OGAWA Hirofumi <hirofumi at mail.parknet.co.jp>

_______________________________________________
Tux3 mailing list
Tux3 at tux3.org
http://mailman.tux3.org/cgi-bin/mailman/listinfo/tux3



More information about the Tux3 mailing list