-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add caching universal blockstore and statestore * Address review comments
- Loading branch information
Showing
6 changed files
with
293 additions
and
6 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
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,49 @@ | ||
package modules | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"github.com/filecoin-project/lotus/node/modules/dtypes" | ||
"github.com/filecoin-project/lotus/node/modules/helpers" | ||
"github.com/filecoin-project/lotus/node/repo" | ||
"go.uber.org/fx" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/filecoin-project/lily/lens/util" | ||
) | ||
|
||
func CacheConfig(blockstoreCacheSize uint, statestoreCacheSize uint) func(lc fx.Lifecycle, mctx helpers.MetricsCtx) (*util.CacheConfig, error) { | ||
return func(lc fx.Lifecycle, mctx helpers.MetricsCtx) (*util.CacheConfig, error) { | ||
return &util.CacheConfig{ | ||
BlockstoreCacheSize: blockstoreCacheSize, | ||
StatestoreCacheSize: statestoreCacheSize, | ||
}, nil | ||
} | ||
} | ||
|
||
func NewCachingUniversalBlockstore(lc fx.Lifecycle, mctx helpers.MetricsCtx, cc *util.CacheConfig, r repo.LockedRepo) (dtypes.UniversalBlockstore, error) { | ||
bs, err := r.Blockstore(helpers.LifecycleCtx(mctx, lc), repo.UniversalBlockstore) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if c, ok := bs.(io.Closer); ok { | ||
lc.Append(fx.Hook{ | ||
OnStop: func(_ context.Context) error { | ||
return c.Close() | ||
}, | ||
}) | ||
} | ||
|
||
if cc.BlockstoreCacheSize == 0 { | ||
return bs, nil | ||
} | ||
|
||
log.Infof("creating caching blockstore with size=%d", cc.BlockstoreCacheSize) | ||
cbs, err := util.NewCachingBlockstore(bs, int(cc.BlockstoreCacheSize)) | ||
if err != nil { | ||
return nil, xerrors.Errorf("failed to create caching blockstore: %v", err) | ||
} | ||
|
||
return cbs, err | ||
} |
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