45 Commits

Author SHA1 Message Date
Josh Rickmar
9034717d69 Try to use reflect.SliceHeader correctly this time 2020-05-21 18:50:41 +00:00
Josh Rickmar
81f25783ae Shorten max array lengths for the data type 2020-05-03 17:32:57 +00:00
Josh Rickmar
f9d3ff6648 Fix incorrect unsafe usage
After checkptr fixes by 2fc6815c, it was discovered that new issues
were hit in production systems, in particular when a single process
opened and updated multiple separate databases.  This indicates that
some bug relating to bad unsafe usage was introduced during this
commit.

This commit combines several attempts at fixing this new issue.  For
example, slices are once again created by slicing an array of "max
allocation" elements, but this time with the cap set to the intended
length.  This operation is espressly permitted according to the Go
wiki, so it should be preferred to type converting a
reflect.SliceHeader.
2020-04-28 20:30:23 +00:00
chyroc
a8af23b57f
opt: reuse var leafPageElementSize (#215) 2020-04-23 17:56:04 -07:00
Josh Rickmar
543c40ab41 Fix unsafe pointer conversions caught by Go 1.14 checkptr 2020-03-18 21:18:39 -04:00
Gyuho Lee
76a4670663 *: update import paths "go.etcd.io/bbolt"
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
2018-08-28 08:15:54 -07:00
Josh Bleecher Snyder
1858583b3b Clean up after #636
freelist.lenall duplicated freelist.count.
freelist.copyall and mergepgids docs had typos.
2016-12-23 08:56:04 -08:00
Josh Bleecher Snyder
4d8824b05d Don't allocate huge slices to merge pgids in freelist.write
Using a large (50gb) database with a read-write-delete heavy load,
nearly 100% of allocated space came from freelists.
1/3 came from freelist.release, 1/3 from freelist.write,
and 1/3 came from tx.allocate to make space for freelist.write.
In the case of freelist.write, the newly allocated giant slice gets
copied to the space prepared by tx.allocate and then discarded.

To avoid this, add func mergepgids that accepts a destination slice,
and use it in freelist.write.

This has a mild negative impact on the existing benchmarks,
but cuts allocated space in my real world db by over 30%.

name                      old time/op    new time/op    delta
_FreelistRelease10K-8       18.7µs ±10%    18.2µs ± 4%    ~             (p=0.548 n=5+5)
_FreelistRelease100K-8       233µs ± 5%     258µs ±20%    ~             (p=0.151 n=5+5)
_FreelistRelease1000K-8     3.34ms ± 8%    3.13ms ± 8%    ~             (p=0.151 n=5+5)
_FreelistRelease10000K-8    32.3ms ± 1%    32.2ms ± 7%    ~             (p=0.690 n=5+5)
DBBatchAutomatic-8          2.18ms ± 3%    2.19ms ± 4%    ~             (p=0.421 n=5+5)
DBBatchSingle-8              140ms ± 6%     140ms ± 4%    ~             (p=0.841 n=5+5)
DBBatchManual10x100-8       4.41ms ± 2%    4.37ms ± 3%    ~             (p=0.548 n=5+5)

name                      old alloc/op   new alloc/op   delta
_FreelistRelease10K-8       82.5kB ± 0%    82.5kB ± 0%    ~     (all samples are equal)
_FreelistRelease100K-8       805kB ± 0%     805kB ± 0%    ~     (all samples are equal)
_FreelistRelease1000K-8     8.05MB ± 0%    8.05MB ± 0%    ~     (all samples are equal)
_FreelistRelease10000K-8    80.4MB ± 0%    80.4MB ± 0%    ~             (p=1.000 n=5+5)
DBBatchAutomatic-8           384kB ± 0%     384kB ± 0%    ~             (p=0.095 n=5+5)
DBBatchSingle-8             17.2MB ± 1%    17.2MB ± 1%    ~             (p=0.310 n=5+5)
DBBatchManual10x100-8        908kB ± 0%     902kB ± 1%    ~             (p=0.730 n=4+5)

name                      old allocs/op  new allocs/op  delta
_FreelistRelease10K-8         5.00 ± 0%      5.00 ± 0%    ~     (all samples are equal)
_FreelistRelease100K-8        5.00 ± 0%      5.00 ± 0%    ~     (all samples are equal)
_FreelistRelease1000K-8       5.00 ± 0%      5.00 ± 0%    ~     (all samples are equal)
_FreelistRelease10000K-8      5.00 ± 0%      5.00 ± 0%    ~     (all samples are equal)
DBBatchAutomatic-8           10.2k ± 0%     10.2k ± 0%  +0.07%          (p=0.032 n=5+5)
DBBatchSingle-8              58.6k ± 0%     59.6k ± 0%  +1.70%          (p=0.008 n=5+5)
DBBatchManual10x100-8        6.02k ± 0%     6.03k ± 0%  +0.17%          (p=0.029 n=4+4)
2016-12-20 14:32:15 -08:00
Ben Johnson
92410e0673
fix Go 1.7 pointer reference bug
This commit fixes a bug where page end-of-header pointers were being
converted to byte slices even when the pointer did not point to
allocated memory. This occurs with pages that have a `page.count`
of zero.

Note: This was not an issue in Go 1.6 but the new Go 1.7 SSA backend
handles `nil` checks differently.

See https://github.com/golang/go/issues/16772
2016-08-18 08:44:57 -06:00
Ben Johnson
2b4a0e2894 set slice capacity
This commit sets the capacity on slices returned from
`Bucket.Get()` to match the slice length. Previously
the capacity would be the size of the mmap max size.

This does not cause any backwards compatibility issues,
however, it does allow users to `append()` to the returned
slice since that will cause Go to realloc a new slice on the
heap.

Fixes #544
2016-03-25 10:53:30 -06:00
Martin Kobetic
04a3e85793 Merge sorted pgids rather than resorting everything 2015-06-16 13:48:54 -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
349dacfd44 Update max alloc size on 386 arch. 2015-02-27 08:45:05 -07:00
Ben Johnson
b9c28b721a Increase max array size to 2GB.
This commit changes the maxAllocSize from 256GB to 2GB to handle large
values. It was previously 0xFFFFFFF and I tried adding one more "F" but
it caused an "array too large" error. I played around with the value
some more and found that 0x7FFFFFFF (2GB) is the highest allowed value.

This does not affect how the data is stored. It is simply used for type
converting pointers to array pointers in order to utilize zero copy
from the mmap.
2015-02-26 16:01:58 -07:00
Ben Johnson
515bf03ff9 Fix i686 build error. 2014-06-18 11:53:01 -06:00
Ben Johnson
fd7b0efeb5 Increase max nodes per page.
This commit changes the maxNodesPerPage constant so that it is essentially unlimited.
Previously, a single large transaction could create more nodes than the mock array
could handle.

Fixes #188.
2014-06-10 09:38:40 -06:00
Ben Johnson
12b36fe70c Fix freelist allocate(). 2014-05-19 14:11:32 -06:00
Ben Johnson
782ead0dbf Fix freelist allocation direction.
This commit fixes the freelist so that it frees from the beginning of the data file
instead of the end. It also adds a fast path for pages which can be allocated from
the first free pages and it includes read transaction stats.
2014-05-19 12:08:33 -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
0e4d77d424 Add 'bolt pages'. 2014-03-21 22:34:54 -06:00
Ben Johnson
a1f43f4d60 Allow reads of unflushed nodes.
This commit allows cursors to read updated values from within the
RWTransaction.
2014-03-01 09:13:59 -07:00
Ben Johnson
8ad59edd02 API Documentation. 2014-02-13 10:58:27 -07:00
Ben Johnson
509e93dff4 Add freelist. 2014-02-10 14:04:01 -07:00
Ben Johnson
84939c21f6 Refactor node lookup. 2014-02-07 15:03:29 -07:00
Ben Johnson
0ed3dc3071 Rename sys ☞ buckets. 2014-02-05 22:15:47 -07:00
Ben Johnson
1a17a2cf1e Add RWTransaction.Put(). 2014-02-01 12:30:37 -05:00
Ben Johnson
26f6fefead Add RWTransaction.write(). 2014-01-30 22:20:50 -05:00
Ben Johnson
149d48fb9e Fix leaf/branch deserialization. 2014-01-30 00:11:46 -05:00
Ben Johnson
4ad445aa85 Add freelist page type. 2014-01-29 22:50:29 -05:00
Ben Johnson
4fc84daf2a Refactor meta.copy() and page.init(). 2014-01-29 22:35:58 -05:00
Ben Johnson
bb7a93f750 Add tpage.read() test. 2014-01-28 16:18:16 -05:00
Ben Johnson
ef590ecdfb lpage 2014-01-27 22:22:37 -05:00
Ben Johnson
192649f453 Intermediate. 2014-01-27 10:11:54 -05:00
Ben Johnson
1baa6d576a Initialize transaction/rwtransaction. 2014-01-26 15:29:06 -07: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
cec7b942e7 Add system buckets. 2014-01-14 13:01:02 -07:00
Ben Johnson
79d9b6bb5a Begin Transaction.Cursor(). 2014-01-13 10:35:04 -07:00
Ben Johnson
f1d7fe5b08 Finish open coverage. 2014-01-13 08:25:56 -07:00
Ben Johnson
ee24437bfc Initial db.open. 2014-01-11 22:51:01 -07:00
Ben Johnson
df8333328f DB.Open(), pages, and meta. 2014-01-10 07:32:12 -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