-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dagstore lotus mount Implementation with tests (#564)
* dagstore lotus mount impl * refactor: nicer error messages * mount api tests * refactor: integrate dag store (#565) Co-authored-by: Dirk McCormick <[email protected]>
- Loading branch information
1 parent
07597f8
commit 92e827d
Showing
30 changed files
with
848 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package dagstore | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"github.com/ipfs/go-cid" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/filecoin-project/dagstore" | ||
"github.com/filecoin-project/dagstore/mount" | ||
"github.com/filecoin-project/dagstore/shard" | ||
|
||
"github.com/filecoin-project/go-fil-markets/carstore" | ||
) | ||
|
||
// DagStoreWrapper hides the details of the DAG store implementation from | ||
// the other parts of go-fil-markets | ||
type DagStoreWrapper interface { | ||
// RegisterShard loads a CAR file into the DAG store and builds an index for it | ||
RegisterShard(ctx context.Context, pieceCid cid.Cid, carPath string) error | ||
// LoadShard fetches the data for a shard and provides a blockstore interface to it | ||
LoadShard(ctx context.Context, pieceCid cid.Cid) (carstore.ClosableBlockstore, error) | ||
} | ||
|
||
type dagStoreWrapper struct { | ||
dagStore *dagstore.DAGStore | ||
mountApi LotusMountAPI | ||
} | ||
|
||
func NewDagStoreWrapper(dsRegistry *mount.Registry, dagStore *dagstore.DAGStore, mountApi LotusMountAPI) (*dagStoreWrapper, error) { | ||
err := dsRegistry.Register(lotusScheme, NewLotusMountTemplate(mountApi)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &dagStoreWrapper{ | ||
dagStore: dagStore, | ||
mountApi: mountApi, | ||
}, nil | ||
} | ||
|
||
type closableBlockstore struct { | ||
dagstore.ReadBlockstore | ||
io.Closer | ||
} | ||
|
||
func (ds *dagStoreWrapper) LoadShard(ctx context.Context, pieceCid cid.Cid) (carstore.ClosableBlockstore, error) { | ||
key := shard.KeyFromCID(pieceCid) | ||
resch := make(chan dagstore.ShardResult, 1) | ||
err := ds.dagStore.AcquireShard(ctx, key, resch, dagstore.AcquireOpts{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// TODO: Can I rely on AcquireShard to return an error if the context times out? | ||
//select { | ||
//case <-ctx.Done(): | ||
// return ctx.Err() | ||
//case res := <-resch: | ||
// return nil, res.Error | ||
//} | ||
|
||
res := <-resch | ||
if res.Error != nil { | ||
return nil, res.Error | ||
} | ||
|
||
bs, err := res.Accessor.Blockstore() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &closableBlockstore{ReadBlockstore: bs, Closer: res.Accessor}, nil | ||
} | ||
|
||
func (ds *dagStoreWrapper) RegisterShard(ctx context.Context, pieceCid cid.Cid, carPath string) error { | ||
key := shard.KeyFromCID(pieceCid) | ||
mt, err := NewLotusMount(pieceCid, ds.mountApi) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
opts := dagstore.RegisterOpts{ExistingTransient: carPath} | ||
resch := make(chan dagstore.ShardResult, 1) | ||
err = ds.dagStore.RegisterShard(ctx, key, mt, resch, opts) | ||
if err != nil { | ||
return xerrors.Errorf("failed to register shard for piece %s: %w", pieceCid, err) | ||
} | ||
|
||
// TODO: Can I rely on RegisterShard to return an error if the context times out? | ||
//select { | ||
//case <-ctx.Done(): | ||
// return ctx.Err() | ||
//case res := <-resch: | ||
// return res.Error | ||
//} | ||
|
||
res := <-resch | ||
return res.Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.