From e16d6c7b112379c8b36c39bd01d7c1c61d583bb3 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 4 Dec 2026 11:20:55 -0800 Subject: [PATCH] test: write failover read files until every volume server backs one (#13391) TestReadWithVolumeServerDown wrote three files and required each volume server to hold a chunk of one of them. When the mount starts before the master is elected, the first writes can all land on the volumes one server lacks, and the test stopped before stopping anything. Write three more at a time, up to twelve, until every server backs a file. Co-authored-by: Claude Opus 5.5 --- test/fuse_failover/framework_test.go | 20 +++++++++++++ test/fuse_failover/volume_failover_test.go | 34 +++++++++++++++------- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/test/fuse_failover/framework_test.go b/test/fuse_failover/framework_test.go index 1dd3b59c6d..f97d995e4b 100644 --- a/test/fuse_failover/framework_test.go +++ b/test/fuse_failover/framework_test.go @@ -499,6 +499,26 @@ func (c *failoverCluster) FileIsOn(path, serverAddress string) (bool, error) { return false, nil } +// everyVolumeServerBacksOneOf reports whether each volume server holds a +// chunk of at least one of the given files. +func (c *failoverCluster) everyVolumeServerBacksOneOf(t *testing.T, names []string) bool { + for i := range c.volumePorts { + backed := false + for _, name := range names { + on, err := c.FileIsOn("/"+name, c.VolumeServerAddress(i)) + require.NoError(t, err, "resolve placement of %s", name) + if on { + backed = true + break + } + } + if !backed { + return false + } + } + return true +} + func (c *failoverCluster) masterAddress() string { return string(pb.NewServerAddress("127.0.0.1", c.masterPort, c.masterGrpcPort)) } diff --git a/test/fuse_failover/volume_failover_test.go b/test/fuse_failover/volume_failover_test.go index 04aa901bb7..be859fa514 100644 --- a/test/fuse_failover/volume_failover_test.go +++ b/test/fuse_failover/volume_failover_test.go @@ -140,16 +140,26 @@ func TestReadWithVolumeServerDown(t *testing.T) { const fileSize = 8 << 20 payloads := make(map[string][]byte) - for i := 0; i < 3; i++ { - name := fmt.Sprintf("readfile-%d", i) - data := make([]byte, fileSize) - _, err := rand.Read(data) - require.NoError(t, err) - require.NoError(t, os.WriteFile(filepath.Join(c.MountDir(0), name), data, 0644)) - payloads[name] = data + var names []string + // Placement decides which two of the three servers hold each volume, and + // early writes can all land on the volumes one server lacks, so write + // more files until every server backs one of them. + for len(names) < 12 { + for i := 0; i < 3; i++ { + name := fmt.Sprintf("readfile-%d", len(names)) + data := make([]byte, fileSize) + _, err := rand.Read(data) + require.NoError(t, err) + require.NoError(t, os.WriteFile(filepath.Join(c.MountDir(0), name), data, 0644)) + payloads[name] = data + names = append(names, name) + } + // Let the filer commit the last chunks before anything is torn down. + time.Sleep(2 * time.Second) + if c.everyVolumeServerBacksOneOf(t, names) { + break + } } - // Let the filer commit the last chunks before anything is torn down. - time.Sleep(2 * time.Second) t.Logf("topology before chaos:\n%s", c.MasterGet("/dir/status?pretty=y")) @@ -161,8 +171,10 @@ func TestReadWithVolumeServerDown(t *testing.T) { // earlier iteration has read, whose chunks the reader has not cached. name := "" for _, allowRead := range []bool{false, true} { - for i := 0; i < 3 && name == ""; i++ { - candidate := fmt.Sprintf("readfile-%d", i) + for _, candidate := range names { + if name != "" { + break + } if alreadyRead[candidate] && !allowRead { continue }