add context to LockedRepo#Datastore().

This commit is contained in:
Raúl Kripalani 2021-01-26 10:25:34 +00:00
parent ce3af308ed
commit a1da1dab85
21 changed files with 42 additions and 29 deletions

View File

@ -134,7 +134,7 @@ func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) {
return nil, xerrors.Errorf("taking mem-repo lock failed: %w", err)
}
ds, err := lr.Datastore("/metadata")
ds, err := lr.Datastore(context.TODO(), "/metadata")
if err != nil {
return nil, xerrors.Errorf("failed to get metadata datastore: %w", err)
}

View File

@ -65,7 +65,7 @@ func BenchmarkGetRandomness(b *testing.B) {
}
}()
mds, err := lr.Datastore("/metadata")
mds, err := lr.Datastore(context.Background(), "/metadata")
if err != nil {
b.Fatal(err)
}

View File

@ -46,7 +46,7 @@ func BackupCmd(repoFlag string, rt repo.RepoType, getApi BackupApiFn) *cli.Comma
}
defer lr.Close() // nolint:errcheck
mds, err := lr.Datastore("/metadata")
mds, err := lr.Datastore(context.TODO(), "/metadata")
if err != nil {
return xerrors.Errorf("getting metadata datastore: %w", err)
}

View File

@ -308,7 +308,7 @@ var runCmd = &cli.Command{
{
// init datastore for r.Exists
_, err := lr.Datastore("/metadata")
_, err := lr.Datastore(context.Background(), "/metadata")
if err != nil {
return err
}
@ -327,7 +327,7 @@ var runCmd = &cli.Command{
log.Error("closing repo", err)
}
}()
ds, err := lr.Datastore("/metadata")
ds, err := lr.Datastore(context.Background(), "/metadata")
if err != nil {
return err
}

View File

@ -188,7 +188,7 @@ var chainBalanceStateCmd = &cli.Command{
}
}()
mds, err := lkrepo.Datastore("/metadata")
mds, err := lkrepo.Datastore(context.Background(), "/metadata")
if err != nil {
return err
}
@ -409,7 +409,7 @@ var chainPledgeCmd = &cli.Command{
}
}()
mds, err := lkrepo.Datastore("/metadata")
mds, err := lkrepo.Datastore(context.Background(), "/metadata")
if err != nil {
return err
}

View File

@ -2,6 +2,7 @@ package main
import (
"bufio"
"context"
"encoding/json"
"fmt"
"io"
@ -75,7 +76,7 @@ var datastoreListCmd = &cli.Command{
}
defer lr.Close() //nolint:errcheck
ds, err := lr.Datastore(datastore.NewKey(cctx.Args().First()).String())
ds, err := lr.Datastore(context.Background(), datastore.NewKey(cctx.Args().First()).String())
if err != nil {
return err
}
@ -141,7 +142,7 @@ var datastoreGetCmd = &cli.Command{
}
defer lr.Close() //nolint:errcheck
ds, err := lr.Datastore(datastore.NewKey(cctx.Args().First()).String())
ds, err := lr.Datastore(context.Background(), datastore.NewKey(cctx.Args().First()).String())
if err != nil {
return err
}

View File

@ -85,7 +85,7 @@ var exportChainCmd = &cli.Command{
}
}()
mds, err := lr.Datastore("/metadata")
mds, err := lr.Datastore(context.Background(), "/metadata")
if err != nil {
return err
}

View File

@ -151,7 +151,7 @@ var stateTreePruneCmd = &cli.Command{
return fmt.Errorf("only badger blockstores are supported")
}
mds, err := lkrepo.Datastore("/metadata")
mds, err := lkrepo.Datastore(context.Background(), "/metadata")
if err != nil {
return err
}

View File

@ -416,7 +416,7 @@ func storageMinerInit(ctx context.Context, cctx *cli.Context, api lapi.FullNode,
return xerrors.Errorf("peer ID from private key: %w", err)
}
mds, err := lr.Datastore("/metadata")
mds, err := lr.Datastore(context.TODO(), "/metadata")
if err != nil {
return err
}

View File

