45 Commits

Author SHA1 Message Date
Ben Johnson
bf5458de2f Add inline documentation for bdc109b.
This commit simply adds some additional comments to the commit provided
by sasha-s that fixes the "slice out of bounds" errors.
2015-05-18 10:14:47 -06:00
sasha-s
bdc109bdc7 fix slice bounds out of range/maxAllocSize bugs
when accessing the node data we used to use cast to
*[maxAllocSize]byte, which breaks if we try to go across maxAllocSize boundary.

This leads to occasional panics.
Sample stacktrace:
```
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
github.com/boltdb/bolt.(*node).write(0xc208010f50, 0xc27452a000)
    $GOPATH/src/github.com/boltdb/bolt/node.go:228 +0x5a5
github.com/boltdb/bolt.(*node).spill(0xc208010f50, 0x0, 0x0)
    $GOPATH/src/github.com/boltdb/bolt/node.go:364 +0x506
github.com/boltdb/bolt.(*node).spill(0xc208010700, 0x0, 0x0)
    $GOPATH/src/github.com/boltdb/bolt/node.go:336 +0x12d
github.com/boltdb/bolt.(*node).spill(0xc208010620, 0x0, 0x0)
    $GOPATH/src/github.com/boltdb/bolt/node.go:336 +0x12d
github.com/boltdb/bolt.(*Bucket).spill(0xc22b6ae880, 0x0, 0x0)
    $GOPATH/src/github.com/boltdb/bolt/bucket.go:535 +0x1c4
github.com/boltdb/bolt.(*Bucket).spill(0xc22b6ae840, 0x0, 0x0)
    $GOPATH/src/github.com/boltdb/bolt/bucket.go:502 +0xac2
github.com/boltdb/bolt.(*Bucket).spill(0xc22f4e2018, 0x0, 0x0)
    $GOPATH/src/github.com/boltdb/bolt/bucket.go:502 +0xac2
github.com/boltdb/bolt.(*Tx).Commit(0xc22f4e2000, 0x0, 0x0)
    $GOPATH/src/github.com/boltdb/bolt/tx.go:150 +0x1ee
github.com/boltdb/bolt.(*DB).Update(0xc2080e4000, 0xc24d077508, 0x0, 0x0)
    $GOPATH/src/github.com/boltdb/bolt/db.go:483 +0x169
```
It usually happens when working with large (50M/100M) values.
One way to reproduce it is to change maxAllocSize in bolt_amd64.go to 70000 and run the tests.
TestBucket_Put_Large crashes.
2015-04-16 11:58:02 -07:00
Ben Johnson
b4d00c394a Expand assertion statements.
This commit expands calls to _assert() that use variadic arguments. These calls require conversion to interface{} so there
was a large number of calls to Go's internal convT2E() function. In some profiling this was taking over 20% of total runtime.
I don't remember seeing this before Go 1.4 so perhaps something has changed.
2015-01-30 14:15:49 -05:00
Ben Johnson
ba6badc57f Move tests to a test package. 2014-07-26 15:11:47 -06:00
Ben Johnson
c3400efefd 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.
2014-07-24 10:36:09 -06:00
Ben Johnson
aa66291b9b Fix root split on very large append.
This commit fixes a bug where a root split on a very large insert would
cause an overflow of the root node. The problem was that the new root
was not split when it was created so a new root with more than 64K child
nodes would overflow the page.count (uint16).
2014-07-23 15:08:59 -06:00
Ben Johnson
fd3c1d44b0 Fix double spill.
This fixes an issue where split nodes can be double spilled. This is typically
not noticable but it can have large effects when bulk inserting as double
spilled nodes will get added to the freelist which will grow quickly.
2014-07-23 09:04:36 -06:00
Ben Johnson
b0c97d887a Optimize large append.
This commit fixes an issue where large nodes would take up most of
the insert time because the entire node size would be calculated to
check if it could fit in a page or not. This changes the behavior
so that a node's size is only calculated up to the size it needs to
check and then returns.
2014-07-22 13:02:38 -06:00
Ben Johnson
b1dbd35da1 Fix merge-split regression.
This commit reverts merge-split and fixes the node.split() to do a multi-page split. This issue
caused problems with bulk loading because it would split into a small page and a very large page.
The very large page, in turn, would be an arbitrary size so when it was freed later it would be
difficult to reuse and would cause serious fragmentation issues.
2014-06-18 16:16:58 -06:00
Ben Johnson
2321036228 Fix double free in merge-left rebalance.
This commit fixes a bug where deletions that caused merge-left rebalances were updating
the parent node which caused a node to "reappear" even after it had been deleted. This was
fixed in merge-right rebalances a while ago but merge-left is less frequent so it was
missed until now.

Many thanks to Jordan Sherer (@jsherer) for finding and reporting the bug.
2014-06-06 17:14:17 -06:00
Ben Johnson
54cad40a78 Fix merge-split spill issues. 2014-06-03 13:40:24 -06:00
Ben Johnson
a96185e8b6 Allow split nodes to be merged with the next node.
This commit changes the node.split() functionality to check if the next node has
available space and, if so, it will merge the newly split keys into the next node.

