From ad0a54bc632f4c515546a621997446c6a5aa90f3 Mon Sep 17 00:00:00 2001 From: zenground0 Date: Thu, 30 Mar 2023 14:56:05 -0600 Subject: [PATCH] Open hotstore for migration --- cmd/lotus-shed/migrations.go | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/cmd/lotus-shed/migrations.go b/cmd/lotus-shed/migrations.go index e2a66f0676..bde72468e4 100644 --- a/cmd/lotus-shed/migrations.go +++ b/cmd/lotus-shed/migrations.go @@ -3,7 +3,8 @@ package main import ( "context" "fmt" - "io" + "os" + "path/filepath" "strconv" "time" @@ -32,6 +33,7 @@ import ( "github.com/filecoin-project/specs-actors/v7/actors/migration/nv15" "github.com/filecoin-project/lotus/blockstore" + badgerbs "github.com/filecoin-project/lotus/blockstore/badger" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" lbuiltin "github.com/filecoin-project/lotus/chain/actors/builtin" @@ -102,16 +104,34 @@ var migrationsCmd = &cli.Command{ defer lkrepo.Close() //nolint:errcheck - bs, err := lkrepo.Blockstore(ctx, repo.UniversalBlockstore) + path, err := lkrepo.SplitstorePath() if err != nil { - return fmt.Errorf("failed to open blockstore: %w", err) + 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 + } + + bs, err := badgerbs.Open(opts) + if err != nil { + return err + } + + // bs, err := lkrepo.Blockstore(ctx, repo.UniversalBlockstore) + // if err != nil { + // return fmt.Errorf("failed to open 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) - } + if err := bs.Close(); err != nil { + log.Warnf("failed to close blockstore: %s", err) } }()