-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement initial read-only blockstore #88
Conversation
Refactor the carbon and carbs packages into a read-only blockstore. Move the packages to `internal` as needed and remove duplicate reader implementations. Improve serialization efficiency for car v2 primitives. Note the readonly blockstore will be altered in the coming PRs to understand car v2 format and work transparently. For now we want to push the refactoring and changes to unblock other parallel workstreams.
v2/blockstore/ro_blockstore.go
Outdated
// ReadOnlyBlockStore provides a read-only Car Block Store. | ||
ReadOnlyBlockStore struct { | ||
backing io.ReaderAt | ||
idx index.Index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably want a non-internal Index type - it sounds like the sharded blockstore would like to be able to detach indexes to store them separate from cars, and also be able to recombine a carv1 + index into a carv2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v2/blockstore/ro_blockstore.go
Outdated
} | ||
|
||
// AllKeysChan returns the list of keys in the store | ||
func (b *ReadOnlyBlockStore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may use this walk for populating the index, and we need to be able to iterate keys in this way somewhere for index generation. In general though, when it's asked for all keys from a blockstore with an index, we should iterate through the index when possible rather than linear reads through the full car.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added TODO thank you for pointing this out
v2/blockstore/ro_blockstore.go
Outdated
@@ -0,0 +1,190 @@ | |||
package blockstore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this package is called blockstore, so I think blockstore/readonly.go is slightly better than blockstore/ro_blockstore.go
v2/blockstore/ro_blockstore.go
Outdated
"encoding/binary" | ||
"errors" | ||
"fmt" | ||
"golang.org/x/exp/mmap" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: not a std import, shouldn't be in this group
v2/blockstore/ro_blockstore.go
Outdated
// errUnsupported is returned for unsupported operations | ||
var errUnsupported = errors.New("unsupported operation") | ||
|
||
type ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any particular reason you use ()
groups for single types? consistency? it does add two lines for very little benefit, so I'd probably avoid it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
face of habit I usually do this to group type declarations
v2/internal/carbon/carbon_fds.go
Outdated
@@ -14,8 +15,8 @@ import ( | |||
type carbonFD struct { | |||
path string | |||
writeHandle *poswriter | |||
carbs.BlockStore | |||
idx *insertionIndex | |||
blockstore.ReadOnlyBlockStore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like the filename, I wonder if this type stutters a bit. blockstore.ReadOnly
is pretty good, or if you still prefer to clarify what it is, maybe blockstore.ReadOnlyStore
?
also, nit: I'm pretty sure the go-ipfs-blockstore package uses the name Blockstore, not BlockStore (note the lack of capitalization of Store), so I think go-car should be consistent too. Maybe its name is a historical typo/mistake, but best to not confuse things further with multiple spellings.
v2/writer.go
Outdated
@@ -3,12 +3,12 @@ package car | |||
import ( | |||
"bytes" | |||
"context" | |||
"github.com/ipld/go-car/v2/internal/index" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm :) maybe run goimports or gofumpt on all the files to make sure you're not mixing things into the std group?
- Sort imports - Rename types for clarity - Add TODO for future PRs
The inclusion of |
noted here ipfs/go-cid#126 |
ReadOnlyBlockstore
as provided bycarbs
.Note, future PRs will adjust the read-only blockstore to accept CAR v2 format and work transparently.