Skip to content

Commit

Permalink
kv: Add ParallelSectorDeleter
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Apr 4, 2021
1 parent 11b2401 commit dc4b3df
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion renter/renterutil/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func createTestingKV(tb testing.TB, numHosts, m, n int) PseudoKV {
P: 3, // TODO: is this a sane default?
Uploader: ParallelChunkUploader{Hosts: hs},
Downloader: ParallelChunkDownloader{Hosts: hs},
Deleter: SerialSectorDeleter{Hosts: hs},
Deleter: ParallelSectorDeleter{Hosts: hs},
}
tb.Cleanup(func() { kv.Close() })

Expand Down
39 changes: 39 additions & 0 deletions renter/renterutil/strategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -1293,3 +1293,42 @@ func (ssd SerialSectorDeleter) DeleteSectors(ctx context.Context, db MetaDB, sec
}
return nil
}

// ParallelSectorDeleter deletes sectors from hosts in parallel.
type ParallelSectorDeleter struct {
Hosts *HostSet
}

// DeleteSectors implements SectorDeleter.
func (psd ParallelSectorDeleter) DeleteSectors(ctx context.Context, db MetaDB, sectors map[hostdb.HostPublicKey][]crypto.Hash) error {
errCh := make(chan *HostError)
for hostKey, roots := range sectors {
go func(hostKey hostdb.HostPublicKey, roots []crypto.Hash) {
errCh <- func() *HostError {
h, err := psd.Hosts.acquire(hostKey)
if err != nil {
return &HostError{hostKey, err}
}
// TODO: no-op if roots already deleted
// TODO: respect ctx
err = h.DeleteSectors(roots)
psd.Hosts.release(hostKey)
if err != nil {
return &HostError{hostKey, err}
}
// TODO: mark sectors as deleted in db
return nil
}()
}(hostKey, roots)
}
var errs HostErrorSet
for range sectors {
if err := <-errCh; err != nil {
errs = append(errs, err)
}
}
if errs != nil {
return fmt.Errorf("could not delete from all hosts: %w", errs)
}
return nil
}

0 comments on commit dc4b3df

Please sign in to comment.