stores: Support RemoveCopies on remote store
This commit is contained in:
parent
45b07674e5
commit
4d65e0101d
34
extern/sector-storage/stores/remote.go
vendored
34
extern/sector-storage/stores/remote.go
vendored
@ -44,12 +44,36 @@ type Remote struct {
|
|||||||
pfHandler PartialFileHandler
|
pfHandler PartialFileHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Remote) RemoveCopies(ctx context.Context, s abi.SectorID, types storiface.SectorFileType) error {
|
func (r *Remote) RemoveCopies(ctx context.Context, s abi.SectorID, typ storiface.SectorFileType) error {
|
||||||
// TODO: do this on remotes too
|
if bits.OnesCount(uint(typ)) != 1 {
|
||||||
// (not that we really need to do that since it's always called by the
|
return xerrors.New("delete expects one file type")
|
||||||
// worker which pulled the copy)
|
}
|
||||||
|
|
||||||
return r.local.RemoveCopies(ctx, s, types)
|
if err := r.local.RemoveCopies(ctx, s, typ); err != nil {
|
||||||
|
return xerrors.Errorf("removing local copies: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
si, err := r.index.StorageFindSector(ctx, s, typ, 0, false)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("finding existing sector %d(t:%d) failed: %w", s, typ, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var hasPrimary bool
|
||||||
|
var keep []ID
|
||||||
|
for _, info := range si {
|
||||||
|
if info.Primary {
|
||||||
|
hasPrimary = true
|
||||||
|
keep = append(keep, info.ID)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !hasPrimary {
|
||||||
|
log.Warnf("remote RemoveCopies: no primary copies of sector %v (%s), not removing anything", s, typ)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.Remove(ctx, s, typ, true, keep)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRemote(local Store, index SectorIndex, auth http.Header, fetchLimit int, pfHandler PartialFileHandler) *Remote {
|
func NewRemote(local Store, index SectorIndex, auth http.Header, fetchLimit int, pfHandler PartialFileHandler) *Remote {
|
||||||
|
Loading…
Reference in New Issue
Block a user