-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Conversation
Haven't looked at the code yet, but a thought invoked by your excellent writeup: It seems a bit too easy to delete "buckets of data" by accidentally overwriting the bucket key with a simple value. Maybe consider treating it as an error instead, i.e. you need to explicitly delete the bucket before you can reuse the key for simple value. FWIW it would be similar to directories and files that way |
@mkobetic That's a good point. I'll change it to disallow overwrite by different value types. |
@mkobetic I changed Put() and Delete() to return I added a bunch of test coverage for everything and fixed some bugs today. I'm feeling pretty good about it now. Tomorrow I'll add nested buckets to the randomized tests, add an importer/exporter, and then merge the PR. /cc @snormore |
This commit adds the ability to create buckets inside of other buckets. It also replaces the buckets page with a root bucket. Fixes boltdb#56.
Conflicts: db_test.go tx_test.go
I updated the PR comment to show how to upgrade existing Bolt databases to the "Version 2" format and I documented the new API. I rewrote the randomized testing yesterday and I found some deadlock issues so those are fixed. I also fixed #101 while I was in there. I've gone through and reviewed the PR several times and it seems to be pretty solid. |
I don't see in the docs or in the tests how to traverse the bucket trees (i.e. nested buckets). It seems when cursor or ForEach hits upon a sub-bucket key it returns the value as nil. Is that the only case where you can get nil; i.e., if you see nil value in that context is that guaranteed to be a subbucket? And then how do you access the sub-bucket to traverse it? ~~~I guess it's actually stored at the root level of the db? Meaning all buckets actually share that one namespace and you have to worry about naming collisions among all subbuckets and top level buckets? Sorry if this is a stupid question. I'd be happy to work on embellishing the documentation with this stuff if you welcome contributions like that.~~~ Awesome software btw, thank you for open sourcing :) |
http://godoc.org/github.com/boltdb/bolt#Cursor http://godoc.org/github.com/boltdb/bolt#Bucket.Bucket |
Oh, right, Bucket.Bucket. Thanks. |
Overview
This pull request adds the ability to nest buckets inside of other buckets. It also replaces the buckets page with a root bucket. This pull request looks bigger than it is. It's mostly moving a lot of
Tx
functionality over to theBucket
.API Changes
Previously, the ability to create, retrieve, and delete buckets was entirely in
Tx
andbuckets
. This made sense because buckets were a top-level construct. Now that buckets can exist inside other buckets, all this functionality has moved into theBucket
type.Buckets and simple byte slice values all exist in the same keyspace. However, trying to create a bucket named
foo
and simple value with thefoo
key will return anErrIncompatibleValue
error.New Bucket functions:
Changes in Bucket functions:
Bucket.Get()
returnsnil
when a bucket key is provided.Bucket.Put()
returnsErrIncompatibleValue
when putting to an existing bucket key.Bucket.Delete()
returnsErrIncompatibleValue
when deleting an existing bucket key.Tx functions
All the previous Tx bucket functions still exist and simply wrap the root bucket's same functions:
However, since buckets are in the regular keyspace, their names are byte slices instead of strings.
File Format Changes
Allowing buckets to be nested made the
buckets
page redundant. Now, instead of a specialized page type, there is a root bucket that theTx
uses to find and create top-level buckets. This root bucket is only accessible to theTx
so it only stores buckets (e.g. no simple byte slice values).Because of this change, older Bolt databases are not compatible after this pull request is merged. I'll be merging in an import/export tool through a separate PR before this pull request is merged. That will allow databases to be exported to a generalized JSON format and imported into a new version of Bolt.
The data format
version
has been bumped to2
with this PR. Opening previous data format versions of the database will returnErrVersionMismatch
error.Upgrading
To upgrade a Bolt database that uses the previous version (
1
), you'll need to install Bolt from thedata/v1
tag:Then install Bolt from
master
:Now you can swap out your old database:
Other Notes
This pull request lacks a few optimizations that will be coming in future PRs:
< pageSize
) to be written with their data into the same value that theirbucket
header exists.Bucket
for access. This is mostly to track nodes for each bucket but that shouldn't be required for read-only transactions. Tweaking this should make iteration faster for nested buckets.Fixes #56.
/cc @tv42 @snormore @mkobetic