mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +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
d0b237fd25
8 files changed
+292
-105
No files matched your search
@@ -49,11 +49,13 @@ func TestProcedureMasterKilledAfterMoveBeforeTargetStarts(t *testing.T) {
|
||||
t.Fatalf("sealed HEAD LSN %d; want %d", got, l)
|
||||
}
|
||||
nw := env.start(t, "blockvolume-s2", "s2")
|
||||
must(checkClaimDoneBy(nw.waitLog(t, 60*time.Second, "durable: HEAD claim for volume=v1 done in"), e2, "s2"))
|
||||
if got := env.adopt(t, nw, "s2"); got != e2 {
|
||||
t.Fatalf("target adopted epoch %d; want recovered epoch %d", got, e2)
|
||||
}
|
||||
env.requireHeadHolder(t, e2, "s2")
|
||||
// Planned hand-over step 8 observes the completed layout claim in HEAD:
|
||||
// its identity advanced while the sealed image and position were kept.
|
||||
out, _ = env.h.command(t, env.chunkShow()...)
|
||||
must(checkLayoutHeadReopenedBy(out, e2, g, l, "s2"))
|
||||
if !bytes.Equal(env.readBlock(t, "s2", 0), block) {
|
||||
t.Fatal("acknowledged source block changed after master crash and move recovery")
|
||||
}
|
||||
|
||||
@@ -9,14 +9,16 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// #425: the procedure gate's owner-endpoint check rejects when EITHER recipient's evidence is missing, unreadable,
|
||||
// has no forced-epoch delivery, or carries another host's endpoints; it passes only with positive evidence from both.
|
||||
// The procedure gate needs positive evidence from every recipient: an owner's
|
||||
// delivery or the documented MOVED refusal before any assignment is delivered.
|
||||
// A refusal never excuses wrong endpoints in a delivery that did occur.
|
||||
func TestWrongOwnerEndpointsNeedsPositiveEvidenceFromEachRecipient(t *testing.T) {
|
||||
owner := bvHost{id: "s2", data: "127.0.0.1:2001", ctrl: "127.0.0.1:2002"}
|
||||
dir := t.TempDir()
|
||||
good := `blockvolume: assignment stream delivery process="X" server="s2" volume="v1" replica="r1" epoch=2 ev=1 data="127.0.0.1:2001" ctrl="127.0.0.1:2002"`
|
||||
wrong := `blockvolume: assignment stream delivery process="X" server="s2" volume="v1" replica="r1" epoch=2 ev=2 data="127.0.0.1:1001" ctrl="127.0.0.1:1002"`
|
||||
other := `blockvolume: assignment stream delivery process="X" server="s1" volume="v1" replica="r1" epoch=1 ev=1 data="127.0.0.1:1001" ctrl="127.0.0.1:1002"`
|
||||
moved := `blockvolume: exiting status=78 reason=moved`
|
||||
logOf := func(name string, lines ...string) *daemon {
|
||||
p := filepath.Join(dir, name+".log")
|
||||
if err := os.WriteFile(p, []byte(strings.Join(lines, "\n")+"\n"), 0o644); err != nil {
|
||||
@@ -35,6 +37,10 @@ func TestWrongOwnerEndpointsNeedsPositiveEvidenceFromEachRecipient(t *testing.T)
|
||||
{"first has no epoch delivery", []*daemon{logOf("a3", other), logOf("b3", good)}, "no epoch delivery logged"},
|
||||
{"second carries another host's endpoints", []*daemon{logOf("a4", good), logOf("b4", good, wrong)}, "127.0.0.1:1001"},
|
||||
{"first empty log", []*daemon{logOf("a5"), logOf("b5", good)}, "no epoch delivery logged"},
|
||||
{"source refused before delivery", []*daemon{logOf("a6", good), logOf("b6", moved)}, ""},
|
||||
{"refusal does not excuse wrong endpoints", []*daemon{logOf("a7", good), logOf("b7", wrong, moved)}, "127.0.0.1:1001"},
|
||||
{"unclassified exit is not a moved refusal", []*daemon{logOf("a8", good), logOf("b8", "blockvolume: exiting status=78")}, "no epoch delivery logged"},
|
||||
{"retry exit is not a moved refusal", []*daemon{logOf("a9", good), logOf("b9", "blockvolume: exiting status=75 reason=assignment_timeout")}, "no epoch delivery logged"},
|
||||
} {
|
||||
bad := wrongOwnerEndpoints(2, owner, c.ds...)
|
||||
switch {
|
||||
|
||||
@@ -244,9 +244,19 @@ func startHandoffEnvTLS(t *testing.T, n int, targets []string, tlsNotAfter map[s
|
||||
// VolumeRecord. The restore-create test uses that form so the master creates
|
||||
// the target's identity and restored image in one request.
|
||||
func startHandoffEnvConfigured(t *testing.T, n int, targets []string, tlsNotAfter map[string]time.Time, precreateTargets bool, masterArgs ...string) *handoffEnv {
|
||||
t.Helper()
|
||||
return startHandoffEnvOnCluster(t, n, targets, tlsNotAfter, precreateTargets, nil, masterArgs...)
|
||||
}
|
||||
|
||||
// startHandoffEnvOnCluster also admits a caller-owned stock filer behind a
|
||||
// fault-injection front; ordinary callers keep the default cluster unchanged.
|
||||
func startHandoffEnvOnCluster(t *testing.T, n int, targets []string, tlsNotAfter map[string]time.Time, precreateTargets bool, cluster *w4WeedCluster, masterArgs ...string) *handoffEnv {
|
||||
t.Helper()
|
||||
h := newPlannedHandoffHarness(t)
|
||||
env := &handoffEnv{h: h, cluster: startWorkspaceWeed(t), chunkPath: fmt.Sprintf("/handoff-%d", time.Now().UnixNano()), hosts: map[string]bvHost{}}
|
||||
if cluster == nil {
|
||||
cluster = startWorkspaceWeed(t)
|
||||
}
|
||||
env := &handoffEnv{h: h, cluster: cluster, chunkPath: fmt.Sprintf("/handoff-%d", time.Now().UnixNano()), hosts: map[string]bvHost{}}
|
||||
must, _ := fatalOn(t)
|
||||
env.hosts["s1"] = bvHost{id: "s1", data: h.dataAddr, ctrl: h.ctrlAddr, status: h.statusAddr, nvme: h.nvmeAddr, root: filepath.Join(h.dir, "vol")}
|
||||
for i := 2; i <= n; i++ {
|
||||
@@ -257,7 +267,7 @@ func startHandoffEnvConfigured(t *testing.T, n int, targets []string, tlsNotAfte
|
||||
id := "n-" + v
|
||||
env.hosts[id] = bvHost{id: id, data: handoffAddress(t), ctrl: handoffAddress(t), status: handoffAddress(t), nvme: handoffAddress(t), root: filepath.Join(h.dir, "vol-"+id), volume: v}
|
||||
}
|
||||
cluster, chunkPath := env.cluster, env.chunkPath
|
||||
chunkPath := env.chunkPath
|
||||
if tlsNotAfter != nil {
|
||||
servers := make([]string, 0, len(env.hosts))
|
||||
for _, b := range env.hosts {
|
||||
|
||||
@@ -50,7 +50,6 @@ func TestProcedurePlannedHandoffToAnotherHost(t *testing.T) {
|
||||
moved, _ := h.command(t, env.moveClean(e, "s2", "move-v1-1")...)
|
||||
e2 := mustU(movedEpochTo(moved, e, g, l, "s2"))
|
||||
nw := env.start(t, "blockvolume-s2", "s2")
|
||||
must(checkClaimDoneBy(nw.waitLog(t, 60*time.Second, "durable: HEAD claim for volume=v1 done in"), e2, "s2"))
|
||||
if got := env.adopt(t, nw, "s2"); got != e2 {
|
||||
t.Fatalf("s2 adopted at epoch %d; want %d", got, e2)
|
||||
}
|
||||
@@ -211,10 +210,11 @@ func TestProcedureForcedMoveWithTheOldHostReturning(t *testing.T) {
|
||||
fresh.root = fresh.root + "-fresh"
|
||||
freshRoot := env.oldHostRefuses(t, "blockvolume-s1-fresh-root", fresh, e2, 78)
|
||||
// A line carries its owner and that owner's endpoints: every line
|
||||
// delivered at the forced epoch, to the new owner and to each returning
|
||||
// old host alike, carries s2's own endpoints, never another host's.
|
||||
// delivered at the forced epoch carries s2's own endpoints, never another
|
||||
// host's. A returning source can instead be refused MOVED before the
|
||||
// assignment stream delivers anything (volume-lifecycle.md, do-not list).
|
||||
if bad := wrongOwnerEndpoints(e2, env.hosts["s2"], nw, back, again, freshRoot); len(bad) > 0 {
|
||||
t.Errorf("epoch-%d deliveries not proven to carry s2's endpoints (want data=%s ctrl=%s in every recipient's lines):\n%s",
|
||||
t.Errorf("epoch-%d owner evidence invalid (want data=%s ctrl=%s in every delivery, or a moved refusal before delivery):\n%s",
|
||||
e2, env.hosts["s2"].data, env.hosts["s2"].ctrl, strings.Join(bad, "\n"))
|
||||
}
|
||||
env.h.waitPrimaryAt(t, env.hosts["s2"].status, e2)
|
||||
@@ -511,8 +511,8 @@ func (env *handoffEnv) forceMove(t *testing.T, e uint64, target, request string)
|
||||
}
|
||||
|
||||
// wrongOwnerEndpoints returns every "assignment stream delivery" log line at epoch e (in any of ds) whose data or control
|
||||
// endpoint is not owner's, plus an entry for each recipient whose log cannot be read or shows no epoch-e
|
||||
// delivery at all (each recipient must positively have received the owner's line).
|
||||
// endpoint is not owner's, plus an entry for each recipient whose log cannot be
|
||||
// read or shows neither an epoch-e delivery nor the documented MOVED refusal.
|
||||
func wrongOwnerEndpoints(e uint64, owner bvHost, ds ...*daemon) []string {
|
||||
var bad []string
|
||||
tag := fmt.Sprintf(" epoch=%d ev=", e)
|
||||
@@ -532,7 +532,9 @@ func wrongOwnerEndpoints(e uint64, owner bvHost, ds ...*daemon) []string {
|
||||
bad = append(bad, d.name+": "+strings.TrimSpace(l))
|
||||
}
|
||||
}
|
||||
if seen == 0 { // positive evidence per recipient: a check that saw no forced-epoch delivery proves nothing
|
||||
if seen == 0 && !strings.Contains(string(raw), "blockvolume: exiting status=78 reason=moved") {
|
||||
// Mere absence proves nothing. The master's typed MOVED refusal
|
||||
// ends an old source's stream before any fact can be delivered.
|
||||
bad = append(bad, d.name+": no epoch delivery logged")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
//go:build subprocess && chunkstore_integration
|
||||
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
// snapshotFilerBoundary forwards the stock filer API unchanged. One applied
|
||||
// write's reply is held until the test kills the holder. Thus the receipt
|
||||
// proves an actual Begin, object create or Commit, independent of a delay.
|
||||
// Assumptions: one snapshot at a time, capture timer/schedule disabled, no GC.
|
||||
// Writers enumerated: UpdateEntry(HEAD Begin/Commit), CreateEntry(pool).
|
||||
// All other writers/readers pass through; pre-restart HEAD uses the backend.
|
||||
type snapshotFilerBoundary struct {
|
||||
filerpb.UnimplementedSeaweedFilerServer
|
||||
backend filerpb.SeaweedFilerClient
|
||||
dir string
|
||||
id layout.VolumeID
|
||||
mu sync.Mutex
|
||||
kind, name string
|
||||
reached chan struct{}
|
||||
release chan struct{}
|
||||
hit bool
|
||||
}
|
||||
|
||||
func newSnapshotFilerBoundary(t *testing.T, cluster *w4WeedCluster) *snapshotFilerBoundary {
|
||||
t.Helper()
|
||||
conn, err := grpc.NewClient(cluster.filerGRPC, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p := &snapshotFilerBoundary{backend: filerpb.NewSeaweedFilerClient(conn)}
|
||||
_, gp, _ := net.SplitHostPort(cluster.filerGRPC)
|
||||
listener, err := net.Listen("tcp", net.JoinHostPort(testListenHost(), gp))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
backendURL, err := url.Parse("http://" + cluster.filerHTTP)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, hp, _ := net.SplitHostPort(cluster.filerHTTP)
|
||||
httpListener, err := net.Listen("tcp", net.JoinHostPort(testListenHost(), hp))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
httpServer := &http.Server{Handler: httputil.NewSingleHostReverseProxy(backendURL), ReadHeaderTimeout: 10 * time.Second}
|
||||
httpDone := make(chan struct{})
|
||||
go func() { defer close(httpDone); _ = httpServer.Serve(httpListener) }()
|
||||
server := grpc.NewServer()
|
||||
filerpb.RegisterSeaweedFilerServer(server, p)
|
||||
done := make(chan struct{})
|
||||
go func() { defer close(done); _ = server.Serve(listener) }()
|
||||
t.Cleanup(func() {
|
||||
p.unblock()
|
||||
server.Stop()
|
||||
_ = listener.Close()
|
||||
<-done
|
||||
_ = httpServer.Close()
|
||||
<-httpDone
|
||||
_ = conn.Close()
|
||||
})
|
||||
cluster.filerGRPC = listener.Addr().String()
|
||||
cluster.filerHTTP = httpListener.Addr().String()
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *snapshotFilerBoundary) arm(kind, name string) <-chan struct{} {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
p.kind, p.name = kind, name
|
||||
p.reached = make(chan struct{})
|
||||
p.release = make(chan struct{})
|
||||
p.hit = false
|
||||
return p.reached
|
||||
}
|
||||
func (p *snapshotFilerBoundary) unblock() {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
if p.release != nil {
|
||||
close(p.release)
|
||||
p.release = nil
|
||||
}
|
||||
}
|
||||
func (p *snapshotFilerBoundary) after(ctx context.Context, dir string, entry *filerpb.Entry) {
|
||||
p.mu.Lock()
|
||||
if p.hit || p.reached == nil || entry == nil || os.Getenv("E1_TEST_SKIP_BOUNDARY") == "1" {
|
||||
p.mu.Unlock()
|
||||
return
|
||||
}
|
||||
match := p.kind == "OBJECT" && path.Dir(dir) == path.Join(p.dir, "pool")
|
||||
if dir == p.dir && entry.Name == layout.HeadName {
|
||||
h, err := chunkstore.DecodeLayoutHeadEntry(entry, p.id)
|
||||
if err == nil {
|
||||
_, named := h.Snapshots[p.name]
|
||||
match = (p.kind == "BEGIN" && h.Activity.Kind == layout.ActSnap && !named) || (p.kind == "COMMIT" && named)
|
||||
}
|
||||
}
|
||||
if !match {
|
||||
p.mu.Unlock()
|
||||
return
|
||||
}
|
||||
p.hit = true
|
||||
close(p.reached)
|
||||
release := p.release
|
||||
p.mu.Unlock()
|
||||
select {
|
||||
case <-release:
|
||||
case <-ctx.Done():
|
||||
}
|
||||
}
|
||||
func (p *snapshotFilerBoundary) head(t *testing.T) layout.Head {
|
||||
t.Helper()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
r, err := p.backend.LookupDirectoryEntry(ctx, &filerpb.LookupDirectoryEntryRequest{Directory: p.dir, Name: layout.HeadName})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h, err := chunkstore.DecodeLayoutHeadEntry(r.Entry, p.id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return h
|
||||
}
|
||||
func (p *snapshotFilerBoundary) LookupDirectoryEntry(ctx context.Context, r *filerpb.LookupDirectoryEntryRequest) (*filerpb.LookupDirectoryEntryResponse, error) {
|
||||
return p.backend.LookupDirectoryEntry(ctx, r)
|
||||
}
|
||||
func (p *snapshotFilerBoundary) CreateEntry(ctx context.Context, r *filerpb.CreateEntryRequest) (*filerpb.CreateEntryResponse, error) {
|
||||
out, err := p.backend.CreateEntry(ctx, r)
|
||||
if err == nil && out.GetErrorCode() == filerpb.FilerError_OK && out.GetError() == "" {
|
||||
p.after(ctx, r.Directory, r.Entry)
|
||||
}
|
||||
return out, err
|
||||
}
|
||||
func (p *snapshotFilerBoundary) UpdateEntry(ctx context.Context, r *filerpb.UpdateEntryRequest) (*filerpb.UpdateEntryResponse, error) {
|
||||
out, err := p.backend.UpdateEntry(ctx, r)
|
||||
if err == nil {
|
||||
p.after(ctx, r.Directory, r.Entry)
|
||||
}
|
||||
return out, err
|
||||
}
|
||||
func (p *snapshotFilerBoundary) DeleteEntry(ctx context.Context, r *filerpb.DeleteEntryRequest) (*filerpb.DeleteEntryResponse, error) {
|
||||
return p.backend.DeleteEntry(ctx, r)
|
||||
}
|
||||
func (p *snapshotFilerBoundary) AssignVolume(ctx context.Context, r *filerpb.AssignVolumeRequest) (*filerpb.AssignVolumeResponse, error) {
|
||||
return p.backend.AssignVolume(ctx, r)
|
||||
}
|
||||
func (p *snapshotFilerBoundary) LookupVolume(ctx context.Context, r *filerpb.LookupVolumeRequest) (*filerpb.LookupVolumeResponse, error) {
|
||||
return p.backend.LookupVolume(ctx, r)
|
||||
}
|
||||
func (p *snapshotFilerBoundary) GetFilerConfiguration(ctx context.Context, r *filerpb.GetFilerConfigurationRequest) (*filerpb.GetFilerConfigurationResponse, error) {
|
||||
return p.backend.GetFilerConfiguration(ctx, r)
|
||||
}
|
||||
func (p *snapshotFilerBoundary) ListEntries(r *filerpb.ListEntriesRequest, s grpc.ServerStreamingServer[filerpb.ListEntriesResponse]) error {
|
||||
stream, err := p.backend.ListEntries(s.Context(), r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for {
|
||||
v, err := stream.Recv()
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = s.Send(v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,42 +6,18 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
|
||||
)
|
||||
|
||||
// Rung E of the snapshot ladder: faults. E1 kills the holder (SIGKILL) while
|
||||
// a snapshot is being taken, at several points of the snapshot, and restarts
|
||||
// it within its lease. The per-step crash cases of the catalog half (after
|
||||
// the name record, after the intent, with the attempt create unknown) are
|
||||
// pinned by a unit test of the catalog; this rung is the same property
|
||||
// through the real processes.
|
||||
|
||||
// nameRecorded reports whether vol's catalog holds a name record for the
|
||||
// snapshot name, read from the filer (not through the product).
|
||||
func (env *handoffEnv) nameRecorded(t *testing.T, vol, name string) bool {
|
||||
t.Helper()
|
||||
c := &http.Client{Timeout: 10 * time.Second}
|
||||
p := path.Join(env.chunkPath, vol, "snapnames", url.PathEscape(name))
|
||||
resp, err := c.Get("http://" + env.cluster.filerHTTP + p + "?metadata=true")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
io.Copy(io.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
switch resp.StatusCode {
|
||||
case http.StatusOK:
|
||||
return true
|
||||
case http.StatusNotFound:
|
||||
return false
|
||||
}
|
||||
t.Fatalf("filer lookup of %s: status %d", p, resp.StatusCode)
|
||||
return false
|
||||
}
|
||||
// Rung E: kill the real holder at applied Begin, object and Commit writes.
|
||||
// The filer's reply is held until SIGKILL, and HEAD is observed before restart.
|
||||
// Per-write kernel controls remain TestSnapshotSession_InterruptAtEveryStep.
|
||||
|
||||
// filerNames lists the entry names (unescaped) of a filer directory, read
|
||||
// straight from the filer (not through the product); a missing directory
|
||||
@@ -86,45 +62,28 @@ func (env *handoffEnv) filerNames(t *testing.T, dir string) map[string]bool {
|
||||
}
|
||||
}
|
||||
|
||||
// TestSnapshotLadderE1CrashDuringASnapshot: rounds on one volume. In each,
|
||||
// blocks in twelve chunks are written and acknowledged (so the snapshot's cut
|
||||
// has twelve chunks to upload), a snapshot with a fixed request id is
|
||||
// started, and the holder is killed after a different delay (from at once to
|
||||
// well after the answer), then restarted within its lease. Each kill's step
|
||||
// is recorded from what it left, read from the filer and the list (not
|
||||
// through the snapshot's own answer):
|
||||
// - ANSWERED: the command answered success before the kill;
|
||||
// - PUBLISHED: no answer, but the snapshot is listed after the restart
|
||||
// (the attempt entry was written; the answer was lost);
|
||||
// - CATALOG: no answer, not listed, but the name record exists (the kill
|
||||
// landed in the catalog steps, before the attempt entry);
|
||||
// - CUT: no answer, no name record, but an intent that was not there
|
||||
// before the request (the kill landed in the snapshot's cut, which
|
||||
// writes its intent first);
|
||||
// - BEFORE: none of these.
|
||||
//
|
||||
// The test fails as inconclusive unless at least one kill is PUBLISHED,
|
||||
// CATALOG or CUT (inside the snapshot). After each restart, before the
|
||||
// retry:
|
||||
// - the snapshot is listed at most once and only active; an ANSWERED one
|
||||
// is listed, at the cut its answer gave;
|
||||
// - one more block is written (acknowledged).
|
||||
//
|
||||
// Then a retry with the same request id completes the snapshot, listed once:
|
||||
// at the cut listed before the retry if it was listed (a replay), else at a
|
||||
// new cut that holds the post-restart block. At the end a next snapshot is
|
||||
// taken after more writes. Every round's snapshot and the next one restore
|
||||
// (to independence, per the restore status) exactly as expected: the blocks
|
||||
// acknowledged before it, the post-restart block only when the retry cut
|
||||
// anew, and every block written after it reading zero.
|
||||
// TestSnapshotLadderE1CrashDuringASnapshot retains the data/replay/restore
|
||||
// oracle, but reaches each crash boundary causally through the stock filer.
|
||||
// A missed boundary is inconclusive, never a successful BEFORE-only campaign.
|
||||
func TestSnapshotLadderE1CrashDuringASnapshot(t *testing.T) {
|
||||
delays := []time.Duration{0, 25 * time.Millisecond, 50 * time.Millisecond, 75 * time.Millisecond,
|
||||
100 * time.Millisecond, 125 * time.Millisecond, 150 * time.Millisecond, 200 * time.Millisecond, 600 * time.Millisecond}
|
||||
boundaries := []string{"BEGIN", "OBJECT", "COMMIT"}
|
||||
var targets []string
|
||||
for i := 0; i <= len(delays); i++ {
|
||||
for i := 0; i <= len(boundaries); i++ {
|
||||
targets = append(targets, fmt.Sprintf("v%d", i+2))
|
||||
}
|
||||
env := startHandoffEnvWith(t, 1, targets)
|
||||
if testListenHost() != "127.0.0.1" {
|
||||
t.Fatal("causal filer fixture requires loopback")
|
||||
}
|
||||
var boundary *snapshotFilerBoundary
|
||||
cluster := startWorkspaceWeedWith(t, t.TempDir(), w4WeedOpts{VolumeSizeLimitMB: 256, VolumeMax: 32,
|
||||
FilerBind: "127.0.0.2", FilerFront: func(c *w4WeedCluster) { boundary = newSnapshotFilerBoundary(t, c) }})
|
||||
env := startHandoffEnvOnCluster(t, 1, targets, procedureTLSConfig(), false, cluster)
|
||||
id, err := layout.ParseVolumeID(env.layoutID("v1"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
boundary.id = id
|
||||
boundary.dir = path.Join(env.chunkPath, layout.VolumeDir("v1", id))
|
||||
env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"}
|
||||
holder := env.start(t, "blockvolume-v1", "s1")
|
||||
e := env.adopt(t, holder, "s1")
|
||||
@@ -139,14 +98,13 @@ func TestSnapshotLadderE1CrashDuringASnapshot(t *testing.T) {
|
||||
var images []map[uint64][]byte // what each round's snapshot must hold
|
||||
cum := map[uint64][]byte{0: marker}
|
||||
steps := map[string]int{}
|
||||
for k, delay := range delays {
|
||||
for k, kind := range boundaries {
|
||||
img := ladderImage(fmt.Sprintf("e1r%d", k), []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, 3)
|
||||
env.writeImage(t, "s1", img)
|
||||
cum = mergeImages(cum, img)
|
||||
name, req := fmt.Sprintf("e1-%d", k), fmt.Sprintf("r-e1-%d", k)
|
||||
|
||||
intents := path.Join(env.chunkPath, "v1", "intents")
|
||||
before := env.filerNames(t, intents)
|
||||
reached := boundary.arm(kind, name)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 150*time.Second)
|
||||
done := make(chan result, 1)
|
||||
go func() {
|
||||
@@ -154,9 +112,23 @@ func TestSnapshotLadderE1CrashDuringASnapshot(t *testing.T) {
|
||||
"--name", name, "--request-id", req)
|
||||
done <- result{out, errOut, code, err}
|
||||
}()
|
||||
time.Sleep(delay)
|
||||
select {
|
||||
case <-reached:
|
||||
case <-time.After(30 * time.Second):
|
||||
cancel()
|
||||
boundary.unblock()
|
||||
<-done
|
||||
t.Fatalf("inconclusive: snapshot never reached applied %s boundary", kind)
|
||||
}
|
||||
holder.kill(t)
|
||||
killed := time.Now()
|
||||
// Restart can abort the old session, so read the real backend first.
|
||||
crashed := boundary.head(t)
|
||||
_, published := crashed.Snapshots[name]
|
||||
if kind == "COMMIT" && !published || kind != "COMMIT" && (published || crashed.Activity.Kind != layout.ActSnap) {
|
||||
t.Fatalf("boundary %s disagrees with pre-restart HEAD: %+v", kind, crashed)
|
||||
}
|
||||
boundary.unblock()
|
||||
var r result
|
||||
select {
|
||||
case r = <-done:
|
||||
@@ -171,11 +143,6 @@ func TestSnapshotLadderE1CrashDuringASnapshot(t *testing.T) {
|
||||
}
|
||||
cancel()
|
||||
answered := r.err == nil && r.code == 0
|
||||
newIntent := false
|
||||
for n := range env.filerNames(t, intents) {
|
||||
newIntent = newIntent || !before[n]
|
||||
}
|
||||
named := env.nameRecorded(t, "v1", name)
|
||||
|
||||
// Restarted within the lease, as the unit's RestartSec does: the same
|
||||
// epoch, serving the blocks written before the kill.
|
||||
@@ -190,20 +157,13 @@ func TestSnapshotLadderE1CrashDuringASnapshot(t *testing.T) {
|
||||
env.requireImage(t, "s1", cum)
|
||||
|
||||
pre := env.snapshots(t, "v1", name)
|
||||
step := "BEFORE"
|
||||
switch {
|
||||
case answered:
|
||||
step = "ANSWERED"
|
||||
case len(pre) == 1:
|
||||
step = "PUBLISHED"
|
||||
case named:
|
||||
step = "CATALOG"
|
||||
case newIntent:
|
||||
step = "CUT"
|
||||
}
|
||||
step := kind
|
||||
steps[step]++
|
||||
t.Logf("round %d (kill after %v): step %s (exit %d err %v; name record %v, new intent %v, listed %v); adopted %v and frontend ready %v after the kill",
|
||||
k, delay, step, r.code, r.err, named, newIntent, len(pre) == 1, adopted.Round(time.Millisecond), time.Since(killed).Round(time.Millisecond))
|
||||
if published != (len(pre) == 1) {
|
||||
t.Fatalf("round %d: pre-restart HEAD published=%v but restart lists %+v", k, published, pre)
|
||||
}
|
||||
t.Logf("round %d: applied %s, pre-restart HEAD gen=%d activity=%s published=%v; exit %d err %v; adopted %v after kill",
|
||||
k, step, crashed.Gen, crashed.Activity.Kind, published, r.code, r.err, adopted.Round(time.Millisecond))
|
||||
switch {
|
||||
case len(pre) > 1:
|
||||
t.Fatalf("round %d: %s listed %d times: %+v", k, name, len(pre), pre)
|
||||
@@ -234,8 +194,8 @@ func TestSnapshotLadderE1CrashDuringASnapshot(t *testing.T) {
|
||||
}
|
||||
cum = mergeImages(cum, post)
|
||||
}
|
||||
t.Logf("kill steps: %v; the catalog steps (CATALOG, PUBLISHED) are pinned per step by TestCatalogRestartAfterAbandonedSnapshot", steps)
|
||||
if steps["PUBLISHED"]+steps["CATALOG"]+steps["CUT"] == 0 {
|
||||
t.Logf("kill steps: %v; per-write cases pinned by TestSnapshotSession_InterruptAtEveryStep", steps)
|
||||
if steps["BEGIN"] != 1 || steps["OBJECT"] != 1 || steps["COMMIT"] != 1 {
|
||||
t.Fatalf("inconclusive: no kill landed inside a snapshot (steps %v)", steps)
|
||||
}
|
||||
|
||||
@@ -244,9 +204,10 @@ func TestSnapshotLadderE1CrashDuringASnapshot(t *testing.T) {
|
||||
env.snapshot(t, "s1", "v1", "e1-next")
|
||||
final := mergeImages(cum, next)
|
||||
|
||||
for k := range delays {
|
||||
for k := range boundaries {
|
||||
later := []map[uint64][]byte{final}
|
||||
env.restoreChecked(t, fmt.Sprintf("e1-%d", k), targets[k], images[k], later...)
|
||||
}
|
||||
env.restoreChecked(t, "e1-next", targets[len(delays)], final)
|
||||
env.restoreChecked(t, "e1-next", targets[len(boundaries)], final)
|
||||
t.Logf("final restore oracle reached: %d crash snapshots plus next snapshot read back", len(boundaries))
|
||||
}
|
||||
@@ -508,7 +508,11 @@ func (env *handoffEnv) hydrate(t *testing.T, target string) {
|
||||
t.Helper()
|
||||
b := env.hosts["n-"+target]
|
||||
c := dialNVMe(t, b.nvme, plannedHandoffNQN)
|
||||
for lba := uint64(0); lba <= ladderLastBlock; lba += ladderChunkBlocks {
|
||||
// A read fetches its chunk only when the block read is not local: a
|
||||
// block the guest wrote is served locally and fills nothing. So read
|
||||
// each chunk's last block, which no ladder image writes (ladderImage
|
||||
// writes offsets 0, 37, 74, ... in a chunk).
|
||||
for lba := uint64(ladderChunkBlocks - 1); lba <= ladderLastBlock; lba += ladderChunkBlocks {
|
||||
_ = c.io.SetDeadline(time.Now().Add(60 * time.Second))
|
||||
c.read(t, lba, 4096)
|
||||
}
|
||||
|
||||
@@ -91,6 +91,10 @@ func startWorkspaceWeedAt(t *testing.T, dir string) *w4WeedCluster {
|
||||
// VolumeSizeLimitMB each (the default holds about 8 GiB of chunks).
|
||||
type w4WeedOpts struct {
|
||||
VolumeSizeLimitMB, VolumeMax int
|
||||
// A fault-injection front keeps the advertised filer endpoint unchanged.
|
||||
// The one real filer binds a private loopback address; no second filer is registered.
|
||||
FilerBind string
|
||||
FilerFront func(*w4WeedCluster)
|
||||
}
|
||||
|
||||
func startWorkspaceWeedWith(t *testing.T, dir string, o w4WeedOpts) *w4WeedCluster {
|
||||
@@ -137,8 +141,17 @@ func startWorkspaceWeedWith(t *testing.T, dir string, o w4WeedOpts) *w4WeedClust
|
||||
run("master", "master", "-ip="+testListenHost(), fmt.Sprintf("-port=%d", mp), "-mdir="+filepath.Join(dir, "m"), fmt.Sprintf("-volumeSizeLimitMB=%d", o.VolumeSizeLimitMB), "-defaultReplication=000")
|
||||
w4WaitTCP(t, c.master, 20*time.Second)
|
||||
run("volume", "volume", "-ip="+testListenHost(), fmt.Sprintf("-port=%d", vp), "-dir="+filepath.Join(dir, "v"), "-master="+c.master, fmt.Sprintf("-max=%d", o.VolumeMax))
|
||||
run("filer", "filer", "-ip="+testListenHost(), fmt.Sprintf("-port=%d", fp), "-master="+c.master, "-defaultStoreDir="+filepath.Join(dir, "f"))
|
||||
filerArgs := []string{"filer", "-ip=" + testListenHost(), fmt.Sprintf("-port=%d", fp), "-master=" + c.master, "-defaultStoreDir=" + filepath.Join(dir, "f")}
|
||||
if o.FilerBind != "" {
|
||||
filerArgs = append(filerArgs, "-ip.bind="+o.FilerBind)
|
||||
c.filerHTTP = net.JoinHostPort(o.FilerBind, fmt.Sprint(fp))
|
||||
c.filerGRPC = net.JoinHostPort(o.FilerBind, fmt.Sprint(fp+10000))
|
||||
}
|
||||
run("filer", filerArgs...)
|
||||
w4WaitTCP(t, c.filerGRPC, 30*time.Second)
|
||||
if o.FilerFront != nil {
|
||||
o.FilerFront(c)
|
||||
}
|
||||
|
||||
// Wait until an assign succeeds (volume registered, volumes growable).
|
||||
cl := c.client(t, "/swblock/vols/probe")
|
||||
|
||||
Reference in new issue
Block a user