consolidate blockstore utils.
This commit is contained in:
parent
3be2681824
commit
7e02868ce2
33
markets/dagstore/blockstore.go
Normal file
33
markets/dagstore/blockstore.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package dagstore
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
|
blocks "github.com/ipfs/go-block-format"
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
|
bstore "github.com/ipfs/go-ipfs-blockstore"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/dagstore"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Blockstore promotes a dagstore.ReadBlockstore to a full closeable Blockstore,
|
||||||
|
// stubbing out the write methods with erroring implementations.
|
||||||
|
type Blockstore struct {
|
||||||
|
dagstore.ReadBlockstore
|
||||||
|
io.Closer
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ bstore.Blockstore = (*Blockstore)(nil)
|
||||||
|
|
||||||
|
func (b *Blockstore) DeleteBlock(c cid.Cid) error {
|
||||||
|
return xerrors.Errorf("DeleteBlock called but not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Blockstore) Put(block blocks.Block) error {
|
||||||
|
return xerrors.Errorf("Put called but not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Blockstore) PutMany(blocks []blocks.Block) error {
|
||||||
|
return xerrors.Errorf("PutMany called but not implemented")
|
||||||
|
}
|
@ -1,33 +0,0 @@
|
|||||||
package dagstore
|
|
||||||
|
|
||||||
import (
|
|
||||||
blocks "github.com/ipfs/go-block-format"
|
|
||||||
"github.com/ipfs/go-cid"
|
|
||||||
bstore "github.com/ipfs/go-ipfs-blockstore"
|
|
||||||
"golang.org/x/xerrors"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/dagstore"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ReadOnlyBlockstore stubs out Blockstore mutators with methods that error out
|
|
||||||
type ReadOnlyBlockstore struct {
|
|
||||||
dagstore.ReadBlockstore
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewReadOnlyBlockstore(rbs dagstore.ReadBlockstore) bstore.Blockstore {
|
|
||||||
return ReadOnlyBlockstore{ReadBlockstore: rbs}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r ReadOnlyBlockstore) DeleteBlock(c cid.Cid) error {
|
|
||||||
return xerrors.Errorf("DeleteBlock called but not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r ReadOnlyBlockstore) Put(block blocks.Block) error {
|
|
||||||
return xerrors.Errorf("Put called but not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r ReadOnlyBlockstore) PutMany(blocks []blocks.Block) error {
|
|
||||||
return xerrors.Errorf("PutMany called but not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ bstore.Blockstore = (*ReadOnlyBlockstore)(nil)
|
|
@ -3,14 +3,12 @@ package dagstore
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/filecoin-project/dagstore/index"
|
"github.com/filecoin-project/dagstore/index"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
ds "github.com/ipfs/go-datastore"
|
ds "github.com/ipfs/go-datastore"
|
||||||
bstore "github.com/ipfs/go-ipfs-blockstore"
|
|
||||||
logging "github.com/ipfs/go-log/v2"
|
logging "github.com/ipfs/go-log/v2"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
@ -46,11 +44,6 @@ type DAGStore interface {
|
|||||||
Start(ctx context.Context) error
|
Start(ctx context.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type closableBlockstore struct {
|
|
||||||
bstore.Blockstore
|
|
||||||
io.Closer
|
|
||||||
}
|
|
||||||
|
|
||||||
type Wrapper struct {
|
type Wrapper struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
@ -216,7 +209,7 @@ func (ds *Wrapper) LoadShard(ctx context.Context, pieceCid cid.Cid) (carstore.Cl
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("successfully loaded blockstore for piece CID %s", pieceCid)
|
log.Debugf("successfully loaded blockstore for piece CID %s", pieceCid)
|
||||||
return &closableBlockstore{Blockstore: NewReadOnlyBlockstore(bs), Closer: res.Accessor}, nil
|
return &Blockstore{ReadBlockstore: bs, Closer: res.Accessor}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *Wrapper) RegisterShard(ctx context.Context, pieceCid cid.Cid, carPath string, eagerInit bool, resch chan dagstore.ShardResult) error {
|
func (ds *Wrapper) RegisterShard(ctx context.Context, pieceCid cid.Cid, carPath string, eagerInit bool, resch chan dagstore.ShardResult) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user