Commit Graph

77 Commits (09ff73b9a728580290b782419771e747c275c8e4)

Author SHA1 Message Date
Thomas Jungblut 62e81c036f introduce a freelist interface
This introduces an interface for the freelist, splits it into two concrete
implementations.

fixes etcd-io#773

Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
2024-07-09 10:41:35 +02:00
Benjamin Wang 019c34e51f add method Inspect to inspect bucket structure
Also added a related command: bbolt inspect db

The outputed etcd data structure:
{
    "name": "root",
    "keyN": 0,
    "children": [
        {
            "name": "alarm",
            "keyN": 0
        },
        {
            "name": "auth",
            "keyN": 2
        },
        {
            "name": "authRoles",
            "keyN": 1
        },
        {
            "name": "authUsers",
            "keyN": 1
        },
        {
            "name": "cluster",
            "keyN": 1
        },
        {
            "name": "key",
            "keyN": 1285
        },
        {
            "name": "lease",
            "keyN": 2
        },
        {
            "name": "members",
            "keyN": 1
        },
        {
            "name": "members_removed",
            "keyN": 0
        },
        {
            "name": "meta",
            "keyN": 3
        }
    ]
}

Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
2024-01-11 15:09:58 +00:00
Benjamin Wang 3ed248c4eb Improve CreateBucketIfNotExists to avoid double searching the same key
Benchmark with this change:
BenchmarkBucket_CreateBucketIfNotExists-10    	     123	   9573035 ns/op	   17930 B/op	      37 allocs/op

Benchmark with old implementnation:
BenchmarkBucket_CreateBucketIfNotExists-10    	     121	  10474415 ns/op	   18147 B/op	      46 allocs/op

Signed-off-by: Benjamin Wang <wachao@vmware.com>
2023-08-07 09:54:26 +01:00
Ishan Tyagi c0b6749ca4 Fix tests to open a bbolt database with file mode:0600 instead of 0666.
Signed-off-by: Ishan Tyagi <ishantyagi25@gmail.com>
2023-07-29 18:06:26 +05:30
Marek Siarkowicz a2395be6b8
Merge pull request #452 from jrick/restore_errors
Introduce errors package and restore API compatibility
2023-04-07 10:51:52 +02:00
Josh Rickmar 7a957f94b2 Introduce errors package and restore API compatibility
This moves the error variables that had been moved to the
internal/common package during recent refactoring to a non-internal
errors package, once again allowing consumers to test for particular
error conditions.

To preserve API compatibility with bbolt v1.3, these error variables
are also redefined in the bbolt package, with deprecation notice to
migrate to bbolt/errors.

Signed-off-by: Josh Rickmar <jrick@zettaport.com>
2023-04-06 13:26:30 +00:00
Kishen V a333d9323c Add tests for 64KB block pages.
Added data to support test coverage for environments which use 64KB pages.

Signed-off-by: Kishen V <kishen.viswanathan@ibm.com>
2023-04-06 09:25:33 +05:30
Benjamin Wang ea511567eb refactor both bolt and guts_cli based on the common package
Signed-off-by: Benjamin Wang <wachao@vmware.com>
2023-03-04 04:22:09 +08:00
Piotr Tabor 26cc5e3e8b Tests: Migrate from test DB to btesting.DB
Signed-off-by: Piotr Tabor <ptab@google.com>
2022-12-28 15:18:46 +01:00
Benjamin Wang f8dc40c033 Removed the use of log and reorder the import items
Signed-off-by: Benjamin Wang <wachao@vmware.com>
2022-12-27 13:05:12 +08:00
Piotr Tabor ebca452da7 Add internal iterator to Bucket that goes over buckets.
So far the code was frequently traversing all the keys (ignoring flag whether key is a bucket)
and trying to open each of the keys as bucket (seeking the same entry from the scratch).

In this proposal, we iterate only through bucket keys.

Signed-off-by: Piotr Tabor <ptab@google.com>
2022-12-21 12:16:50 +01:00
Piotr Tabor b09984ea16 Fix bbolt test for 16KB block page (e.g. Mac with M1 CPU).
The tests were failing when doing development on M1 mac. This was due to page-size difference (4KB assumed in tests) vs. the
OS defaults.

