mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
Merge #640's branch at its newest head into ci/process-level-tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
1fb51fcb7f
3 files changed
+64
-40
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -20,11 +21,13 @@ import (
|
||||
// again on the same host (same server and endpoints) with --durable-root
|
||||
// on a file system with room and nothing freed, starts and serves the
|
||||
// snapshot;
|
||||
// - no blast radius: while v2 stays refused (in the catalog, never
|
||||
// started), deleting the source's snapshot is allowed (deleting), and the
|
||||
// source volume is then deleted through the volume-lifecycle page's steps
|
||||
// (seal, revoke, ACK, volume-delete), which complete. Each step answers
|
||||
// within its bound; nothing is blocked by the refused target.
|
||||
// - the source's snapshot stays while targets depend on it: its delete is
|
||||
// refused with snapshot_has_dependents while v2 is refused and v3
|
||||
// serves. Once both targets are deleted (v2 started on a root with room;
|
||||
// each through the volume-lifecycle page's seal, revoke, ACK and
|
||||
// volume-delete), the snapshot delete succeeds, and the source volume is
|
||||
// then deleted through the same steps. Each step answers within its
|
||||
// bound.
|
||||
func TestHeadroomRefusedTargetBlastRadiusAndAnotherRoot(t *testing.T) {
|
||||
small, filler := os.Getenv("CHUNKSTORE_SMALL_ROOT"), os.Getenv("CHUNKSTORE_SMALL_FILLER")
|
||||
if small == "" || filler == "" {
|
||||
@@ -67,11 +70,32 @@ func TestHeadroomRefusedTargetBlastRadiusAndAnotherRoot(t *testing.T) {
|
||||
})
|
||||
env.requireImage(t, "n-v3", img)
|
||||
|
||||
// Blast radius, v2 still refused: delete the source's snapshot, then the source volume.
|
||||
out, errOut, code := env.h.run(t, "ops", "chunk", "snapshot-delete", "--master", env.h.masterAddr, "--volume", "v1", "--name", "base",
|
||||
"--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath)
|
||||
if code != 0 || !strings.Contains(out, `"state":"deleting"`) {
|
||||
t.Fatalf("snapshot-delete of the source snapshot while a restore target is refused: exit %d %s %s; want deleting", code, out, errOut)
|
||||
// While v2 is refused and v3 serves, the source's snapshot cannot be deleted.
|
||||
deleteBase := func() (string, string, int) {
|
||||
return env.h.run(t, "ops", "chunk", "snapshot-delete", "--master", env.h.masterAddr, "--volume", "v1", "--name", "base",
|
||||
"--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath)
|
||||
}
|
||||
out, errOut, code := deleteBase()
|
||||
if code == 0 || !strings.Contains(out+errOut, "snapshot_has_dependents") {
|
||||
t.Fatalf("snapshot-delete of the source snapshot while restore targets depend on it: exit %d %s %s; want snapshot_has_dependents", code, out, errOut)
|
||||
}
|
||||
|
||||
// Delete both targets: v2 on a root with room, then each through the
|
||||
// page's steps.
|
||||
b2 := env.hosts["n-v2"]
|
||||
b2.root = filepath.Join(env.h.dir, "vol-n-v2-with-room")
|
||||
env.hosts["n-v2"] = b2
|
||||
adopted := func(vol string) *regexp.Regexp {
|
||||
return regexp.MustCompile(`blockvolume: volume ` + vol + ` adopted as PRIMARY at r1@(\d+) `)
|
||||
}
|
||||
d2 := env.startTarget(t, "v2", "blockvolume-v2-with-room")
|
||||
env.deleteServingTarget(t, "v2", env.hosts["n-v2"], d2, logUint(t, d2, adopted("v2")))
|
||||
env.deleteServingTarget(t, "v3", b3, d3, logUint(t, d3, adopted("v3")))
|
||||
|
||||
// Now the snapshot delete succeeds, and then the source volume's delete.
|
||||
out, errOut, code = deleteBase()
|
||||
if code != 0 || !strings.Contains(out, `"state":"absent"`) {
|
||||
t.Fatalf("snapshot-delete of the source snapshot after its targets were deleted: exit %d %s %s; want absent", code, out, errOut)
|
||||
}
|
||||
g := env.seal(t, "s1", e)
|
||||
env.revoke(t, e, g)
|
||||
@@ -80,7 +104,7 @@ func TestHeadroomRefusedTargetBlastRadiusAndAnotherRoot(t *testing.T) {
|
||||
}
|
||||
env.waitAck(t, e, g)
|
||||
out, errOut, code = env.volumeDelete(t, "del-v1")
|
||||
requireDeleteCompleted(t, out, errOut, code, false)
|
||||
requireDeleteCompleted(t, out, errOut, code)
|
||||
}
|
||||
|
||||
// TestHeadroomRefusedRestoreTargetKeepsItsSourceSnapshot: a restore target
|
||||
|
||||
@@ -393,8 +393,8 @@ func TestSnapshotLadderB1SnapshotQuery(t *testing.T) {
|
||||
}
|
||||
out, errOut, code := env.h.run(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v2", "--snapshot", "x", "--target", "v3",
|
||||
"--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath)
|
||||
if code == 0 || !strings.Contains(out+errOut, "restore_source_not_own") {
|
||||
t.Fatalf("restore from a restore target's snapshot: exit %d, want restore_source_not_own\n%s\n%s", code, out, errOut)
|
||||
if code == 0 || !strings.Contains(out, `"code":"not_admitted"`) || !strings.Contains(out, "names another volume's chunks") {
|
||||
t.Fatalf("restore from a restore target's snapshot: exit %d, want not_admitted naming another volume's chunks\n%s\n%s", code, out, errOut)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,52 +22,52 @@ func (env *handoffEnv) volumeDelete(t *testing.T, request string) (string, strin
|
||||
"--master", env.h.masterAddr, "--request-id", request)
|
||||
}
|
||||
|
||||
// requireDeleteCompleted checks step 4's answer: admitted, committed, HEAD
|
||||
// marked, completed; and replayed when it is a rerun of a completed delete.
|
||||
func requireDeleteCompleted(t *testing.T, out, errOut string, code int, rerun bool) {
|
||||
// requireDeleteCompleted checks step 4's documented state:"deleted" result
|
||||
// (volume-lifecycle.md, "Delete a volume", step 4). Retries use the same
|
||||
// request id and must complete again; the CLI reports no replayed flag.
|
||||
func requireDeleteCompleted(t *testing.T, out, errOut string, code int) {
|
||||
t.Helper()
|
||||
var res struct {
|
||||
Admitted, Committed, HeadMarked, Completed, Replayed bool
|
||||
}
|
||||
if code != 0 || json.Unmarshal([]byte(out), &res) != nil || !res.Admitted || !res.Committed || !res.HeadMarked || !res.Completed || res.Replayed != rerun {
|
||||
t.Fatalf("volume-delete: exit %d %s %s; want admitted, committed, headMarked, completed, replayed %v", code, out, errOut, rerun)
|
||||
if code != 0 || !handoffDeleteCompleted(out) {
|
||||
t.Fatalf("volume-delete: exit %d %s %s; want a volume directory and state deleted", code, out, errOut)
|
||||
}
|
||||
}
|
||||
|
||||
// headShown returns HEAD's state and chunk count from `ops chunk show`.
|
||||
// headShown reads head.State and independently counts stored pool objects.
|
||||
// volume-lifecycle.md step 4 specifies that show has no chunkCount field;
|
||||
// its object-listing alternative preserves the checks that nothing was
|
||||
// removed on refusal and no chunks remain after completion.
|
||||
func (env *handoffEnv) headShown(t *testing.T) (string, int) {
|
||||
t.Helper()
|
||||
out, _ := env.h.command(t, env.chunkShow()...)
|
||||
var body struct {
|
||||
Head *struct {
|
||||
State string `json:"state"`
|
||||
ChunkCount int `json:"chunkCount"`
|
||||
} `json:"head"`
|
||||
var head struct {
|
||||
State string `json:"state"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(out), &body); err != nil || body.Head == nil {
|
||||
out := env.headOf(t, "v1")
|
||||
if err := json.Unmarshal([]byte(out), &head); err != nil {
|
||||
t.Fatalf("chunk show: %v %s", err, out)
|
||||
}
|
||||
return body.Head.State, body.Head.ChunkCount
|
||||
return head.State, env.poolObjects(t, "v1")
|
||||
}
|
||||
|
||||
// requireDeletedForGood checks the page's end state ("state": "deleted",
|
||||
// "chunkCount": 0) and that a rerun with the same request id completes
|
||||
// again.
|
||||
// requireDeletedForGood checks the page's deleted HEAD and empty pool,
|
||||
// then repeats the delete with the same request id and checks both again.
|
||||
func (env *handoffEnv) requireDeletedForGood(t *testing.T, request string) {
|
||||
t.Helper()
|
||||
if state, n := env.headShown(t); state != "deleted" || n != 0 {
|
||||
t.Fatalf("chunk show after the delete: state %q, chunkCount %d; want deleted, 0", state, n)
|
||||
t.Fatalf("after the delete: HEAD state %q, pool objects %d; want deleted, 0", state, n)
|
||||
}
|
||||
out, errOut, code := env.volumeDelete(t, request)
|
||||
requireDeleteCompleted(t, out, errOut, code, true)
|
||||
requireDeleteCompleted(t, out, errOut, code)
|
||||
if state, n := env.headShown(t); state != "deleted" || n != 0 {
|
||||
t.Fatalf("after the repeated delete: HEAD state %q, pool objects %d; want deleted, 0", state, n)
|
||||
}
|
||||
}
|
||||
|
||||
// TestProcedureDeleteAVolume: the page's steps. A volume with a snapshot is
|
||||
// sealed, revoked (blockvolume sends the ACK and exits 0 by itself) and its
|
||||
// ACK seen; volume-delete is refused while the snapshot exists, with nothing
|
||||
// deleted; the snapshot is deleted; volume-delete then answers admitted,
|
||||
// committed, headMarked, completed, `chunk show` shows HEAD deleted with no
|
||||
// chunks, and a rerun with the same request id completes again.
|
||||
// deleted; the snapshot is deleted; volume-delete then answers deleted,
|
||||
// `chunk show` shows HEAD deleted and the pool is empty, and a rerun with
|
||||
// the same request id completes again.
|
||||
func TestProcedureDeleteAVolume(t *testing.T) {
|
||||
env := startHandoffEnv(t, 1)
|
||||
holder := env.start(t, "blockvolume-s1", "s1")
|
||||
@@ -92,7 +92,7 @@ func TestProcedureDeleteAVolume(t *testing.T) {
|
||||
}
|
||||
env.deleteSnapshot(t, "v1", "s1")
|
||||
out, errOut, code = env.volumeDelete(t, "del-v1")
|
||||
requireDeleteCompleted(t, out, errOut, code, false)
|
||||
requireDeleteCompleted(t, out, errOut, code)
|
||||
env.requireDeletedForGood(t, "del-v1")
|
||||
}
|
||||
|
||||
@@ -130,6 +130,6 @@ func TestProcedureDeleteAfterASignalStop(t *testing.T) {
|
||||
}
|
||||
env.waitAck(t, e, g)
|
||||
out, errOut, code = env.volumeDelete(t, "del-v1")
|
||||
requireDeleteCompleted(t, out, errOut, code, false)
|
||||
requireDeleteCompleted(t, out, errOut, code)
|
||||
env.requireDeletedForGood(t, "del-v1")
|
||||
}
|
||||
Reference in new issue
Block a user