mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
test(storage): a failed rewind's position is kept by the next; bounded walker test
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9ccda0ead6
commit
2cd6f1de1a
1 file changed
+63
-9
@@ -295,23 +295,37 @@ func TestUpgradePassOneRunAndRewindDuringACompare(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parked, resume := make(chan struct{}), make(chan struct{})
|
||||
var once sync.Once
|
||||
var once, release sync.Once
|
||||
p.compare = func(c context.Context, chunk uint64) (bool, error) {
|
||||
if chunk == 80 {
|
||||
first := false
|
||||
once.Do(func() { first = true })
|
||||
if first {
|
||||
close(parked)
|
||||
<-resume
|
||||
select {
|
||||
case <-resume:
|
||||
case <-c.Done():
|
||||
return false, c.Err()
|
||||
}
|
||||
}
|
||||
}
|
||||
return v.compare(c, chunk)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- p.Run(context.Background()) }()
|
||||
<-parked
|
||||
if err := p.Run(context.Background()); err == nil {
|
||||
t.Fatal("a second walker ran beside the first")
|
||||
go func() { done <- p.Run(ctx) }()
|
||||
t.Cleanup(func() { // never leave the walker parked
|
||||
release.Do(func() { close(resume) })
|
||||
cancel()
|
||||
<-done
|
||||
})
|
||||
select {
|
||||
case <-parked:
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("the walker never reached chunk 80")
|
||||
}
|
||||
if err := p.Run(context.Background()); !errors.Is(err, ErrUpgradePassRunning) {
|
||||
t.Fatalf("a second walker ran beside the first: %v", err)
|
||||
}
|
||||
v.mu.Lock()
|
||||
for c := uint64(20); c < 40; c++ {
|
||||
@@ -322,9 +336,16 @@ func TestUpgradePassOneRunAndRewindDuringACompare(t *testing.T) {
|
||||
if err := p.Rewind(20); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
close(resume)
|
||||
if err := <-done; err != nil {
|
||||
t.Fatal(err)
|
||||
release.Do(func() { close(resume) })
|
||||
var runErr error
|
||||
select {
|
||||
case runErr = <-done:
|
||||
done <- runErr // for the cleanup's join
|
||||
case <-time.After(20 * time.Second):
|
||||
t.Fatal("the walker did not finish")
|
||||
}
|
||||
if runErr != nil {
|
||||
t.Fatal(runErr)
|
||||
}
|
||||
for c := uint64(20); c < 40; c++ {
|
||||
if !v.durable[c] {
|
||||
@@ -333,6 +354,39 @@ func TestUpgradePassOneRunAndRewindDuringACompare(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A failed rewind's position is kept by a later one: finished, a rewind to 20
|
||||
// fails to write, a rewind to 60 succeeds; a reopen must start at or before 20.
|
||||
func TestUpgradePassAFailedRewindIsKeptByTheNext(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
v := newPassVolume()
|
||||
p, err := newUpgradePass(dir, 7, 100, v, v.compare)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.Run(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
blocked := filepath.Join(t.TempDir(), "not-a-dir")
|
||||
if err := os.WriteFile(blocked, nil, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.dir = blocked
|
||||
if err := p.Rewind(20); err == nil {
|
||||
t.Fatal("the control needs a failed cursor write")
|
||||
}
|
||||
p.dir = dir
|
||||
if err := p.Rewind(60); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c, err := readUpgradePassCursor(dir, 7)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c.Next > 20 {
|
||||
t.Fatalf("persisted cursor %d skips the chunks of the failed rewind to 20", c.Next)
|
||||
}
|
||||
}
|
||||
|
||||
// Work counted but not yet persisted survives a cancel or a failed write on
|
||||
// the same instance; chunks already known add nothing.
|
||||
func TestUpgradePassKeepsItsCountAcrossRuns(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user