Signed-off-by: Piotr Tabor <ptab@google.com>
2022-12-16 19:14:51 +01:00
wpedrak c69165412d Skip few long running tests in `-short` mode 2021-04-23 13:10:08 +02: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
Gyuho Lee 0bff9a461c *: update import paths to "github.com/etcd-io/bbolt"
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
2018-08-27 19:25:01 -07:00
Gyu-Ho Lee c3092301af *: go vet fixes
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
2017-08-11 13:47:10 -07:00
Anthony Romano 9fc2cf177d Merge pull request #23 from heyitsanthony/del-nonexisting
Fix deletion of non-existing keys
2017-08-11 10:43:32 -07:00
Pavel Borzenkov 3c6c3ac0a2 Add a test for deletion of non-existing key
As of now the test fails and tries to delete the next key returned by
the cursor, which happens to be a nested bucket. That's why Delete is
fails.

Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
2017-08-10 23:07:50 -07:00
Anthony Romano 78ca4fde00 get rid of os.Getpagesize() calls where appropriate 2017-08-10 20:46:08 -07:00
Anthony Romano 12923fe56c Merge pull request #12 from heyitsanthony/skip-freelist-overflow
freelist: read all free pages on count overflow
2017-08-10 14:28:08 -07:00
Anthony Romano 1038faf165 test: use qconfig() instead of defaults in TestBucket_Put_Single
Default/nil quick.Config uses 1000 rounds, causing TestBucker_Put_Single to
run for over 3 minutes in CI. The default count (via qconfig()) for boltdb
is 5, so use that.
2017-08-09 00:30:52 -07:00
Anthony Romano f50ad8e90c test: check free page counts on close/reopen for freelist overflow
Confirm that the number of freed pages exceeds the overflow count, then check
that reopening gives the same number of free pages.
2017-08-08 23:37:24 -07:00
Xiang 78b54a42e1 *: use coreos/bbolt as import path 2017-06-20 11:03:31 -07:00
Ben Johnson f5d275b537
Minor bolt compact revisions 2016-09-05 15:43:02 -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
Gyu-Ho Lee 42ab7c097f *: fix test print format 2016-01-08 00:31:45 -08:00
Ben Johnson 8b08bd4a80 test suite refactoring
This commit refactors the test suite to make it cleaner and to use the
standard testing library better. The `assert()`, `equals()`, and `ok()`
functions have been removed and some test names have been changed for
clarity.

No functionality has been changed.
2016-01-02 21:30:31 -07:00
Matthew Dawson a0c33d065b In TestBucket_Delete_FreelistOverflow, use Cursor.Delete to remove records.
When removing all the keys from the bucket, use Cursor.Delete directly, which
avoids a seek through the bucket to find the element to delete.  This knocks
1/5 of the time off my laptop when running this test while not reducing the
amount of overflow pages cleared out of the free list.
2015-10-17 14:04:42 -04:00
Ben Johnson 06e894e661 Fix Drone CI.
This commit ignores the TestBucket_Put_ValueTooLarge test on
Drone CI because the containers do not have enough memory. This
test will still be run by anyone else who runs the test suite so
that will still provide coverage.
2015-06-04 11:48:43 -06:00
Matt Layher 530d83e137 bucket_test: add test for ErrValueTooLarge on insert 2015-05-12 16:35:27 -04:00
Ben Johnson ac1149a3f5 Persist sequence-only changes.
This commit fixes a bug where only calling NextSequence() on a Bucket does not cause the Bucket to be
peristed. The simple fix is to simply materialize the root node so that the bucket is flushed out
during commit.

Thanks to Matthew Dawson (@MJDSys) for reporting.

https://github.com/boltdb/bolt/issues/296
2015-02-02 08:27:34 -07:00
Ben Johnson 44e6192d2b Remove testify. 2014-07-26 17:17:03 -06:00
Ben Johnson ba6badc57f Move tests to a test package. 2014-07-26 15:11:47 -06:00
Ben Johnson ca2339d7cb Remove wrapping test closures. 2014-07-26 14:44:04 -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 ce0754b0d3 Allow freelist overflow.
This commit is a backwards compatible change that allows the freelist to overflow the
page.count (uint16). It works by checking if the overflow will occur and marking the
page.count as 0xFFFF and setting the actual count to the first element of the freelist.

This approach was used because it's backwards compatible and it doesn't make sense to
change the data type of all page counts when only the freelist's page can overflow.

Fixes #192.
2014-07-10 14:50:21 -06:00
Ben Johnson 4f428feecc Merge pull request #208 from benbjohnson/open-timeout
Add Open() options, flock timeout.
2014-06-22 10:10:55 -06:00
Ben Johnson 0f585358f4 Change Bucket.NextSequence() to return uint64.
This commit changes NextSequence() to return a uint64 instead of an int. This also
removes the ErrSequenceOverflow error condition since overflowing a uint64 is unlikely.

Fixes #39.
2014-06-22 09:33:28 -06:00
Ben Johnson 00ee0da528 Add Open() options, flock timeout.
This commit changes Open() to provide an additional Options argument. The options
argument currently only has a Timeout which will cause the Open() to return
ErrTimeout if a file lock cannot be obtained in time.

Fixes #207.
2014-06-21 14:44:28 -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 4db99647eb Fix freelist rollback. 2014-06-13 15:50:47 -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
yosssi a9189ddefb Fix `ExampleBucket_Put` to use `db.View` instead of `db.Update`. 2014-05-31 11:22:50 +09: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 e728eb90da Minor stats fixes. 2014-05-14 12:06:31 -06:00
Martin Kobetic 0716cdaec8 tweaks 2014-05-12 19:33:53 +00:00
Martin Kobetic 0dbfa3f08a merge inline branch into leaf branch 2014-05-12 18:22:45 +00:00