(ctx context.Context, commit ksuid.KSUID, dryrun bool)
| 283 | } |
| 284 | |
| 285 | func (p *Pool) Vacuum(ctx context.Context, commit ksuid.KSUID, dryrun bool) ([]ksuid.KSUID, error) { |
| 286 | group, ctx := errgroup.WithContext(ctx) |
| 287 | group.SetLimit(runtime.GOMAXPROCS(0)) |
| 288 | ch := make(chan *data.Object) |
| 289 | group.Go(func() error { |
| 290 | defer close(ch) |
| 291 | return p.commits.Vacuumable(ctx, commit, ch) |
| 292 | }) |
| 293 | var vacuumed []ksuid.KSUID |
| 294 | var mu sync.Mutex |
| 295 | for o := range ch { |
| 296 | if dryrun { |
| 297 | // For dryrun just check if the object exists and append existing |
| 298 | // objects to list of results. |
| 299 | group.Go(func() error { |
| 300 | ok, err := p.engine.Exists(ctx, data.SequenceURI(p.DataPath, o.ID)) |
| 301 | if ok { |
| 302 | mu.Lock() |
| 303 | vacuumed = append(vacuumed, o.ID) |
| 304 | mu.Unlock() |
| 305 | } |
| 306 | return err |
| 307 | }) |
| 308 | continue |
| 309 | } |
| 310 | group.Go(func() error { |
| 311 | err := p.engine.Delete(ctx, data.SequenceURI(p.DataPath, o.ID)) |
| 312 | if err == nil { |
| 313 | mu.Lock() |
| 314 | vacuumed = append(vacuumed, o.ID) |
| 315 | mu.Unlock() |
| 316 | } |
| 317 | if errors.Is(err, fs.ErrNotExist) { |
| 318 | err = nil |
| 319 | } |
| 320 | return err |
| 321 | }) |
| 322 | // Delete the seek index as well. |
| 323 | group.Go(func() error { |
| 324 | err := p.engine.Delete(ctx, data.SeekIndexURI(p.DataPath, o.ID)) |
| 325 | if errors.Is(err, fs.ErrNotExist) { |
| 326 | err = nil |
| 327 | } |
| 328 | return err |
| 329 | }) |
| 330 | } |
| 331 | if err := group.Wait(); err != nil { |
| 332 | return nil, err |
| 333 | } |
| 334 | return vacuumed, nil |
| 335 | } |
| 336 | |
| 337 | func (p *Pool) Main(ctx context.Context) (BranchMeta, error) { |
| 338 | branch, err := p.OpenBranchByName(ctx, "main") |
nothing calls this directly
no test coverage detected