stores: http: Support multiple storage IDs in ?keep

This commit is contained in:
Łukasz Magiera 2022-03-16 10:35:26 +01:00
parent ada499ef14
commit 668c33fdcd
5 changed files with 34 additions and 8 deletions

View File

@ -57,8 +57,8 @@ var (
FullAPIVersion0 = newVer(1, 5, 0)
FullAPIVersion1 = newVer(2, 2, 0)
MinerAPIVersion0 = newVer(1, 4, 0)
WorkerAPIVersion0 = newVer(1, 5, 0)
MinerAPIVersion0 = newVer(1, 5, 0)
WorkerAPIVersion0 = newVer(1, 6, 0)
)
//nolint:varcheck,deadcode

View File

@ -172,7 +172,7 @@ func (handler *FetchHandler) remoteDeleteSector(w http.ResponseWriter, r *http.R
return
}
if err := handler.Local.Remove(r.Context(), id, ft, false, []ID{ID(r.FormValue("keep"))}); err != nil {
if err := handler.Local.Remove(r.Context(), id, ft, false, ParseIDList(r.FormValue("keep"))); err != nil {
log.Errorf("%+v", err)
w.WriteHeader(500)
return

View File

@ -7,6 +7,7 @@ import (
"net/url"
gopath "path"
"sort"
"strings"
"sync"
"time"
@ -29,6 +30,27 @@ var SkippedHeartbeatThresh = HeartbeatInterval * 5
// filesystem, local or networked / shared by multiple machines
type ID string
const IDSep = "."
type IDList []ID
func (il IDList) String() string {
l := make([]string, len(il))
for i, id := range il {
l[i] = string(id)
}
return strings.Join(l, IDSep)
}
func ParseIDList(s string) IDList {
strs := strings.Split(s, IDSep)
out := make([]ID, len(strs))
for i, str := range strs {
out[i] = ID(str)
}
return out
}
type Group = string
type StorageInfo struct {

View File

@ -156,7 +156,7 @@ func (r *Remote) AcquireSector(ctx context.Context, s storage.SectorRef, existin
if op == storiface.AcquireMove {
id := ID(storageID)
if err := r.deleteFromRemote(ctx, url, &id); err != nil {
if err := r.deleteFromRemote(ctx, url, []ID{id}); err != nil {
log.Warnf("deleting sector %v from %s (delete %s): %+v", s, storageID, url, err)
}
}
@ -355,7 +355,7 @@ storeLoop:
}
}
for _, url := range info.URLs {
if err := r.deleteFromRemote(ctx, url, nil); err != nil {
if err := r.deleteFromRemote(ctx, url, keepIn); err != nil {
log.Warnf("remove %s: %+v", url, err)
continue
}
@ -366,9 +366,9 @@ storeLoop:
return nil
}
func (r *Remote) deleteFromRemote(ctx context.Context, url string, keepIn *ID) error {
func (r *Remote) deleteFromRemote(ctx context.Context, url string, keepIn IDList) error {
if keepIn != nil {
url = url + "?keep=" + string(*keepIn)
url = url + "?keep=" + keepIn.String()
}
log.Infof("Delete %s", url)

View File

@ -516,7 +516,11 @@ func (l *LocalWorker) Remove(ctx context.Context, sector abi.SectorID) error {
func (l *LocalWorker) MoveStorage(ctx context.Context, sector storage.SectorRef, types storiface.SectorFileType) (storiface.CallID, error) {
return l.asyncCall(ctx, sector, MoveStorage, func(ctx context.Context, ci storiface.CallID) (interface{}, error) {
return nil, l.storage.MoveStorage(ctx, sector, types)
if err := l.storage.MoveStorage(ctx, sector, types); err != nil {
return nil, xerrors.Errorf("move to storage: %w", err)
}
return nil, l.storage.RemoveCopies(ctx, sector.ID, types)
})
}