aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-02-06 16:21:36 -0700
committerBen Johnson <benbjohnson@yahoo.com>2014-02-06 16:21:36 -0700
commit1318213f1d652dfd035ffe6116e2be31573ca64a (patch)
tree465931a9aa89ab725d4cd7750002f909336104a1
parentMerge pull request #18 from benbjohnson/master (diff)
downloaddedo-1318213f1d652dfd035ffe6116e2be31573ca64a.tar.gz
dedo-1318213f1d652dfd035ffe6116e2be31573ca64a.tar.xz
Clean up.
-rw-r--r--buckets.go2
-rw-r--r--rwtransaction.go16
-rw-r--r--rwtransaction_test.go1
-rw-r--r--transaction.go10
4 files changed, 14 insertions, 15 deletions
diff --git a/buckets.go b/buckets.go
index 59a82d8..482dea2 100644
--- a/buckets.go
+++ b/buckets.go
@@ -7,7 +7,7 @@ import (
// buckets represents a in-memory buckets page.
type buckets struct {
- pgid pgid
+ pgid pgid
items map[string]*bucket
}
diff --git a/rwtransaction.go b/rwtransaction.go
index d6cde58..fed59a6 100644
--- a/rwtransaction.go
+++ b/rwtransaction.go
@@ -180,19 +180,14 @@ func (t *RWTransaction) spill() {
roots = append(roots, root{n, n.pgid})
}
- // Split nodes and write them.
+ // Split nodes into appropriate sized nodes.
+ // The first node in this list will be a reference to n to preserve ancestry.
newNodes := n.split(t.db.pageSize)
// If this is a root node that split then create a parent node.
if n.parent == nil && len(newNodes) > 1 {
- n.parent = &node{
- isLeaf: false,
- key: newNodes[0].inodes[0].key,
- depth: n.depth - 1,
- inodes: make(inodes, 0),
- }
+ n.parent = &node{isLeaf: false}
nodes = append(nodes, n.parent)
- sort.Sort(nodes)
}
// Write nodes to dirty pages.
@@ -204,7 +199,7 @@ func (t *RWTransaction) spill() {
newNode.write(p)
newNode.pgid = p.id
newNode.parent = n.parent
-
+
// The first node should use the existing entry, other nodes are inserts.
var oldKey []byte
if i == 0 {
@@ -224,6 +219,9 @@ func (t *RWTransaction) spill() {
for _, root := range roots {
t.buckets.updateRoot(root.pgid, root.node.root().pgid)
}
+
+ // Clear out nodes now that they are all spilled.
+ t.nodes = make(map[pgid]*node)
}
// write writes any dirty pages to disk.
diff --git a/rwtransaction_test.go b/rwtransaction_test.go
index 75a606b..f027e8b 100644
--- a/rwtransaction_test.go
+++ b/rwtransaction_test.go
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/assert"
)
+
// Ensure that a RWTransaction can be retrieved.
func TestRWTransaction(t *testing.T) {
withOpenDB(func(db *DB, path string) {
diff --git a/transaction.go b/transaction.go
index 5733e9e..d21693a 100644
--- a/transaction.go
+++ b/transaction.go
@@ -10,11 +10,11 @@ const (
type txnid uint64
type Transaction struct {
- id int
- db *DB
- meta *meta
- buckets *buckets
- pages map[pgid]*page
+ id int
+ db *DB
+ meta *meta
+ buckets *buckets
+ pages map[pgid]*page
}
// init initializes the transaction and associates it with a database.