Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do concurrent cleanup #85

Merged
merged 1 commit into from
Mar 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions pkg/bench/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,31 @@ func (c *Common) createEmptyBucket(ctx context.Context) error {
// deleteAllInBucket will delete all content in a bucket.
// If no prefixes are specified everything in bucket is deleted.
func (c *Common) deleteAllInBucket(ctx context.Context, prefixes ...string) {
doneCh := make(chan struct{})
defer close(doneCh)
cl, done := c.Client()
defer done()
if len(prefixes) == 0 {
prefixes = []string{""}
}
var wg sync.WaitGroup
remove := make(chan string, 1)
errCh := cl.RemoveObjectsWithContext(ctx, c.Bucket, remove)
wg.Add(len(prefixes))
for _, prefix := range prefixes {
go func(prefix string) {
defer wg.Done()

doneCh := make(chan struct{})
defer close(doneCh)
cl, done := c.Client()
defer done()
remove := make(chan string, 10)
errCh := cl.RemoveObjectsWithContext(ctx, c.Bucket, remove)
defer func() {
// Signal we are done
close(remove)
// Wait for deletes to finish
err := <-errCh
if err.Err != nil {
console.Error(err.Err)
}
}()

objects := cl.ListObjectsV2(c.Bucket, prefix, true, doneCh)
for {
select {
Expand All @@ -140,13 +151,6 @@ func (c *Common) deleteAllInBucket(ctx context.Context, prefixes ...string) {
}(prefix)
}
wg.Wait()
// Signal we are done
close(remove)
// Wait for deletes to finish
err := <-errCh
if err.Err != nil {
console.Error(err.Err)
}

}

Expand Down