mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
test: a committed delete during the wait exits 78 deleted; admitted stays 75
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f77a75c58e
commit
c49134bc00
1 file changed
+76
@@ -3,12 +3,18 @@
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
type masterWaitView struct {
|
||||
@@ -184,3 +190,73 @@ func TestObsoleteUnitStopsWithReachableMaster(t *testing.T) {
|
||||
t.Fatalf("obsolete unit exit %v after %v; want 75 assignment_timeout after the 30 s bound", err, took)
|
||||
}
|
||||
}
|
||||
|
||||
// revokeAndExit seals v1 on s1, revokes it at e and waits for the holder's
|
||||
// clean exit and recorded ACK: the volume is then admissible for delete.
|
||||
func revokeAndExit(t *testing.T, env *handoffEnv, holder *daemon, e uint64) {
|
||||
t.Helper()
|
||||
b := env.hosts["s1"]
|
||||
out, _ := env.h.command(t, "ops", "chunk", "detach", "--plain", "--volume", "v1", "--status-addr", b.status, "--timeout", "120s")
|
||||
var a struct {
|
||||
HeadGen uint64 `json:"headGen"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(out), &a); err != nil || a.HeadGen == 0 {
|
||||
t.Fatalf("plain detach: %v %q", err, out)
|
||||
}
|
||||
env.h.command(t, "ops", "workspace", "revoke", "--master", env.h.masterAddr, "--volume", "v1", "--replica", "r1",
|
||||
"--epoch", fmt.Sprint(e), "--sealed-gen", fmt.Sprint(a.HeadGen))
|
||||
if err := holder.wait(30 * time.Second); err != nil {
|
||||
t.Fatalf("holder after the revocation: %v; want a clean exit", err)
|
||||
}
|
||||
poll(t, 30*time.Second, "the ACK was never recorded", func() bool {
|
||||
out, _ := env.h.command(t, "ops", "workspace", "show", "--master", env.h.masterAddr, "--volume", "v1")
|
||||
return showsAck(out, e, a.HeadGen)
|
||||
})
|
||||
}
|
||||
|
||||
// A process waiting on its cached assignment while the volume's delete is
|
||||
// committed exits 78 deleted at once (the master's typed DELETED refusal);
|
||||
// while the delete is only admitted (abortable) it keeps the bounded wait and
|
||||
// exits 75 assignment_timeout, never 78.
|
||||
func TestWaitingVolumeDeletedDuringOutageExits78(t *testing.T) {
|
||||
t.Run("committed", func(t *testing.T) {
|
||||
env := startHandoffEnv(t, 1)
|
||||
holder := env.start(t, "bv-del-holder", "s1")
|
||||
e := env.adopt(t, holder, "s1")
|
||||
revokeAndExit(t, env, holder, e)
|
||||
waiting := env.start(t, "bv-del-waiting", "s1")
|
||||
waiting.waitLog(t, 30*time.Second, "blockvolume: volume v1 adopted as PRIMARY at r1@")
|
||||
out, errOut, code := env.h.run(t, "ops", "chunk", "volume-delete", "--volume", "v1", "--chunk-filer", env.cluster.filerGRPC,
|
||||
"--chunk-path", env.chunkPath, "--master", env.h.masterAddr, "--request-id", "del-while-waiting")
|
||||
var del struct{ Completed bool }
|
||||
if code != 0 || json.Unmarshal([]byte(out), &del) != nil || !del.Completed {
|
||||
t.Fatalf("volume-delete while a process waits: exit %d %s %s; want completed", code, out, errOut)
|
||||
}
|
||||
err := waiting.wait(30 * time.Second)
|
||||
if exitCode(err) != 78 || !waiting.has("blockvolume: exiting status=78 reason=deleted") {
|
||||
t.Fatalf("waiting process after the committed delete: %v; want 78 reason=deleted", err)
|
||||
}
|
||||
})
|
||||
t.Run("admitted", func(t *testing.T) {
|
||||
env := startHandoffEnv(t, 1)
|
||||
holder := env.start(t, "bv-adm-holder", "s1")
|
||||
e := env.adopt(t, holder, "s1")
|
||||
revokeAndExit(t, env, holder, e)
|
||||
conn, err := grpc.NewClient(env.h.masterAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if _, err := control.NewLifecycleServiceClient(conn).MarkVolumeDeleting(ctx, &control.MarkVolumeDeletingRequest{VolumeId: "v1", Token: "admit-only"}); err != nil {
|
||||
t.Fatal("admit the delete:", err)
|
||||
}
|
||||
at := time.Now()
|
||||
waiting := env.start(t, "bv-adm-waiting", "s1")
|
||||
err = waiting.wait(2 * time.Minute)
|
||||
if exitCode(err) != 75 || !waiting.has("reason=assignment_timeout") || time.Since(at) < 25*time.Second {
|
||||
t.Fatalf("waiting process under an admitted delete: %v after %v; want the bounded 75 assignment_timeout", err, time.Since(at))
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user