stores: http: Support multiple storage IDs in ?keep
This commit is contained in:
parent
ada499ef14
commit
668c33fdcd
@ -57,8 +57,8 @@ var (
|
|||||||
FullAPIVersion0 = newVer(1, 5, 0)
|
FullAPIVersion0 = newVer(1, 5, 0)
|
||||||
FullAPIVersion1 = newVer(2, 2, 0)
|
FullAPIVersion1 = newVer(2, 2, 0)
|
||||||
|
|
||||||
MinerAPIVersion0 = newVer(1, 4, 0)
|
MinerAPIVersion0 = newVer(1, 5, 0)
|
||||||
WorkerAPIVersion0 = newVer(1, 5, 0)
|
WorkerAPIVersion0 = newVer(1, 6, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint:varcheck,deadcode
|
//nolint:varcheck,deadcode
|
||||||
|
2
extern/sector-storage/stores/http_handler.go
vendored
2
extern/sector-storage/stores/http_handler.go
vendored
@ -172,7 +172,7 @@ func (handler *FetchHandler) remoteDeleteSector(w http.ResponseWriter, r *http.R
|
|||||||
return
|
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)
|
log.Errorf("%+v", err)
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(500)
|
||||||
return
|
return
|
||||||
|
22
extern/sector-storage/stores/index.go
vendored
22
extern/sector-storage/stores/index.go
vendored
@ -7,6 +7,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
gopath "path"
|
gopath "path"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -29,6 +30,27 @@ var SkippedHeartbeatThresh = HeartbeatInterval * 5
|
|||||||
// filesystem, local or networked / shared by multiple machines
|
// filesystem, local or networked / shared by multiple machines
|
||||||
type ID string
|
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 Group = string
|
||||||
|
|
||||||
type StorageInfo struct {
|
type StorageInfo struct {
|
||||||
|
8
extern/sector-storage/stores/remote.go
vendored
8
extern/sector-storage/stores/remote.go
vendored
@ -156,7 +156,7 @@ func (r *Remote) AcquireSector(ctx context.Context, s storage.SectorRef, existin
|
|||||||
|
|
||||||
if op == storiface.AcquireMove {
|
if op == storiface.AcquireMove {
|
||||||
id := ID(storageID)
|
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)
|
log.Warnf("deleting sector %v from %s (delete %s): %+v", s, storageID, url, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -355,7 +355,7 @@ storeLoop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, url := range info.URLs {
|
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)
|
log.Warnf("remove %s: %+v", url, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -366,9 +366,9 @@ storeLoop:
|
|||||||
return nil
|
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 {
|
if keepIn != nil {
|
||||||
url = url + "?keep=" + string(*keepIn)
|
url = url + "?keep=" + keepIn.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Delete %s", url)
|
log.Infof("Delete %s", url)
|
||||||
|
6
extern/sector-storage/worker_local.go
vendored
6
extern/sector-storage/worker_local.go
vendored
@ -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) {
|
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 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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user