@ -1,6 +1,7 @@
package main
import (
"context"
"encoding/json"
"io/ioutil"
"os"
@ -190,7 +191,7 @@ var initRestoreCmd = &cli.Command{
log.Info("Restoring metadata backup")
mds, err := lr.Datastore("/metadata")
mds, err := lr.Datastore(context.TODO(), "/metadata")
if err != nil {
return err
}

View File

@ -118,7 +118,7 @@ var runCmd = &cli.Command{
var w api.WalletAPI = lw
if cctx.Bool("ledger") {
ds, err := lr.Datastore("/metadata")
ds, err := lr.Datastore(context.Background(), "/metadata")
if err != nil {
return err
}

View File

@ -1,6 +1,7 @@
package main
import (
"context"
"os"
dstore "github.com/ipfs/go-datastore"
@ -87,7 +88,7 @@ func restore(cctx *cli.Context, r repo.Repo) error {
log.Info("Restoring metadata backup")
mds, err := lr.Datastore("/metadata")
mds, err := lr.Datastore(context.TODO(), "/metadata")
if err != nil {
return err
}

View File

@ -437,7 +437,7 @@ func ImportChain(ctx context.Context, r repo.Repo, fname string, snapshot bool)
return xerrors.Errorf("failed to open blockstore: %w", err)
}
mds, err := lr.Datastore("/metadata")
mds, err := lr.Datastore(context.TODO(), "/metadata")
if err != nil {
return err
}

View File

@ -39,6 +39,7 @@ import (
"github.com/filecoin-project/lotus/node/impl/full"
payapi "github.com/filecoin-project/lotus/node/impl/paych"
"github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/node/modules/helpers"
"github.com/filecoin-project/lotus/node/repo"
"github.com/filecoin-project/lotus/node/repo/importmgr"
"github.com/filecoin-project/lotus/node/repo/retrievalstoremgr"
@ -78,8 +79,9 @@ func HandleMigrateClientFunds(lc fx.Lifecycle, ds dtypes.MetadataDS, wallet full
})
}
func ClientMultiDatastore(lc fx.Lifecycle, r repo.LockedRepo) (dtypes.ClientMultiDstore, error) {
ds, err := r.Datastore("/client")
func ClientMultiDatastore(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRepo) (dtypes.ClientMultiDstore, error) {
ctx := helpers.LifecycleCtx(mctx, lc)
ds, err := r.Datastore(ctx, "/client")
if err != nil {
return nil, xerrors.Errorf("getting datastore out of reop: %w", err)
}

View File

@ -8,6 +8,7 @@ import (
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/backupds"
"github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/node/modules/helpers"
"github.com/filecoin-project/lotus/node/repo"
)
@ -27,8 +28,9 @@ func KeyStore(lr repo.LockedRepo) (types.KeyStore, error) {
return lr.KeyStore()
}
func Datastore(r repo.LockedRepo) (dtypes.MetadataDS, error) {
mds, err := r.Datastore("/metadata")
func Datastore(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRepo) (dtypes.MetadataDS, error) {
ctx := helpers.LifecycleCtx(mctx, lc)
mds, err := r.Datastore(ctx, "/metadata")
if err != nil {
return nil, err
}

View File

@ -357,8 +357,9 @@ func NewProviderPieceStore(lc fx.Lifecycle, ds dtypes.MetadataDS) (dtypes.Provid
return ps, nil
}
func StagingMultiDatastore(lc fx.Lifecycle, r repo.LockedRepo) (dtypes.StagingMultiDstore, error) {
ds, err := r.Datastore("/staging")
func StagingMultiDatastore(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRepo) (dtypes.StagingMultiDstore, error) {
ctx := helpers.LifecycleCtx(mctx, lc)
ds, err := r.Datastore(ctx, "/staging")
if err != nil {
return nil, xerrors.Errorf("getting datastore out of reop: %w", err)
}
@ -379,8 +380,9 @@ func StagingMultiDatastore(lc fx.Lifecycle, r repo.LockedRepo) (dtypes.StagingMu
// StagingBlockstore creates a blockstore for staging blocks for a miner
// in a storage deal, prior to sealing
func StagingBlockstore(r repo.LockedRepo) (dtypes.StagingBlockstore, error) {
stagingds, err := r.Datastore("/staging")
func StagingBlockstore(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRepo) (dtypes.StagingBlockstore, error) {
ctx := helpers.LifecycleCtx(mctx, lc)
stagingds, err := r.Datastore(ctx, "/staging")
if err != nil {
return nil, err
}

View File

@ -1,6 +1,7 @@
package repo
import (
"context"
"os"
"path/filepath"
@ -67,7 +68,7 @@ func (fsr *fsLockedRepo) openDatastores(readonly bool) (map[string]datastore.Bat
return out, nil
}
func (fsr *fsLockedRepo) Datastore(ns string) (datastore.Batching, error) {
func (fsr *fsLockedRepo) Datastore(_ context.Context, ns string) (datastore.Batching, error) {
fsr.dsOnce.Do(func() {
fsr.ds, fsr.dsErr = fsr.openDatastores(fsr.readonly)
})

View File

@ -52,7 +52,10 @@ type LockedRepo interface {
Close() error
// Returns datastore defined in this repo.
Datastore(namespace string) (datastore.Batching, error)
// The supplied context must only be used to initialize the datastore.
// The implementation should not retain the context for usage throughout
// the lifecycle.
Datastore(ctx context.Context, namespace string) (datastore.Batching, error)
// Blockstore returns an IPLD blockstore for the requested domain.
// The supplied context must only be used to initialize the blockstore.

View File

@ -237,7 +237,7 @@ func (lmem *lockedMemRepo) Close() error {
}
func (lmem *lockedMemRepo) Datastore(ns string) (datastore.Batching, error) {
func (lmem *lockedMemRepo) Datastore(_ context.Context, ns string) (datastore.Batching, error) {
if err := lmem.checkToken(); err != nil {
return nil, err
}

View File

@ -77,7 +77,7 @@ func CreateTestStorageNode(ctx context.Context, t *testing.T, waddr address.Addr
})
require.NoError(t, err)
ds, err := lr.Datastore("/metadata")
ds, err := lr.Datastore(context.TODO(), "/metadata")
require.NoError(t, err)
err = ds.Put(datastore.NewKey("miner-address"), act.Bytes())
require.NoError(t, err)

View File

@ -165,7 +165,7 @@ func PrepareMiner(t *TestEnvironment) (*LotusMiner, error) {
return nil, err
}
ds, err := lr.Datastore("/metadata")
ds, err := lr.Datastore(context.Background(), "/metadata")
if err != nil {
return nil, err
}