lp: Small migration improvements

This commit is contained in:
Łukasz Magiera 2024-02-14 11:09:10 +01:00
parent ee31932731
commit 9ddfe23702
3 changed files with 32 additions and 17 deletions

View File

@ -77,6 +77,10 @@ func (f FIL) MarshalText() (text []byte, err error) {
}
func (f FIL) UnmarshalText(text []byte) error {
if f.Int == nil {
return fmt.Errorf("cannot unmarshal into nil BigInt (text:%s)", string(text))
}
p, err := ParseFIL(string(text))
if err != nil {
return err

View File

@ -37,7 +37,7 @@ var configMigrateCmd = &cli.Command{
Aliases: []string{FlagMinerRepoDeprecation},
EnvVars: []string{"LOTUS_MINER_PATH", "LOTUS_STORAGE_PATH"},
Value: "~/.lotusminer",
Usage: fmt.Sprintf("Specify miner repo path. flag(%s) and env(LOTUS_STORAGE_PATH) are DEPRECATION, will REMOVE SOON", FlagMinerRepoDeprecation),
Usage: "Miner repo path",
},
&cli.StringFlag{
Name: "repo",
@ -124,7 +124,7 @@ func fromMiner(cctx *cli.Context) (err error) {
if err != nil {
return fmt.Errorf("could not read config.toml: %w", err)
}
var lpCfg config.LotusProviderConfig
lpCfg := config.DefaultLotusProvider()
_, err = deps.LoadConfigWithUpgrades(string(buf), &lpCfg)
if err != nil {
return fmt.Errorf("could not decode toml: %w", err)
@ -177,12 +177,16 @@ func fromMiner(cctx *cli.Context) (err error) {
}
lpCfg.Apis.ChainApiInfo = []string{header.Get("Authorization")[7:] + ":" + ainfo.Addr}
// Enable WindowPoSt
lpCfg.Subsystems.EnableWindowPost = true
msg += "\nBefore running lotus-provider, ensure any miner/worker answering of WindowPost is disabled by " +
// WindowPoSt message
msg += "\n!! Before running lotus-provider with Window PoSt enabled, ensure any miner/worker answering of WindowPost is disabled by " +
"(on Miner) " + configColor("DisableBuiltinWindowPoSt=true") + " and (on Workers) not enabling windowpost on CLI or via " +
"environment variable " + configColor("LOTUS_WORKER_WINDOWPOST") + "."
// WinningPoSt message
msg += "\n!! Before running lotus-provider with Winning PoSt enabled, ensure any miner/worker answering of WinningPost is disabled by " +
"(on Miner) " + configColor("DisableBuiltinWinningPoSt=true") + " and (on Workers) not enabling winningpost on CLI or via " +
"environment variable " + configColor("LOTUS_WORKER_WINNINGPOST") + "."
// Express as configTOML
configTOML := &bytes.Buffer{}
if err = toml.NewEncoder(configTOML).Encode(lpCfg); err != nil {

View File

@ -180,7 +180,7 @@ func (dbi *DBIndex) StorageAttach(ctx context.Context, si storiface.StorageInfo,
}
}
retryWait := time.Millisecond * 100
retryWait := time.Millisecond * 20
retryAttachStorage:
// Single transaction to attach storage which is not present in the DB
_, err := dbi.harmonyDB.BeginTransaction(ctx, func(tx *harmonydb.Tx) (commit bool, err error) {
@ -289,7 +289,7 @@ func (dbi *DBIndex) StorageDetach(ctx context.Context, id storiface.ID, url stri
log.Warnw("Dropping sector path endpoint", "path", id, "url", url)
} else {
retryWait := time.Millisecond * 100
retryWait := time.Millisecond * 20
retryDropPath:
// Single transaction to drop storage path and sector decls which have this as a storage path
_, err := dbi.harmonyDB.BeginTransaction(ctx, func(tx *harmonydb.Tx) (commit bool, err error) {
@ -321,15 +321,9 @@ func (dbi *DBIndex) StorageDetach(ctx context.Context, id storiface.ID, url stri
}
func (dbi *DBIndex) StorageReportHealth(ctx context.Context, id storiface.ID, report storiface.HealthReport) error {
var canSeal, canStore bool
err := dbi.harmonyDB.QueryRow(ctx,
"SELECT can_seal, can_store FROM storage_path WHERE storage_id=$1", id).Scan(&canSeal, &canStore)
if err != nil {
return xerrors.Errorf("Querying for storage id %s fails with err %v", id, err)
}
_, err = dbi.harmonyDB.Exec(ctx,
retryWait := time.Millisecond * 20
retryReportHealth:
_, err := dbi.harmonyDB.Exec(ctx,
"UPDATE storage_path set capacity=$1, available=$2, fs_available=$3, reserved=$4, used=$5, last_heartbeat=NOW()",
report.Stat.Capacity,
report.Stat.Available,
@ -337,7 +331,20 @@ func (dbi *DBIndex) StorageReportHealth(ctx context.Context, id storiface.ID, re
report.Stat.Reserved,
report.Stat.Used)
if err != nil {
return xerrors.Errorf("updating storage health in DB fails with err: %v", err)
//return xerrors.Errorf("updating storage health in DB fails with err: %v", err)
if harmonydb.IsErrSerialization(err) {
time.Sleep(retryWait)
retryWait *= 2
goto retryReportHealth
}
return err
}
var canSeal, canStore bool
err = dbi.harmonyDB.QueryRow(ctx,
"SELECT can_seal, can_store FROM storage_path WHERE storage_id=$1", id).Scan(&canSeal, &canStore)
if err != nil {
return xerrors.Errorf("Querying for storage id %s fails with err %v", id, err)
}
if report.Stat.Capacity > 0 {