2019-08-01 14:14:16 +00:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-03-09 21:33:01 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"path/filepath"
|
2019-08-01 14:14:16 +00:00
|
|
|
|
|
|
|
"go.uber.org/fx"
|
|
|
|
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-10-01 11:58:26 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/backupds"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
2021-01-26 10:25:34 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/modules/helpers"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/repo"
|
2019-08-01 14:14:16 +00:00
|
|
|
)
|
|
|
|
|
2019-08-01 14:19:53 +00:00
|
|
|
func LockedRepo(lr repo.LockedRepo) func(lc fx.Lifecycle) repo.LockedRepo {
|
|
|
|
return func(lc fx.Lifecycle) repo.LockedRepo {
|
|
|
|
lc.Append(fx.Hook{
|
|
|
|
OnStop: func(_ context.Context) error {
|
|
|
|
return lr.Close()
|
|
|
|
},
|
|
|
|
})
|
2019-08-01 14:14:16 +00:00
|
|
|
|
2019-08-01 14:19:53 +00:00
|
|
|
return lr
|
2019-08-01 14:14:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-01 14:19:53 +00:00
|
|
|
func KeyStore(lr repo.LockedRepo) (types.KeyStore, error) {
|
|
|
|
return lr.KeyStore()
|
2019-08-01 14:14:16 +00:00
|
|
|
}
|
|
|
|
|
2021-03-09 21:33:01 +00:00
|
|
|
func Datastore(disableLog bool) func(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRepo) (dtypes.MetadataDS, error) {
|
|
|
|
return func(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
|
|
|
|
}
|
|
|
|
|
|
|
|
var logdir string
|
|
|
|
if !disableLog {
|
|
|
|
logdir = filepath.Join(r.Path(), "kvlog/metadata")
|
|
|
|
}
|
|
|
|
|
|
|
|
bds, err := backupds.Wrap(mds, logdir)
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("opening backupds: %w", err)
|
|
|
|
}
|
2020-10-01 11:58:26 +00:00
|
|
|
|
2021-03-09 21:33:01 +00:00
|
|
|
lc.Append(fx.Hook{
|
|
|
|
OnStop: func(_ context.Context) error {
|
|
|
|
return bds.CloseLog()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return bds, nil
|
|
|
|
}
|
2019-08-01 14:14:16 +00:00
|
|
|
}
|