stores: Support RemoveCopies on remote store
This commit is contained in:
parent
668c33fdcd
commit
d249eb3f93
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
|
||||
}
|
||||
|
||||
func (r *Remote) RemoveCopies(ctx context.Context, s abi.SectorID, types storiface.SectorFileType) error {
|
||||
// TODO: do this on remotes too
|
||||
// (not that we really need to do that since it's always called by the
|
||||
// worker which pulled the copy)
|
||||
func (r *Remote) RemoveCopies(ctx context.Context, s abi.SectorID, typ storiface.SectorFileType) error {
|
||||
if bits.OnesCount(uint(typ)) != 1 {
|
||||
return xerrors.New("delete expects one file type")
|
||||
}
|
||||
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user