Skip to content

Commit

Permalink
Update to context datastores
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Dec 10, 2021
1 parent e6f2442 commit 0ddf813
Show file tree
Hide file tree
Showing 4 changed files with 527 additions and 94 deletions.
12 changes: 6 additions & 6 deletions v2/blockstore/readonly.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ func (b *ReadOnly) readBlock(idx int64) (cid.Cid, []byte, error) {
}

// DeleteBlock is unsupported and always errors.
func (b *ReadOnly) DeleteBlock(_ cid.Cid) error {
func (b *ReadOnly) DeleteBlock(_ context.Context, _ cid.Cid) error {
return errReadOnly
}

// Has indicates if the store contains a block that corresponds to the given key.
// This function always returns true for any given key with multihash.IDENTITY code.
func (b *ReadOnly) Has(key cid.Cid) (bool, error) {
func (b *ReadOnly) Has(ctx context.Context, key cid.Cid) (bool, error) {
// Check if the given CID has multihash.IDENTITY code
// Note, we do this without locking, since there is no shared information to lock for in order to perform the check.
if _, ok, err := isIdentity(key); err != nil {
Expand Down Expand Up @@ -241,7 +241,7 @@ func (b *ReadOnly) Has(key cid.Cid) (bool, error) {

// Get gets a block corresponding to the given key.
// This API will always return true if the given key has multihash.IDENTITY code.
func (b *ReadOnly) Get(key cid.Cid) (blocks.Block, error) {
func (b *ReadOnly) Get(ctx context.Context, key cid.Cid) (blocks.Block, error) {
// Check if the given CID has multihash.IDENTITY code
// Note, we do this without locking, since there is no shared information to lock for in order to perform the check.
if digest, ok, err := isIdentity(key); err != nil {
Expand Down Expand Up @@ -293,7 +293,7 @@ func (b *ReadOnly) Get(key cid.Cid) (blocks.Block, error) {
}

// GetSize gets the size of an item corresponding to the given key.
func (b *ReadOnly) GetSize(key cid.Cid) (int, error) {
func (b *ReadOnly) GetSize(ctx context.Context, key cid.Cid) (int, error) {
// Check if the given CID has multihash.IDENTITY code
// Note, we do this without locking, since there is no shared information to lock for in order to perform the check.
if digest, ok, err := isIdentity(key); err != nil {
Expand Down Expand Up @@ -361,12 +361,12 @@ func isIdentity(key cid.Cid) (digest []byte, ok bool, err error) {
}

// Put is not supported and always returns an error.
func (b *ReadOnly) Put(blocks.Block) error {
func (b *ReadOnly) Put(context.Context, blocks.Block) error {
return errReadOnly
}

// PutMany is not supported and always returns an error.
func (b *ReadOnly) PutMany([]blocks.Block) error {
func (b *ReadOnly) PutMany(context.Context, []blocks.Block) error {
return errReadOnly
}

Expand Down
20 changes: 10 additions & 10 deletions v2/blockstore/readwrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,14 @@ func (b *ReadWrite) unfinalize() error {
}

// Put puts a given block to the underlying datastore
func (b *ReadWrite) Put(blk blocks.Block) error {
func (b *ReadWrite) Put(ctx context.Context, blk blocks.Block) error {
// PutMany already checks b.ronly.closed.
return b.PutMany([]blocks.Block{blk})
return b.PutMany(ctx, []blocks.Block{blk})
}

// PutMany puts a slice of blocks at the same time using batching
// capabilities of the underlying datastore whenever possible.
func (b *ReadWrite) PutMany(blks []blocks.Block) error {
func (b *ReadWrite) PutMany(ctx context.Context, blks []blocks.Block) error {
b.ronly.mu.Lock()
defer b.ronly.mu.Unlock()

Expand Down Expand Up @@ -393,19 +393,19 @@ func (b *ReadWrite) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) {
return b.ronly.AllKeysChan(ctx)
}

func (b *ReadWrite) Has(key cid.Cid) (bool, error) {
return b.ronly.Has(key)
func (b *ReadWrite) Has(ctx context.Context, key cid.Cid) (bool, error) {
return b.ronly.Has(ctx, key)
}

func (b *ReadWrite) Get(key cid.Cid) (blocks.Block, error) {
return b.ronly.Get(key)
func (b *ReadWrite) Get(ctx context.Context, key cid.Cid) (blocks.Block, error) {
return b.ronly.Get(ctx, key)
}

func (b *ReadWrite) GetSize(key cid.Cid) (int, error) {
return b.ronly.GetSize(key)
func (b *ReadWrite) GetSize(ctx context.Context, key cid.Cid) (int, error) {
return b.ronly.GetSize(ctx, key)
}

func (b *ReadWrite) DeleteBlock(_ cid.Cid) error {
func (b *ReadWrite) DeleteBlock(_ context.Context, _ cid.Cid) error {
return fmt.Errorf("ReadWrite blockstore does not support deleting blocks")
}

Expand Down
6 changes: 3 additions & 3 deletions v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ go 1.16
require (
github.com/ipfs/go-block-format v0.0.3
github.com/ipfs/go-cid v0.1.0
github.com/ipfs/go-ipfs-blockstore v1.0.3
github.com/ipfs/go-ipfs-blockstore v1.1.2
github.com/ipfs/go-ipld-cbor v0.0.5
github.com/ipfs/go-ipld-format v0.2.0
github.com/ipfs/go-merkledag v0.3.2
github.com/ipfs/go-merkledag v0.5.1
github.com/ipld/go-codec-dagpb v1.3.0
github.com/ipld/go-ipld-prime v0.14.0
github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20211119015904-892d2f92ba8b
github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20211210233348-792631ef5aa0
github.com/multiformats/go-multicodec v0.3.1-0.20210902112759-1539a079fd61
github.com/multiformats/go-multihash v0.1.0
github.com/multiformats/go-varint v0.0.6
Expand Down
Loading

0 comments on commit 0ddf813

Please sign in to comment.