From 91d3edecfd96a14b95037b4bf798563142e6edff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 21 Feb 2024 13:28:49 +0100 Subject: [PATCH] lp: Address review --- cmd/lotus-provider/cli.go | 2 +- provider/lpseal/task_trees.go | 3 --- provider/lpweb/hapi/robust_rpc.go | 5 +++- storage/paths/db_index.go | 41 ++++++------------------------- 4 files changed, 12 insertions(+), 39 deletions(-) diff --git a/cmd/lotus-provider/cli.go b/cmd/lotus-provider/cli.go index 86e01ab35..dc1bdde16 100644 --- a/cmd/lotus-provider/cli.go +++ b/cmd/lotus-provider/cli.go @@ -30,7 +30,7 @@ var cliCmd = &cli.Command{ Flags: []cli.Flag{ &cli.StringFlag{ Name: "machine", - Usage: "machine host:port", + Usage: "machine host:port (lotus-provider run --listen address)", }, }, Before: func(cctx *cli.Context) error { diff --git a/provider/lpseal/task_trees.go b/provider/lpseal/task_trees.go index dbef9ecde..3f9b000cd 100644 --- a/provider/lpseal/task_trees.go +++ b/provider/lpseal/task_trees.go @@ -142,9 +142,6 @@ func (t *TreesTask) Do(taskID harmonytask.TaskID, stillOwned func() bool) (done return false, xerrors.Errorf("computing tree d: %w", err) } - // todo: Sooo tree-d contains exactly the unsealed data in the prefix - // when we finalize we can totally just truncate that file and move it to unsealed !! - // R / C sealed, unsealed, err := t.sc.TreeRC(ctx, sref, commd) if err != nil { diff --git a/provider/lpweb/hapi/robust_rpc.go b/provider/lpweb/hapi/robust_rpc.go index 8f0780b8d..e9914bfa6 100644 --- a/provider/lpweb/hapi/robust_rpc.go +++ b/provider/lpweb/hapi/robust_rpc.go @@ -78,7 +78,10 @@ func (a *app) updateRpc(ctx context.Context) error { if err != nil { continue } - _ = closer // todo + go func() { + <-ctx.Done() + closer() + }() a.workingApi = v1api } diff --git a/storage/paths/db_index.go b/storage/paths/db_index.go index 142a32e83..4c935762f 100644 --- a/storage/paths/db_index.go +++ b/storage/paths/db_index.go @@ -180,8 +180,6 @@ func (dbi *DBIndex) StorageAttach(ctx context.Context, si storiface.StorageInfo, } } - 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) { var urls sql.NullString @@ -243,17 +241,9 @@ retryAttachStorage: return false, xerrors.Errorf("StorageAttach insert fails: %v", err) } return true, nil - }) - if err != nil { - if harmonydb.IsErrSerialization(err) { - time.Sleep(retryWait) - retryWait *= 2 - goto retryAttachStorage - } - return err - } + }, harmonydb.RetrySerializationErr()) - return nil + return err } func (dbi *DBIndex) StorageDetach(ctx context.Context, id storiface.ID, url string) error { @@ -289,8 +279,6 @@ 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 * 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) { // Drop storage path completely @@ -305,19 +293,14 @@ func (dbi *DBIndex) StorageDetach(ctx context.Context, id storiface.ID, url stri return false, err } return true, nil - }) + }, harmonydb.RetrySerializationErr()) if err != nil { - if harmonydb.IsErrSerialization(err) { - time.Sleep(retryWait) - retryWait *= 2 - goto retryDropPath - } return err } log.Warnw("Dropping sector storage", "path", id) } - return nil + return err } func (dbi *DBIndex) StorageReportHealth(ctx context.Context, id storiface.ID, report storiface.HealthReport) error { @@ -392,8 +375,6 @@ func (dbi *DBIndex) StorageDeclareSector(ctx context.Context, storageID storifac return xerrors.Errorf("invalid filetype") } - retryWait := time.Millisecond * 100 -retryStorageDeclareSector: _, err := dbi.harmonyDB.BeginTransaction(ctx, func(tx *harmonydb.Tx) (commit bool, err error) { var currPrimary sql.NullBool err = tx.QueryRow( @@ -426,17 +407,9 @@ retryStorageDeclareSector: } return true, nil - }) - if err != nil { - if harmonydb.IsErrSerialization(err) { - time.Sleep(retryWait) - retryWait *= 2 - goto retryStorageDeclareSector - } - return err - } + }, harmonydb.RetrySerializationErr()) - return nil + return err } func (dbi *DBIndex) StorageDropSector(ctx context.Context, storageID storiface.ID, s abi.SectorID, ft storiface.SectorFileType) error { @@ -873,7 +846,7 @@ func (dbi *DBIndex) lock(ctx context.Context, sector abi.SectorID, read storifac } return true, nil - }) + }, harmonydb.RetrySerializationErr()) if err != nil { return false, err }