forked from thanos-io/thanos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix race condition in filesystem bucket client Delete() (thanos-io#5103)
* Fix race condition in filesystem bucket client Delete() Signed-off-by: Marco Pracucci <[email protected]> * Added missing copyright header Signed-off-by: Marco Pracucci <[email protected]> * Addressed review comments Signed-off-by: Marco Pracucci <[email protected]> Signed-off-by: Nicholaswang <[email protected]>
- Loading branch information
1 parent
d218bdb
commit 9ef3454
Showing
2 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package filesystem | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/thanos-io/thanos/pkg/testutil" | ||
) | ||
|
||
func TestDelete_EmptyDirDeletionRaceCondition(t *testing.T) { | ||
const runs = 1000 | ||
|
||
ctx := context.Background() | ||
|
||
for r := 0; r < runs; r++ { | ||
b, err := NewBucket(t.TempDir()) | ||
testutil.Ok(t, err) | ||
|
||
// Upload 2 objects in a subfolder. | ||
testutil.Ok(t, b.Upload(ctx, "subfolder/first", strings.NewReader("first"))) | ||
testutil.Ok(t, b.Upload(ctx, "subfolder/second", strings.NewReader("second"))) | ||
|
||
// Prepare goroutines to concurrently delete the 2 objects (each one deletes a different object) | ||
start := make(chan struct{}) | ||
group := sync.WaitGroup{} | ||
group.Add(2) | ||
|
||
for _, object := range []string{"first", "second"} { | ||
go func(object string) { | ||
defer group.Done() | ||
|
||
<-start | ||
testutil.Ok(t, b.Delete(ctx, "subfolder/"+object)) | ||
}(object) | ||
} | ||
|
||
// Go! | ||
close(start) | ||
group.Wait() | ||
} | ||
} |