diff --git a/cmd/lotus-shed/invariants.go b/cmd/lotus-shed/invariants.go index e74a0dd24c2..0342d8b625f 100644 --- a/cmd/lotus-shed/invariants.go +++ b/cmd/lotus-shed/invariants.go @@ -3,10 +3,14 @@ package main import ( "context" "fmt" - "io" + "os" + "path/filepath" "strconv" "time" + badgerbs "github.com/filecoin-project/lotus/blockstore/badger" + "github.com/filecoin-project/lotus/blockstore/splitstore" + "github.com/ipfs/go-cid" "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -73,24 +77,52 @@ var invariantsCmd = &cli.Command{ defer lkrepo.Close() //nolint:errcheck - bs, err := lkrepo.Blockstore(ctx, repo.UniversalBlockstore) + cold, err := lkrepo.Blockstore(ctx, repo.UniversalBlockstore) if err != nil { - return fmt.Errorf("failed to open blockstore: %w", err) + return fmt.Errorf("failed to open universal blockstore %w", err) } - defer func() { - if c, ok := bs.(io.Closer); ok { - if err := c.Close(); err != nil { - log.Warnf("failed to close blockstore: %s", err) - } - } - }() + path, err := lkrepo.SplitstorePath() + if err != nil { + return err + } + + path = filepath.Join(path, "hot.badger") + if err := os.MkdirAll(path, 0755); err != nil { + return err + } + + opts, err := repo.BadgerBlockstoreOptions(repo.HotBlockstore, path, lkrepo.Readonly()) + if err != nil { + return err + } + + hot, err := badgerbs.Open(opts) + if err != nil { + return err + } mds, err := lkrepo.Datastore(context.Background(), "/metadata") if err != nil { return err } + cfg := &splitstore.Config{ + MarkSetType: "map", + DiscardColdBlocks: true, + } + ss, err := splitstore.Open(path, mds, hot, cold, cfg) + if err != nil { + return err + } + defer func() { + if err := ss.Close(); err != nil { + log.Warnf("failed to close blockstore: %s", err) + + } + }() + bs := ss + cs := store.NewChainStore(bs, bs, mds, filcns.Weight, nil) defer cs.Close() //nolint:errcheck