Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Apr 11, 2024
1 parent 4fce724 commit a116c7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 8 additions & 5 deletions curiosrc/web/hapi/simpleinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"context"
"fmt"
"github.com/filecoin-project/lotus/storage/paths"
"github.com/samber/lo"
"net/http"
"os"
"sort"
Expand Down Expand Up @@ -224,6 +226,10 @@ func (a *app) sectorInfo(w http.ResponseWriter, r *http.Request) {
err = a.db.Select(ctx, &sectorLocations, `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
Expand All @@ -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,
Expand Down Expand Up @@ -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"`
Expand Down
8 changes: 5 additions & 3 deletions storage/paths/db_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (

const NoMinerFilter = abi.ActorID(0)

const URLSeparator = ","

var errAlreadyLocked = errors.New("already locked")

type DBIndex struct {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a116c7a

Please sign in to comment.