diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-07-24 10:36:09 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-07-24 10:36:09 -0600 |
commit | c3400efefdf9733e98cb125d00a0c0721a2db51e (patch) | |
tree | 6ba412db0873b653e98d1db414293d413dd2f558 /bucket.go | |
parent | Merge pull request #228 from benbjohnson/fix-large-append (diff) | |
download | dedo-c3400efefdf9733e98cb125d00a0c0721a2db51e.tar.gz dedo-c3400efefdf9733e98cb125d00a0c0721a2db51e.tar.xz |
Change fill percent to be per-bucket.
This commit moves the DB.FillPercent field to Bucket.FillPercent. This
allows the fill percentage to be specified per-bucket, per-tx. This
value is not persisted and should be set whenever using it.
Diffstat (limited to 'bucket.go')
-rw-r--r-- | bucket.go | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -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,11 @@ 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. + FillPercent float64 } // bucket represents the on-file representation of a bucket. @@ -44,7 +58,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 +169,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. |