aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kobetic <mkobetic@gmail.com>2014-04-17 22:01:16 +0000
committerMartin Kobetic <mkobetic@gmail.com>2014-04-17 22:01:16 +0000
commit9a3d0db1b2f46e79f391c1cd839c7fce6bfb8918 (patch)
treeb1c15a26a3537de0a00f700005b68251947ef4c7
parenthide the cursor stack details behind function calls (pop/push/current) (diff)
downloaddedo-9a3d0db1b2f46e79f391c1cd839c7fce6bfb8918.tar.gz
dedo-9a3d0db1b2f46e79f391c1cd839c7fce6bfb8918.tar.xz
trying to fix large seek
-rw-r--r--c/cursor.go8
-rw-r--r--c/cursor_test.go24
2 files changed, 18 insertions, 14 deletions
diff --git a/c/cursor.go b/c/cursor.go
index e3495b3..189d385 100644
--- a/c/cursor.go
+++ b/c/cursor.go
@@ -163,7 +163,8 @@ void bolt_cursor_seek(bolt_cursor *c, bolt_val seek, bolt_val *key, bolt_val *va
return;
};
- // Set the key/value for the current position.
+ // Find first leaf and return key/value.
+ cursor_first_leaf(c);
cursor_key_value(c, key, value, flags);
}
@@ -243,6 +244,7 @@ void cursor_search(bolt_cursor *c, bolt_val key, pgid id) {
// Push page onto the cursor stack.
elem_ref *ref = cursor_push(c, id);
+ printf("search page id=%d depth=%d\n", (int)id, c->top);
// If we're on a leaf page/node then find the specific node.
if (ref->page->flags & PAGE_LEAF) {
cursor_search_leaf(c, key);
@@ -290,7 +292,9 @@ void cursor_search_branch(bolt_cursor *c, bolt_val key) {
if (key.size == 0 || (rc == 0 && key.size >= elem->ksize) || rc < 0) {
ref->index = i;
cursor_search(c, key, elem->pgid);
- return;
+ if (cursor_current(c) == ref) ref->index++;
+ if (ref->index < ref->page->count) return;
+ break;
}
}
diff --git a/c/cursor_test.go b/c/cursor_test.go
index 21b6696..ef0f4bc 100644
--- a/c/cursor_test.go
+++ b/c/cursor_test.go
@@ -146,30 +146,30 @@ func TestCursor_Seek_Large(t *testing.T) {
db.Update(func(tx *bolt.Tx) error {
b, _ := tx.CreateBucket([]byte("widgets"))
for i := 1; i < 1000; i++ {
- b.Put([]byte(fmt.Sprintf("%05d", i*10)), []byte(fmt.Sprintf("%020d", i*10)))
+ b.Put([]byte(fmt.Sprintf("%05d\000", i*10)), []byte(fmt.Sprintf("%020d", i*10)))
}
return nil
})
db.View(func(tx *bolt.Tx) error {
c := NewCursor(tx.Bucket([]byte("widgets")))
- // Exact match should go to the key.
- k, v, _ := c.Seek([]byte("05000"))
- assert.Equal(t, "05000", string(k))
+ fmt.Println("// Exact match should go to the key.")
+ k, v, _ := c.Seek([]byte("05000\000"))
+ assert.Equal(t, "05000\000", string(k))
assert.Equal(t, fmt.Sprintf("%020d", 5000), string(v))
- // Inexact match should go to the next key.
- k, v, _ = c.Seek([]byte("07495"))
- assert.Equal(t, "07500", string(k))
+ fmt.Println("// Inexact match should go to the next key.")
+ k, v, _ = c.Seek([]byte("07495\000"))
+ assert.Equal(t, "07500\000", string(k))
assert.Equal(t, fmt.Sprintf("%020d", 7500), string(v))
- // Low key should go to the first key.
- k, v, _ = c.Seek([]byte("00000"))
- assert.Equal(t, "00010", string(k))
+ fmt.Println("// Low key should go to the first key.")
+ k, v, _ = c.Seek([]byte("00000\000"))
+ assert.Equal(t, "00010\000", string(k))
assert.Equal(t, fmt.Sprintf("%020d", 10), string(v))
- // High key should return no key.
- k, v, _ = c.Seek([]byte("40000"))
+ fmt.Println("// High key should return no key.")
+ k, v, _ = c.Seek([]byte("40000\000"))
assert.Equal(t, "", string(k))
assert.Equal(t, "", string(v))