Skip to content

Commit

Permalink
Merge pull request #6762 from filecoin-project/feat/splitstore-exposed
Browse files Browse the repository at this point in the history
Implement exposed splitstore
  • Loading branch information
magik6k authored Jul 15, 2021
2 parents f07a370 + e003203 commit 25cd577
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 1 deletion.
114 changes: 114 additions & 0 deletions blockstore/splitstore/splitstore_expose.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package splitstore

import (
"context"
"errors"

blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"

bstore "github.com/filecoin-project/lotus/blockstore"
)

type exposedSplitStore struct {
s *SplitStore
}

var _ bstore.Blockstore = (*exposedSplitStore)(nil)

func (s *SplitStore) Expose() bstore.Blockstore {
return &exposedSplitStore{s: s}
}

func (es *exposedSplitStore) DeleteBlock(_ cid.Cid) error {
return errors.New("DeleteBlock: operation not supported")
}

func (es *exposedSplitStore) DeleteMany(_ []cid.Cid) error {
return errors.New("DeleteMany: operation not supported")
}

func (es *exposedSplitStore) Has(c cid.Cid) (bool, error) {
if isIdentiyCid(c) {
return true, nil
}

has, err := es.s.hot.Has(c)
if has || err != nil {
return has, err
}

return es.s.cold.Has(c)
}

func (es *exposedSplitStore) Get(c cid.Cid) (blocks.Block, error) {
if isIdentiyCid(c) {
data, err := decodeIdentityCid(c)
if err != nil {
return nil, err
}

return blocks.NewBlockWithCid(data, c)
}

blk, err := es.s.hot.Get(c)
switch err {
case bstore.ErrNotFound:
return es.s.cold.Get(c)
default:
return blk, err
}
}

func (es *exposedSplitStore) GetSize(c cid.Cid) (int, error) {
if isIdentiyCid(c) {
data, err := decodeIdentityCid(c)
if err != nil {
return 0, err
}

return len(data), nil
}

size, err := es.s.hot.GetSize(c)
switch err {
case bstore.ErrNotFound:
return es.s.cold.GetSize(c)
default:
return size, err
}
}

func (es *exposedSplitStore) Put(blk blocks.Block) error {
return es.s.Put(blk)
}

func (es *exposedSplitStore) PutMany(blks []blocks.Block) error {
return es.s.PutMany(blks)
}

func (es *exposedSplitStore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) {
return es.s.AllKeysChan(ctx)
}

func (es *exposedSplitStore) HashOnRead(enabled bool) {}

func (es *exposedSplitStore) View(c cid.Cid, f func([]byte) error) error {
if isIdentiyCid(c) {
data, err := decodeIdentityCid(c)
if err != nil {
return err
}

return f(data)
}

err := es.s.hot.View(c, f)
switch err {
case bstore.ErrNotFound:
return es.s.cold.View(c, f)

default:
return err
}
}
2 changes: 1 addition & 1 deletion node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func Repo(r repo.Repo) Option {
Override(new(dtypes.BasicChainBlockstore), modules.ChainSplitBlockstore),
Override(new(dtypes.BasicStateBlockstore), modules.StateSplitBlockstore),
Override(new(dtypes.BaseBlockstore), From(new(dtypes.SplitBlockstore))),
Override(new(dtypes.ExposedBlockstore), From(new(dtypes.SplitBlockstore))),
Override(new(dtypes.ExposedBlockstore), modules.ExposedSplitBlockstore),
),
If(!cfg.EnableSplitstore,
Override(new(dtypes.BasicChainBlockstore), modules.ChainFlatBlockstore),
Expand Down
4 changes: 4 additions & 0 deletions node/modules/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func SplitBlockstore(cfg *config.Chainstore) func(lc fx.Lifecycle, r repo.Locked
}
}

func ExposedSplitBlockstore(_ fx.Lifecycle, s dtypes.SplitBlockstore) dtypes.ExposedBlockstore {
return s.(*splitstore.SplitStore).Expose()
}

func StateFlatBlockstore(_ fx.Lifecycle, _ helpers.MetricsCtx, bs dtypes.UniversalBlockstore) (dtypes.BasicStateBlockstore, error) {
return bs, nil
}
Expand Down

0 comments on commit 25cd577

Please sign in to comment.