From a116c7af0ab0c6ac6ba76ee4de51a7f96b8976b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 11 Apr 2024 18:15:52 +0200 Subject: [PATCH] Address review --- curiosrc/web/hapi/simpleinfo.go | 13 ++++++++----- storage/paths/db_index.go | 8 +++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/curiosrc/web/hapi/simpleinfo.go b/curiosrc/web/hapi/simpleinfo.go index 08218476bb1..2a39d5e5744 100644 --- a/curiosrc/web/hapi/simpleinfo.go +++ b/curiosrc/web/hapi/simpleinfo.go @@ -4,6 +4,8 @@ import ( "bytes" "context" "fmt" + "github.com/filecoin-project/lotus/storage/paths" + "github.com/samber/lo" "net/http" "os" "sort" @@ -224,6 +226,10 @@ func (a *app) sectorInfo(w http.ResponseWriter, r *http.Request) { err = a.db.Select(ctx, §orLocations, `SELECT p.can_seal, p.can_store, l.sector_filetype, l.storage_id, p.urls FROM sector_location l JOIN storage_path p ON l.storage_id = p.storage_id WHERE l.sector_num = $1 and l.miner_id = $2 ORDER BY p.can_seal, p.can_store, l.storage_id`, intid, spid) + if err != nil { + http.Error(w, xerrors.Errorf("failed to fetch sector locations: %w", err).Error(), http.StatusInternalServerError) + return + } type fileLocations struct { StorageID string @@ -244,7 +250,7 @@ func (a *app) sectorInfo(w http.ResponseWriter, r *http.Request) { for i, loc := range sectorLocations { loc := loc - urlList := strings.Split(loc.Urls, ",") // Assuming URLs are comma-separated + urlList := strings.Split(loc.Urls, paths.URLSeparator) fLoc := fileLocations{ StorageID: loc.StorageID, @@ -325,10 +331,7 @@ func (a *app) sectorInfo(w http.ResponseWriter, r *http.Request) { appendNonNil(task.TaskCommitMsg) if len(taskIDs) > 0 { - ids := make([]int64, 0, len(taskIDs)) - for id := range taskIDs { - ids = append(ids, id) - } + ids := lo.Keys(taskIDs) var dbtasks []struct { OwnerID *string `db:"owner_id"` diff --git a/storage/paths/db_index.go b/storage/paths/db_index.go index f79e6941d03..470d5c33c6c 100644 --- a/storage/paths/db_index.go +++ b/storage/paths/db_index.go @@ -26,6 +26,8 @@ import ( const NoMinerFilter = abi.ActorID(0) +const URLSeparator = "," + var errAlreadyLocked = errors.New("already locked") type DBIndex struct { @@ -197,13 +199,13 @@ func (dbi *DBIndex) StorageAttach(ctx context.Context, si storiface.StorageInfo, if storageId.Valid { var currUrls []string if urls.Valid { - currUrls = strings.Split(urls.String, ",") + currUrls = strings.Split(urls.String, URLSeparator) } currUrls = union(currUrls, si.URLs) _, err = tx.Exec( "UPDATE storage_path set urls=$1, weight=$2, max_storage=$3, can_seal=$4, can_store=$5, groups=$6, allow_to=$7, allow_types=$8, deny_types=$9, allow_miners=$10, deny_miners=$11, last_heartbeat=NOW() WHERE storage_id=$12", - strings.Join(currUrls, ","), + strings.Join(currUrls, URLSeparator), si.Weight, si.MaxStorage, si.CanSeal, @@ -277,7 +279,7 @@ func (dbi *DBIndex) StorageDetach(ctx context.Context, id storiface.ID, url stri } if len(modUrls) > 0 { - newUrls := strings.Join(modUrls, ",") + newUrls := strings.Join(modUrls, URLSeparator) _, err := dbi.harmonyDB.Exec(ctx, "UPDATE storage_path set urls=$1 WHERE storage_id=$2", newUrls, id) if err != nil { return err