mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
test: preserve the advertised filer identity at crash boundaries
(cherry picked from commit ff6490991ae0dbad1dd285ebac35ea6a49282e0a)
This commit is contained in:
1 parent
82f6d2f1c8
commit
184f4eacd4
4 files changed
+69
-14
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -6,6 +6,9 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
@@ -37,28 +40,46 @@ type snapshotFilerBoundary struct {
|
||||
hit bool
|
||||
}
|
||||
|
||||
func newSnapshotFilerBoundary(t *testing.T, env *handoffEnv) (*snapshotFilerBoundary, string) {
|
||||
func newSnapshotFilerBoundary(t *testing.T, cluster *w4WeedCluster) *snapshotFilerBoundary {
|
||||
t.Helper()
|
||||
id, err := layout.ParseVolumeID(env.layoutID("v1"))
|
||||
conn, err := grpc.NewClient(cluster.filerGRPC, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conn, err := grpc.NewClient(env.cluster.filerGRPC, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
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)
|
||||
}
|
||||
p := &snapshotFilerBoundary{backend: filerpb.NewSeaweedFilerClient(conn), id: id,
|
||||
dir: path.Join(env.chunkPath, layout.VolumeDir("v1", id))}
|
||||
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
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; _ = conn.Close() })
|
||||
return p, listener.Addr().String()
|
||||
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{} {
|
||||
|
||||
@@ -71,9 +71,20 @@ func TestSnapshotLadderE1CrashDuringASnapshot(t *testing.T) {
|
||||
for i := 0; i <= len(boundaries); i++ {
|
||||
targets = append(targets, fmt.Sprintf("v%d", i+2))
|
||||
}
|
||||
env := startHandoffEnvWith(t, 1, targets)
|
||||
boundary, filerAddr := newSnapshotFilerBoundary(t, env)
|
||||
env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off", "--chunk-filer", filerAddr}
|
||||
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")
|
||||
marker := pattern("ladder-e1-marker")
|
||||
|
||||
@@ -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