mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
test: expose operation publication races with volume deletion
This commit is contained in:
1 parent
260c95ab8a
commit
68d9f28af7
1 file changed
+95
@@ -0,0 +1,95 @@
|
||||
package chunkstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb"
|
||||
)
|
||||
|
||||
type heldOperationCreate struct {
|
||||
Filer
|
||||
kind string
|
||||
reached chan struct{}
|
||||
release chan struct{}
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
func (f *heldOperationCreate) CreateEntry(ctx context.Context, dir string, e *filerpb.Entry, exclusive bool) error {
|
||||
if path.Base(dir) == "operations" && string(e.Extended[layoutKind]) == f.kind {
|
||||
f.once.Do(func() { close(f.reached) })
|
||||
select {
|
||||
case <-f.release:
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
return f.Filer.CreateEntry(ctx, dir, e, exclusive)
|
||||
}
|
||||
|
||||
// Two independent catalogs share only the filer. A paused old request must
|
||||
// not publish new namespace authority or receipt bytes after delete returns.
|
||||
func TestSnapshotOperationDeleteFencesPausedPublications(t *testing.T) {
|
||||
for _, kind := range []string{"snapshot-operation-index", "snapshot-operation"} {
|
||||
t.Run(kind, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
catalog, filer, blobs, _, volume := rerunFixture(t)
|
||||
held := &heldOperationCreate{Filer: filer, kind: kind, reached: make(chan struct{}), release: make(chan struct{})}
|
||||
other, err := NewBCatalog(held, blobs, catalog.base)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store, err := other.Store(volume)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
_, _, err := store.CreateSnapshotOperation(ctx, "paused", "create", "daily", strings.Repeat("a", 64))
|
||||
done <- err
|
||||
}()
|
||||
var releaseOnce sync.Once
|
||||
unblock := func() { releaseOnce.Do(func() { close(held.release) }) }
|
||||
joined := false
|
||||
defer func() {
|
||||
unblock()
|
||||
cancel()
|
||||
if !joined {
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Error("paused admission did not join")
|
||||
}
|
||||
}
|
||||
}()
|
||||
select {
|
||||
case <-held.reached:
|
||||
case err := <-done:
|
||||
joined = true
|
||||
t.Fatalf("did not reach publication barrier: %v", err)
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("publication barrier not reached")
|
||||
}
|
||||
if _, err := catalog.DeleteVolume(ctx, volume, okDeleteAuthority{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
unblock()
|
||||
var admissionErr error
|
||||
select {
|
||||
case admissionErr = <-done:
|
||||
joined = true
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("late admission did not return")
|
||||
}
|
||||
entries, listErr := filer.ListEntries(ctx, path.Join(store.root, "operations"), "", "", 128)
|
||||
if admissionErr == nil || listErr != nil || len(entries) != 0 {
|
||||
t.Fatalf("completed deletion allowed late publication: admission=%v entries=%d list=%v", admissionErr, len(entries), listErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user