From a2359c57ab8e09961dce6664663ae5ff79fa335c Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 11 Jun 2021 23:08:48 +0300 Subject: [PATCH 1/2] noop blockstore --- blockstore/noop.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 blockstore/noop.go diff --git a/blockstore/noop.go b/blockstore/noop.go new file mode 100644 index 00000000000..f2658cbd739 --- /dev/null +++ b/blockstore/noop.go @@ -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 +} From 832e6f1b7e632d1d169b757c15d02cbc45cc3115 Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 11 Jun 2021 23:22:20 +0300 Subject: [PATCH 2/2] hook noop blockstore for splitstore in DI --- node/builder.go | 4 ++++ node/config/def.go | 4 +++- node/modules/blockstore.go | 8 ++++++-- node/modules/dtypes/storage.go | 5 ++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/node/builder.go b/node/builder.go index f05dd81649d..5f52c6ccdc3 100644 --- a/node/builder.go +++ b/node/builder.go @@ -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)), diff --git a/node/config/def.go b/node/config/def.go index af799f702ab..6819a5cba44 100644 --- a/node/config/def.go +++ b/node/config/def.go @@ -187,6 +187,7 @@ type Chainstore struct { } type Splitstore struct { + ColdStoreType string HotStoreType string TrackingStoreType string MarkSetType string @@ -263,7 +264,8 @@ func DefaultFullNode() *FullNode { Chainstore: Chainstore{ EnableSplitstore: false, Splitstore: Splitstore{ - HotStoreType: "badger", + ColdStoreType: "universal", + HotStoreType: "badger", }, }, } diff --git a/node/modules/blockstore.go b/node/modules/blockstore.go index 787d782b7ea..6dd776999da 100644 --- a/node/modules/blockstore.go +++ b/node/modules/blockstore.go @@ -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 { @@ -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 diff --git a/node/modules/dtypes/storage.go b/node/modules/dtypes/storage.go index e35d02811a7..8d82006b752 100644 --- a/node/modules/dtypes/storage.go +++ b/node/modules/dtypes/storage.go @@ -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