aboutsummaryrefslogtreecommitdiff
path: root/bucket.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-07-24 11:25:57 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-07-24 11:25:57 -0600
commitd021755f077c19224e32f5d88a4f35a4076e00d6 (patch)
tree8082796f45131be814281ffd2b3acefab92d2656 /bucket.go
parentMerge pull request #228 from benbjohnson/fix-large-append (diff)
parentAdd FillPercent documentation. (diff)
downloaddedo-d021755f077c19224e32f5d88a4f35a4076e00d6.tar.gz
dedo-d021755f077c19224e32f5d88a4f35a4076e00d6.tar.xz
Merge pull request #229 from benbjohnson/bucket-fill-percent
Change fill percent to be per-bucket.
Diffstat (limited to 'bucket.go')
-rw-r--r--bucket.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/bucket.go b/bucket.go
index 16a29fe..1ef0d5e 100644
--- a/bucket.go
+++ b/bucket.go
@@ -23,6 +23,15 @@ const (
const bucketHeaderSize = int(unsafe.Sizeof(bucket{}))
+const (
+ minFillPercent = 0.1
+ maxFillPercent = 1.0
+)
+
+// DefaultFillPercent is the percentage that split pages are filled.
+// This value can be changed by setting Bucket.FillPercent.
+const DefaultFillPercent = 0.5
+
// Bucket represents a collection of key/value pairs inside the database.
type Bucket struct {
*bucket
@@ -31,6 +40,13 @@ type Bucket struct {
page *page // inline page reference
rootNode *node // materialized node for the root page.
nodes map[pgid]*node // node cache
+
+ // Sets the threshold for filling nodes when they split. By default,
+ // the bucket will fill to 50% but it can be useful to increase this
+ // amount if you know that your write workloads are mostly append-only.
+ //
+ // This is non-persisted across transactions so it must be set in every Tx.
+ FillPercent float64
}
// bucket represents the on-file representation of a bucket.
@@ -44,7 +60,7 @@ type bucket struct {
// newBucket returns a new bucket associated with a transaction.
func newBucket(tx *Tx) Bucket {
- var b = Bucket{tx: tx}
+ var b = Bucket{tx: tx, FillPercent: DefaultFillPercent}
if tx.writable {
b.buckets = make(map[string]*Bucket)
b.nodes = make(map[pgid]*node)
@@ -155,7 +171,11 @@ func (b *Bucket) CreateBucket(key []byte) (*Bucket, error) {
}
// Create empty, inline bucket.
- var bucket = Bucket{bucket: &bucket{}, rootNode: &node{isLeaf: true}}
+ var bucket = Bucket{
+ bucket: &bucket{},
+ rootNode: &node{isLeaf: true},
+ FillPercent: DefaultFillPercent,
+ }
var value = bucket.write()
// Insert into node.