From 9ddfe23702ea99424a77d1d7725a61ab86584d66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 14 Feb 2024 11:09:10 +0100 Subject: [PATCH] lp: Small migration improvements --- chain/types/fil.go | 4 ++++ cmd/lotus-provider/config_migrate.go | 14 ++++++++----- storage/paths/db_index.go | 31 +++++++++++++++++----------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/chain/types/fil.go b/chain/types/fil.go index 2a0ccb460..d20b3c021 100644 --- a/chain/types/fil.go +++ b/chain/types/fil.go @@ -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 diff --git a/cmd/lotus-provider/config_migrate.go b/cmd/lotus-provider/config_migrate.go index 805c404bd..7b395d5a9 100644 --- a/cmd/lotus-provider/config_migrate.go +++ b/cmd/lotus-provider/config_migrate.go @@ -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 { diff --git a/storage/paths/db_index.go b/storage/paths/db_index.go index 32afdea1e..1472997b6 100644 --- a/storage/paths/db_index.go +++ b/storage/paths/db_index.go @@ -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 {