Skip to content
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

Noop coldstore for splitstore #6458

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions blockstore/noop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package blockstore

import (
"context"
"io"

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

var _ Blockstore = (*noopstore)(nil)

type noopstore struct {
bs Blockstore
}

func NewNoopStore(bs Blockstore) Blockstore {
return &noopstore{bs: bs}
}

func (b *noopstore) Has(cid cid.Cid) (bool, error) {
return b.bs.Has(cid)
}

func (b *noopstore) HashOnRead(hor bool) {
b.bs.HashOnRead(hor)
}

func (b *noopstore) Get(cid cid.Cid) (blocks.Block, error) {
return b.bs.Get(cid)
}

func (b *noopstore) GetSize(cid cid.Cid) (int, error) {
return b.bs.GetSize(cid)
}

func (b *noopstore) View(cid cid.Cid, f func([]byte) error) error {
return b.bs.View(cid, f)
}

func (b *noopstore) Put(blk blocks.Block) error {
return nil
}

func (b *noopstore) PutMany(blks []blocks.Block) error {
return nil
}

func (b *noopstore) DeleteBlock(cid cid.Cid) error {
return nil
}

func (b *noopstore) DeleteMany(cids []cid.Cid) error {
return nil
}

func (b *noopstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) {
return b.bs.AllKeysChan(ctx)
}

func (b *noopstore) Close() error {
if c, ok := b.bs.(io.Closer); ok {
return c.Close()
}
return nil
}
4 changes: 4 additions & 0 deletions node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ func Repo(r repo.Repo) Option {
Override(new(dtypes.UniversalBlockstore), modules.UniversalBlockstore),

If(cfg.EnableSplitstore,
If(cfg.Splitstore.ColdStoreType == "universal",
Override(new(dtypes.ColdBlockstore), From(new(dtypes.UniversalBlockstore)))),
If(cfg.Splitstore.ColdStoreType == "noop",
Override(new(dtypes.ColdBlockstore), modules.NoopColdBlockstore)),
If(cfg.Splitstore.HotStoreType == "badger",
Override(new(dtypes.HotBlockstore), modules.BadgerHotBlockstore)),
Override(new(dtypes.SplitBlockstore), modules.SplitBlockstore(cfg)),
Expand Down
4 changes: 3 additions & 1 deletion node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ type Chainstore struct {
}

type Splitstore struct {
ColdStoreType string
HotStoreType string
TrackingStoreType string
MarkSetType string
Expand Down Expand Up @@ -263,7 +264,8 @@ func DefaultFullNode() *FullNode {
Chainstore: Chainstore{
EnableSplitstore: false,
Splitstore: Splitstore{
HotStoreType: "badger",
ColdStoreType: "universal",
HotStoreType: "badger",
},
},
}
Expand Down
8 changes: 6 additions & 2 deletions node/modules/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func UniversalBlockstore(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.Locked
return bs, err
}

func NoopColdBlockstore(lc fx.Lifecycle, bs dtypes.UniversalBlockstore) (dtypes.ColdBlockstore, error) {
return blockstore.NewNoopStore(bs), nil
}

func BadgerHotBlockstore(lc fx.Lifecycle, r repo.LockedRepo) (dtypes.HotBlockstore, error) {
path, err := r.SplitstorePath()
if err != nil {
Expand Down Expand Up @@ -66,8 +70,8 @@ func BadgerHotBlockstore(lc fx.Lifecycle, r repo.LockedRepo) (dtypes.HotBlocksto
return bs, nil
}

func SplitBlockstore(cfg *config.Chainstore) func(lc fx.Lifecycle, r repo.LockedRepo, ds dtypes.MetadataDS, cold dtypes.UniversalBlockstore, hot dtypes.HotBlockstore) (dtypes.SplitBlockstore, error) {
return func(lc fx.Lifecycle, r repo.LockedRepo, ds dtypes.MetadataDS, cold dtypes.UniversalBlockstore, hot dtypes.HotBlockstore) (dtypes.SplitBlockstore, error) {
func SplitBlockstore(cfg *config.Chainstore) func(lc fx.Lifecycle, r repo.LockedRepo, ds dtypes.MetadataDS, cold dtypes.ColdBlockstore, hot dtypes.HotBlockstore) (dtypes.SplitBlockstore, error) {
return func(lc fx.Lifecycle, r repo.LockedRepo, ds dtypes.MetadataDS, cold dtypes.ColdBlockstore, hot dtypes.HotBlockstore) (dtypes.SplitBlockstore, error) {
path, err := r.SplitstorePath()
if err != nil {
return nil, err
Expand Down
5 changes: 4 additions & 1 deletion node/modules/dtypes/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ import (
type MetadataDS datastore.Batching

type (
// UniversalBlockstore is the cold blockstore.
// UniversalBlockstore is the universal blockstore backend.
UniversalBlockstore blockstore.Blockstore

// ColdBlockstore is the Cold blockstore abstraction for the splitstore
ColdBlockstore blockstore.Blockstore

// HotBlockstore is the Hot blockstore abstraction for the splitstore
HotBlockstore blockstore.Blockstore

Expand Down