Previously, keys could be continually put into the left side of a split causing that
first half to split off small right side nodes. This was especially problematic with
databases with a high fill percent.
2014-06-02 15:26:58 -06:00
Ben Johnson
cefc3c5ebd Add circular dependency integrity check.
This commit adds a check to prevent circular dependencies in branch nodes. If a circular dependency occurs
then a panic will be called and the commit will be prevented. This only works for a single branch level
and will not recursively search the tree.
2014-05-28 08:02:55 -06:00
Ben Johnson
a1873dd6f6 Add option to adjust fill percentage.
This commit adds the ability to adjust the fill percentage for splitting nodes. This
works by setting a threshold that is a percentage of a total page size. When that
threshold is crossed during a split then a new node is created.

This is primarily beneficial for append-only workloads.

Fixes #163.
2014-05-15 14:04:57 -06:00
Ben Johnson
d1b21e619d Merge branch 'master' of https://github.com/boltdb/bolt into fix-deletion
Conflicts:
	node.go
2014-05-09 09:38:08 -06:00
Ben Johnson
a5cb717fc7 Fix deletion reclamation. 2014-05-09 09:26:34 -06:00
Martin Kobetic
d279ea44ce add asserts for detecting pgid high watermark overflow 2014-05-09 13:35:00 +00:00
Ben Johnson
0966dde0d4 Fix bucket free. 2014-05-07 10:37:50 -06:00
Ben Johnson
55e71b0902 Add inline bucket support.
This commit adds support for writing small buckets directly inline to their value in
their parent's leaf node. Previously, subbuckets would simply have a bucket header
stored in their parent bucket which pointed to the root page. This required that
every bucket use at least a single page. This has a high overhead for buckets with
only one or two small items.

Inline buckets checks subbuckets to see if they only have a small amount of data
(about 1kb) and no subbuckets. If these conditions are met then the bucket's root
node is written to a fake page which is simply a pointer to the end of the bucket's
header.

Fixes #124.
2014-05-05 16:39:55 -06:00
Ben Johnson
25fea2fd9f Refactor split/spill. 2014-05-03 16:21:28 -06:00
Ben Johnson
698b07b074 Add nested buckets.
This commit adds the ability to create buckets inside of other buckets.
It also replaces the buckets page with a root bucket.

Fixes #56.
2014-04-11 12:36:54 -06:00
Ben Johnson
686b6a3341 Add performance counters.
This commit adds performance counters for each transaction which are rolled
up to the database level on each commit/rollback. Counters are meant to be
a very fast way to track what is going on in the database. A few timers are
also added in areas where the time.Now() overhead is not noticible.

The DB.Stat() function is now deprecated since the `bolt` CLI now performs
similar functions.

Fixes #108.
2014-04-02 16:03:03 -06:00
Ben Johnson
7f2de9f17a Add DB.Check(). 2014-03-29 14:22:32 -06:00
Ben Johnson
c551e45a47 Consolidate Tx and RWTx. 2014-03-08 20:40:48 -07:00
Ben Johnson
57376f0905 Rename Transaction to Tx.
I changed the Transaction/RWTransaction types to Tx/RWTx, respectively. This makes the naming
more consistent with other packages such as database/sql. The txnid is changed to txid as well.
2014-03-08 17:04:02 -07:00
Ben Johnson
3b2fd8f2d3 Revert "Refactor Transaction/Bucket API."
This reverts commit 1ad2b99f281d587b767b36f886401e81d17915a9.
2014-02-22 22:54:54 -07:00
Ben Johnson
1ad2b99f28 Refactor Transaction/Bucket API. 2014-02-21 22:57:50 -07:00
Ben Johnson
459b8eb4ab Read-only transactional block. 2014-02-16 15:43:35 -07:00
Ben Johnson
8ad59edd02 API Documentation. 2014-02-13 10:58:27 -07:00
Ben Johnson
7bb878ff69 Mmap remap. 2014-02-12 11:49:57 -07:00
Ben Johnson
b8122bf568 Cursor iteration. 2014-02-11 09:07:07 -07:00
Ben Johnson
509e93dff4 Add freelist. 2014-02-10 14:04:01 -07:00
Ben Johnson
3da04c52b9 Rebalance after deletion. 2014-02-08 23:13:54 -07:00
Ben Johnson
84939c21f6 Refactor node lookup. 2014-02-07 15:03:29 -07:00
Ben Johnson
a0c8de592d Fix multi-put transaction. 2014-02-06 16:06:13 -07:00
Ben Johnson
8b3b81ef47 Fix quick tests. 2014-02-05 07:56:13 -07:00
Ben Johnson
0cae98efc5 Add RWTransaction.Delete(). 2014-02-03 14:33:51 -07:00
Ben Johnson
1a17a2cf1e Add RWTransaction.Put(). 2014-02-01 12:30:37 -05:00
Ben Johnson
73ab1d420d TODO 2014-01-24 16:32:18 -07:00
Ben Johnson
20b26eac78 TODO 2014-01-24 12:51:56 -07:00
Ben Johnson
bce3e667df Intermediate commit. 2014-01-21 15:00:48 -07:00
Ben Johnson
153372abd4 Refactoring to RWCursor, RWTxn, and branch/leaf nodes and pages. 2014-01-17 15:23:39 -07:00
Ben Johnson
ee24437bfc Initial db.open. 2014-01-11 22:51:01 -07:00
Ben Johnson
f922c1d2bc Move all C code into repo. 2014-01-09 09:07:10 -07:00
Ben Johnson
ebc9f0da9e Basic types. 2014-01-08 08:06:17 -07:00